mihaildev/yii2-user

Yii2 Simple User Module

Installs: 19

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

v1.0.0 2016-10-24 00:27 UTC

This package is not auto-updated.

Last update: 2024-11-09 20:12:25 UTC


README

Простая авторизация для сайта

Установка и Настройка

  1. добавляем в composer.json - "mihaildev/yii2-user": "*"
  2. замена стандартной компоненты
'components' => [
        'user' => [
            'class' => 'mihaildev\user\Component',
            'enableAutoLogin' => true,
            'loginUrl' => ['/site/login'], //'loginUrl' => ['/user/login'],
            'userList' => [
                '1' => [// id value
                  'id' => '1',
                  'username' => 'admin',
                  'password' => 'admin',
                ]
            ],
            'authKeySalt' => 'SomeSecreteValue'
        ],
  1. добавление в контроллер действий
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout'],
                'rules' => [
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    public function actions()
    {
        return [
            'login' => [
                'class' => 'mihaildev\user\action\LogIn',
                //'template' => 'login' // default: @mihaildev/user/views/login.php,
                //'defaultUrl' => ['/site/index'],

            ],
            'logout' => 'mihaildev\user\action\LogOut',
        ];
    }

или добавляем контроллер mihaildev\user\Controller

'controllerMap' => [
        'user' => [
            'class' => 'mihaildev\user\Controller',
            //'template' => 'login' // default: @mihaildev/user/views/login.php,
            //'defaultUrl' => ['/site/index'],
        ]