All Projects β†’ yii2mod β†’ yii2-user

yii2mod / yii2-user

Licence: MIT license
Flexible user registration and authentication module for Yii2.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-user

yii2-fileapi-widget
Yii2 FileAPI widget.
Stars: ✭ 51 (+112.5%)
Mutual labels:  yii2, yii2-extension
yii2-emoji
πŸ˜„ this is a emoji extension of yii2.
Stars: ✭ 17 (-29.17%)
Mutual labels:  yii2, yii2-extension
yii2-jwt-tools
An easy way to configure JWT authentication and validation on Yii Framework 2 Projects
Stars: ✭ 22 (-8.33%)
Mutual labels:  yii2, yii2-extension
yii2-sweet-submit
sweet sumit using sweetalert
Stars: ✭ 26 (+8.33%)
Mutual labels:  yii2, yii2-extension
yii2-ion-slider
Easily customizable range slider with skins support.
Stars: ✭ 21 (-12.5%)
Mutual labels:  yii2, yii2-extension
behavior-trait
Allows handling events via inline declared methods, which can be added by traits
Stars: ✭ 18 (-25%)
Mutual labels:  yii2, yii2-extension
yii2-linkable-behavior
Yii2 behavior to help creating urls easier
Stars: ✭ 12 (-50%)
Mutual labels:  yii2, yii2-extension
yii2-stat
Yii2 Multi Web Statistic Module (yametrika, google-analytic, own db-counter)
Stars: ✭ 18 (-25%)
Mutual labels:  yii2, yii2-extension
yii2-array-query
Yii2 component that allows for searching/filtering the elements of an array.
Stars: ✭ 34 (+41.67%)
Mutual labels:  yii2, yii2-extension
yii2-vote
Provides voting for any model πŸ‘ πŸ‘Ž
Stars: ✭ 70 (+191.67%)
Mutual labels:  yii2, yii2-extension
yii2-cashier
Yii2 Cashier provides an interface to Stripe's subscription billing services.
Stars: ✭ 43 (+79.17%)
Mutual labels:  yii2, yii2-extension
yii2-elasticsearch
Elasticsearch client based on official Elasticsearch PHP library
Stars: ✭ 14 (-41.67%)
Mutual labels:  yii2, yii2-extension
ar-search
Provides unified search model for Yii ActiveRecord
Stars: ✭ 31 (+29.17%)
Mutual labels:  yii2, yii2-extension
yii2-pgsql
Improved PostgreSQL schemas for Yii2
Stars: ✭ 34 (+41.67%)
Mutual labels:  yii2, yii2-extension
yii2-newsletter
Module for saving user contacts from newsletter form to database
Stars: ✭ 17 (-29.17%)
Mutual labels:  yii2, yii2-extension
yii2-bankcard-info
ι“Άθ‘Œε‘ε‘ε·εˆ†ζžοΌˆYii2扩展)
Stars: ✭ 15 (-37.5%)
Mutual labels:  yii2, yii2-extension
yii2-mailqueue
Yii2 mail queue component for yii2-swiftmailer.
Stars: ✭ 15 (-37.5%)
Mutual labels:  yii2, yii2-extension
yii2-translatable
Translatable behavior aggregates logic of linking translations to the primary model
Stars: ✭ 15 (-37.5%)
Mutual labels:  yii2, yii2-extension
yii2-rollbar
Rollbar for Yii2
Stars: ✭ 36 (+50%)
Mutual labels:  yii2, yii2-extension
yii2-js-urlmanager
That extension provide a way to create urls from your frontend part.
Stars: ✭ 53 (+120.83%)
Mutual labels:  yii2, yii2-extension

Yii2 User Extension


Flexible user registration and authentication module for Yii2

Latest Stable Version Total Downloads License Scrutinizer Code Quality Build Status

Installation

The preferred way to install this extension is through composer.

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

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.
  1. [[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.
  1. [[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.
  1. [[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.
  1. [[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:
php yii migrate/up --migrationPath=@vendor/yii2mod/yii2-user/migrations
  1. You need to configure the params section in your project configuration:
'params' => [
   'user.passwordResetTokenExpire' => 3600
]
  1. 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:
'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();
    }
],
  1. For sending emails you need to configure the mailer component in the configuration of your project.

  2. 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:

<?php

use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $user */

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

Hello <?php echo Html::encode($user->username) ?>,

Follow the link below to reset your password:

<?php echo Html::a(Html::encode($resetLink), $resetLink) ?>

This template used for password reset email.

  1. 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. 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
  1. Also some actions send flash messages, so you should use an AlertWidget to render flash messages on your site.

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

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

  • 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:

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].