PHPackages                             yii2mod/yii2-user - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. yii2mod/yii2-user

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

yii2mod/yii2-user
=================

User module

2.1(9y ago)2817.5k↓53.6%10[4 issues](https://github.com/yii2mod/yii2-user/issues)1MITPHPPHP &gt;=5.6

Since Jul 13Pushed 6y ago6 watchersCompare

[ Source](https://github.com/yii2mod/yii2-user)[ Packagist](https://packagist.org/packages/yii2mod/yii2-user)[ RSS](/packages/yii2mod-yii2-user/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (20)Used By (1)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii2 User Extension
===================

[](#yii2-user-extension)

Flexible user registration and authentication module for Yii2

[![Latest Stable Version](https://camo.githubusercontent.com/e9c951d8f28dcf6c6e633759737a99b01fe463ac1e18bb004a688ddff7975784/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d757365722f762f737461626c65)](https://packagist.org/packages/yii2mod/yii2-user) [![Total Downloads](https://camo.githubusercontent.com/ec7c0934b49c0e6f50e6d690237a0761d2a5efbe4be3622095a56289c4f0e112/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d757365722f646f776e6c6f616473)](https://packagist.org/packages/yii2mod/yii2-user) [![License](https://camo.githubusercontent.com/1a09d24ed5e2d571833ae07270b5a3ce47a5603339f89172b102b336bb82af85/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d757365722f6c6963656e7365)](https://packagist.org/packages/yii2mod/yii2-user)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cf58e9d1753532a4f2c96eea91a0830cfcc5d2b9fc88daec2737bdfb3eda9a69/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796969326d6f642f796969322d757365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yii2mod/yii2-user/?branch=master) [![Build Status](https://camo.githubusercontent.com/3efa33248b90de17cfea748c6cb0ae2441cc1ac71e71c7c67be6c56d3d85593e/68747470733a2f2f7472617669732d63692e6f72672f796969326d6f642f796969322d757365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2mod/yii2-user)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

```
"yii2mod/yii2-user": "*"

```

to the require section of your `composer.json` file.

Actions
-------

[](#actions)

This extension provides several independent action classes, which provides particular operation support:

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
=============

[](#configuration)

1. If you use this extension without [base template](https://github.com/yii2mod/base), then you need execute migration by the following command:

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

```

2. You need to configure the `params` section in your project configuration:

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

3. Your need to create the UserModel class that be extends of [UserModel](https://github.com/yii2mod/yii2-user/blob/master/models/BaseUserModel.php) and configure the property `identityClass` for `user` component in your project configuration, for example:

```
'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.
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:

```

Hello ,

Follow the link below to reset your password:

```

> This template used for password reset email.

6. Add to SiteController (or configure via `$route` param in urlManager):

```
    /**
     * @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:

1.
2.
3.
4.
5.

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

Using action events
-------------------

[](#using-action-events)

You may use the following events:

```
    /**
     * @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
================

[](#console-commands)

Setup
-----

[](#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.

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

Available console actions
-------------------------

[](#available-console-actions)

- **user/create** - Creates a new user.

```
./yii user/create

- email (required): string
- username (required): string
- password (required): string
```

- **user/role/assign** - Assign role to the user.

```
./yii user/role/assign

- roleName (required): string
- email (required): string
```

- **user/role/revoke** - Revoke role from the user.

```
./yii user/role/revoke

- roleName (required): string
- email (required): string
```

- **user/delete** - Deletes a user.

```
./yii user/delete

- email (required): string
```

- **user/update-password** - Updates user's password to given.

```
./yii user/update-password

- email (required): string
- password (required): string
```

Internationalization
--------------------

[](#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:

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

Support us
----------

[](#support-us)

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~52 days

Total

19

Last Release

3313d ago

Major Versions

1.9.4 → 2.02017-02-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a53a15e1548ce60ee92591e71492a39eaaecfc88eaa1a9d7f353d5c910381de?d=identicon)[disem](/maintainers/disem)

---

Top Contributors

[![dmitry-semenov](https://avatars.githubusercontent.com/u/17027799?v=4)](https://github.com/dmitry-semenov "dmitry-semenov (5 commits)")[![laoheimao](https://avatars.githubusercontent.com/u/17297242?v=4)](https://github.com/laoheimao "laoheimao (1 commits)")

---

Tags

yii2yii2-extensionyii2-loginyii2-reset-passwordyii2-signupyii2-useryii2User managementyii2-useruser module

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/yii2mod-yii2-user/health.svg)

```
[![Health](https://phpackages.com/badges/yii2mod-yii2-user/health.svg)](https://phpackages.com/packages/yii2mod-yii2-user)
```

###  Alternatives

[dektrium/yii2-user

Flexible user registration and authentication module for Yii2

928815.9k38](/packages/dektrium-yii2-user)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
