Auth extensions
If you want simple auth (login/signup/forgot), this is what you want! This extension
has simple action what have added in controller. Extension has events:, (*1)
, (*2)
Installation
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist yiicod/yii2-auth "*"
or add, (*5)
"yiicod/yii2-auth": "*"
to the require section of your composer.json., (*6)
run, (*7)
php yii migrate/up --migrationPath=@yiicod/auth/migrations
Please note that messages are wrapped with Yii::t()
to support message translations, you should define default message source for them if you don't use i18n., (*8)
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource'
],
],
],
Config
'components' => [
'auth' => [
'class' => 'yiicod\auth\Auth',
],
]
'bootstrap' => ['auth']
Using
Copy yiicod\auth\controllers\WebUserController to controllers folder.
After this you can use actions, (*9)
/**
* Declares class-based actions.
* For change functional use AuthUserBehavior.
* Auth events:
*
* - beforeLogin(ActionEvent)
* - afterLogin(ActionEvent)
* - errorLogin(ActionEvent)
*
* - beforeSignup(ActionEvent)
* - afterSignup(ActionEvent)
* - errorSignup(ActionEvent)
*
* - beforeCheckRecoveryKey(ActionEvent)
* - afterCheckRecoveryKey(ActionEvent)
* - errorCheckRecoveryKey(ActionEvent)
*
* - beforeForgot(ActionEvent)
* - afterForgot(ActionEvent)
* - errorForgot(ActionEvent)
*
* - beforeLogout(ActionEvent)
* - afterLogout(ActionEvent)
*
*
* Global events
* yiicod.auth.controllers.webUser.[Action class name].[Event name (beforeLogin)]
*
*
*/
public function actions()
{
return ArrayHelper::merge(parent::actions(), [
'login' => [
'class' => \yiicod\auth\actions\webUser\LoginAction::className(),
],
'requestPasswordReset' => [
'class' => \yiicod\auth\actions\webUser\RequestPasswordResetAction::className(),
],
'logout' => [
'class' => \yiicod\auth\actions\webUser\LogoutAction::className(),
],
'signup' => [
'class' => \yiicod\auth\actions\webUser\SignupAction::className(),
],
'resetPassword' => [
'class' => \yiicod\auth\actions\webUser\ResetPasswordAction::className(),
],
]
);
}