542

Product support

Get help in the plugin support forum.

  • Added on Nov 14, 2017
  • Current version: 1.2.16
  • Platform Compatibility
    v3.x not tested
    v2.x not tested
    v1.x use latest
  • Created by
  • Public repository

Categories

This plugin adds a user system and the distribution of permissions between groups. Also you can write your own additions to this plugin.

Requirements

This plugin requires the Ajax Framework to be included in your layout/page in order to handle form requests.

Manage users and their permissions

The plugin performs functions such as registration, authorization and user management.

Registration users

Registration to the site is allowed by default. If you are running a closed site, or need to temporarily disable registration, you may disable this feature by switching Allow user registration to the OFF setting.

Activation

The Activation mode specifies the activation workflow:

  • Automatic (default): This mode will automatically activate a user when they first register.
  • User: The user can activate their account by responding to a confirmation message sent to their nominated email address.
  • Administrator: The user can only be activated by an administrator via the back-end area.
User Info

User permissions

To create your own rights, in the main file Plugin.php add a new method registerUsersPermissions

//Create new permissions
public function registerUsersPermissions()
{
    return [
        'keerill.users.access' => [
            'label' => 'Label premission',
            'tab' => 'Other'
        ],
        'keerill.users.some_permission' => [
            'label' => 'Some Permission',
            'tab' => 'Some tab'
        ]
    ]
}

Also for sorting, you can add to the array order, the lower, the higher this point will be

//Create new permissions
public function registerUsersPermissions()
{
    return [
        'keerill.users.access' => [
            'label' => 'Label premission',
            'tab' => 'Other',
            'order' => '10'
        ]
    ]
}

Session component

To get an authenticated user, add this component to the layout/page. After adding this component, a variable will be avaliable on the page {{ user }}

User variable

{% if user %}
    <p>Hello {{ user.name }}</p>
{% else %}
    <p>Nobody is logged in</p>
{% endif %}

Signing out

To end the user session, paste this code snippet into the page.

<a data-request="onLogout" data-request-data="redirect: '/good-bye'">Sign out</a>

AuthManager facade

The facade AuthManager, that you can use for common tasks, it basically inherits the class KEERill\Users\Classes\AuthManager for functionality.

Use AuthManager::register to register a new user:

$user = AuthManager::register([
    'name' => 'Some User',
    'email' => 'some@website.tld',
    'password' => 'changeme',
    'password_confirmation' => 'changeme',
]);

Use the second argument to automatically active the user:

// Auto activate this user
$user = AuthManager::register([...], true);

AuthManager::check the method checks whether the user is authenticated

// Returns true if signed in.
$loggedIn = AuthManager::check();

To get the model of an authenticated user, use AuthManager::getUser method.

// Returns the signed in user
$user = AuthManager::getUser();

You can authenticate a user by specifying a login and password using AuthManager::authenticate.

// Authenticate user by credentials
$user = AuthManager::authenticate([
    'login' => post('login'),
    'password' => post('password')
]);

The second argument is used to store the cookie for the user.

$user = AuthManager::authenticate([...], true);

The method also uses 2 optional arguments, $login and $customMessage.

Login used for the API false, the old session will not be reset and no new one will be created, only the user model KEERill\Users\Models\User well be created by standard authorization

Custom Message used for the API, this message will be insterted into the user's access log

You can also authenticate as a user simply by transferring the user model togeth AuthManager::login.

// Sign in as a specific user
AuthManager::login($user);

The second argument will remember you.

// Sign in and remember the user
AuthManager::login($user, true);

Use AuthManager::findUserByCredentials method, to search for the user.

$user = AuthManager::findUserByCredentials(['name' => 'Username']);

User Logs

In the plugin, you can enable logging of user activity. Using the add() method used in KEERill\Users\Models\Log you can add an entry to the log. As arguments, you need to transfer the user model, the message and the write code

// Create new log
Log::add($user, 'Message log', 'code');

User Access Logs

In the plugin, you can enable logging access to the user account. Using the add() method used in KEERill\Users\Models\AccessLog you can add a log entry. As arguments, you need to transfer tge user model, message adn login status [true - if the input is successful, false - conversely]

// Create new accesslog
AccessLog::add($user, 'Auth success', true);

User Events

  • keerill.users.beforeAuthenticate $component, $credentials, $postDatas and keerill.users.authenticate $component, $user, $postDatas:

    it works when the user is authenticated on the site

  • keerill.users.beforeRegister $component, $postDatas and keerill.users.register $component, $user, $postDatas:

    it works when a user registers on the site

  • keerill.users.beforeSaveSettings $component, $user, $postDatas and keerill.users.afterSaveSettings $component, $user:

    it works when the user saves his settings

  • keerill.users.logout $component, $user:

    it works when a user exits from his account

  • keerill.users.activation $user:

    triggers when the user activates their account

  • keerill.users.reset $user:

    triggers when the user retrieves the password

  • keerill.users.ban $user:

    it works when the user is blocked by the administration

  • keerill.users.extendsComponents $plugin:

    triggered when registration of plugin components takes place, is used to add their components to the plugin

1.2.16

Fixed clearLoginAttempts and remove $login in authenticate

Jul 14, 2018

1.2.15

Fixed return code 500 in Auth, Register and Settings components

Jun 14, 2018

1.2.14

Updated Permissions Widget. Add method getPermissionsOptions

Mar 04, 2018

1.2.13

Fixed settings permission

Feb 28, 2018

1.2.12

Fixed report widget (new Registrations)

Feb 16, 2018

1.2.11

Fixed lang in component Settings

Jan 16, 2018

1.2.10

Fixed URL referer

Dec 06, 2017

1.2.9

Add report widget for backend "New registrations"

Dec 02, 2017

1.2.8

Fixed languages and add Translate Plugin support

Nov 15, 2017

1.2.7

Add validate post datas in save settings

Nov 13, 2017

1.2.6

Remove permissions table, function registerUserPermissions add new permission user plugin

Nov 13, 2017

1.2.5

Add data column in user logs table

Nov 13, 2017

1.2.2

Seed tables defaults groups

Nov 13, 2017

1.2.1

Create IP Bans

Nov 13, 2017

1.2.0

Release new version

Nov 13, 2017

1.1.2

Create logs user activity

Nov 13, 2017

1.1.0

Release User Plugin

Nov 13, 2017

1.0.2

Create Users Table

Nov 13, 2017

1.0.1

First version of Users

Nov 13, 2017