2017 © Pedro Peláez
 

yii2-extension yii2-user

User module

image

yii2mod/yii2-user

User module

  • Sunday, August 20, 2017
  • by disem
  • Repository
  • 3 Watchers
  • 17 Stars
  • 4,594 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 4 Open issues
  • 20 Versions
  • 4 % Grown

The README.md

, (*1)

Yii2 User Extension


Flexible user registration and authentication module for Yii2, (*2)

Latest Stable Version Total Downloads License Scrutinizer Code Quality Build Status, (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist yii2mod/yii2-user "*"

or add, (*6)

"yii2mod/yii2-user": "*"

to the require section of your composer.json file., (*7)

Actions

This extension provides several independent action classes, which provides particular operation support:, (*8)

  1. [[yii2mod\user\actions\LoginAction]] - Logs in a user. The following additional parameters are available:
    • view - name of the view, which should be rendered.
    • modelClass - login model class name.
    • layout - the name of the layout to be applied to this view.
    • returnUrl - url which user should be redirected to on success.
  2. [[yii2mod\user\actions\LogoutAction]] - Logs out the current user. The following additional parameters are available:
    • returnUrl - url which user should be redirected to on success.
  3. [[yii2mod\user\actions\SignupAction]] - Signup a user. The following additional parameters are available:
    • view - name of the view, which should be rendered.
    • modelClass - signup model class name.
    • returnUrl - url which user should be redirected to on success.
  4. [[yii2mod\user\actions\RequestPasswordResetAction]] - Request password reset for a user. The following additional parameters are available:
    • view - name of the view, which should be rendered.
    • modelClass - request password model class.
    • successMessage - message to the user when the mail is sent successfully.
    • errorMessage - error message for the user when the email was not sent.
    • returnUrl - url which user should be redirected to on success.
  5. [[yii2mod\user\actions\PasswordResetAction]] - Reset password for a user. The following additional parameters are available:
    • view - name of the view, which should be rendered.
    • modelClass - reset password model class.
    • successMessage - message to be set on success.
    • returnUrl - url which user should be redirected to on success.

Configuration

1) If you use this extension without base template, then you need execute migration by the following command:, (*9)

php yii migrate/up --migrationPath=@vendor/yii2mod/yii2-user/migrations

2) You need to configure the params section in your project configuration:, (*10)

'params' => [
   'user.passwordResetTokenExpire' => 3600
]

3) Your need to create the UserModel class that be extends of UserModel and configure the property identityClass for user component in your project configuration, for example:, (*11)

'user' => [
    'identityClass' => 'yii2mod\user\models\UserModel',
    // for update last login date for user, you can call the `afterLogin` event as follows
    'on afterLogin' => function ($event) {
        $event->identity->updateLastLogin();
    }
],

4) For sending emails you need to configure the mailer component in the configuration of your project., (*12)

5) If you don't have the passwordResetToken.php template file in the mail folder of your project, then you need to create it, for example:, (*13)

urlManager->createAbsoluteUrl(['site/password-reset', 'token' => $user->password_reset_token]);
?>

Hello username) ?>,

Follow the link below to reset your password:



This template used for password reset email., (*14)

6) Add to SiteController (or configure via $route param in urlManager):, (*15)

    /**
     * @return array
     */
    public function actions()
    {
        return [
            'login' => [
                'class' => 'yii2mod\user\actions\LoginAction'
            ],
            'logout' => [
                'class' => 'yii2mod\user\actions\LogoutAction'
            ],
            'signup' => [
                'class' => 'yii2mod\user\actions\SignupAction'
            ],
            'request-password-reset' => [
                'class' => 'yii2mod\user\actions\RequestPasswordResetAction'
            ],
            'password-reset' => [
                'class' => 'yii2mod\user\actions\PasswordResetAction'
            ],
        ];
    }

You can then access to this actions through the following URL:, (*16)

  1. http://localhost/site/login
  2. http://localhost/site/logout
  3. http://localhost/site/signup
  4. http://localhost/site/request-password-reset
  5. http://localhost/site/password-reset

7) Also some actions send flash messages, so you should use an AlertWidget to render flash messages on your site., (*17)

Using action events

You may use the following events:, (*18)

    /**
     * @return array
     */
    public function actions()
    {
        return [
            'login' => [
                'class' => 'yii2mod\user\actions\LoginAction',
                'on beforeLogin' => function ($event) {
                    // your custom code
                },
                'on afterLogin' => function ($event) {
                    // your custom code
                },
            ],
            'logout' => [
                'class' => 'yii2mod\user\actions\LogoutAction',
                'on beforeLogout' => function ($event) {
                    // your custom code
                },
                'on afterLogout' => function ($event) {
                    // your custom code
                },
            ],
            'signup' => [
                'class' => 'yii2mod\user\actions\SignupAction',
                'on beforeSignup' => function ($event) {
                    // your custom code
                },
                'on afterSignup' => function ($event) {
                    // your custom code
                },
            ],
            'request-password-reset' => [
                'class' => 'yii2mod\user\actions\RequestPasswordResetAction',
                'on beforeRequest' => function ($event) {
                    // your custom code
                },
                'on afterRequest' => function ($event) {
                    // your custom code
                },
            ],
            'password-reset' => [
                'class' => 'yii2mod\user\actions\PasswordResetAction',
                'on beforeReset' => function ($event) {
                    // your custom code
                },
                'on afterReset' => function ($event) {
                    // your custom code
                },
            ],
        ];
    }

Console commands

Setup

To enable console commands, you need to add module into console config of you app. /config/console.php in yii2-app-basic template, or /console/config/main.php in yii2-app-advanced., (*19)


return [ 'id' => 'app-console', 'modules' => [ 'user' => [ 'class' => 'yii2mod\user\ConsoleModule', ], ],

Available console actions

  • user/create - Creates a new user.

./yii user/create <email> <username> <password> - email (required): string - username (required): string - password (required): string
  • user/role/assign - Assign role to the user.

./yii user/role/assign <roleName> <email> - roleName (required): string - email (required): string
  • user/role/revoke - Revoke role from the user.

./yii user/role/revoke <roleName> <email> - roleName (required): string - email (required): string
  • user/delete - Deletes a user.

./yii user/delete <email> - email (required): string
  • user/update-password - Updates user's password to given.

./yii user/update-password <email> <password> - email (required): string - password (required): string

Internationalization

All text and messages introduced in this extension are translatable under category 'yii2mod.user'. You may use translations provided within this extension, using following application configuration:, (*20)

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'yii2mod.user' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@yii2mod/user/messages',
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

Support us

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff., (*21)

The Versions

20/08 2017

dev-master

9999999-dev

User module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 user management yii2-user user module

08/06 2017

2.1

2.1.0.0

User module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 user management yii2-user user module

11/02 2017

2.0

2.0.0.0

User module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 user management yii2-user user module

27/01 2017

1.9.4

1.9.4.0

User module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 user management yii2-user user module

22/11 2016

1.9.3

1.9.3.0

User module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 user management yii2-user user module

11/11 2016

1.9.2

1.9.2.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 user management yii2-user user module

09/11 2016

1.9.1

1.9.1.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 user management yii2-user user module

09/11 2016

1.9

1.9.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 user management yii2-user user module

02/08 2016

1.8.1

1.8.1.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 user management yii2-user user module

02/08 2016

1.8

1.8.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 user management yii2-user user module

28/07 2016

1.7

1.7.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 user management yii2-user user module

25/07 2016

1.6

1.6.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 user management yii2-user user module

21/07 2016

1.5

1.5.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

19/07 2016

1.4

1.4.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

18/07 2016

1.3

1.3.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

15/07 2016

1.2

1.2.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

07/07 2016

1.1

1.1.0.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

20/05 2016

1.0.2

1.0.2.0

User module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

22/03 2016

1.0.1

1.0.1.0

User module

  Sources   Download

MIT

by Igor Chepurnoy

extension yii2

13/07 2015

1.0

1.0.0.0

User module

  Sources   Download

MIT

by Igor Chepurnoy

extension yii2