为 Yii2 框架提供的简单身份验证(登录、注册、忘记密码)及强大的扩展功能
1.0.2
2015-11-01 20:02 UTC
Requires
This package is auto-updated.
Last update: 2024-08-27 00:11:00 UTC
README
如果您需要简单的身份验证(登录/注册/忘记密码),这正是您需要的!此扩展已在控制器中添加了简单操作。扩展具有事件
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist yiicod/yii2-auth "*"
或者
"yiicod/yii2-auth": "*"
将以下内容添加到您的 composer.json 文件中的 require 部分。
运行
php yii migrate/up --migrationPath=@yiicod/auth/migrations
请注意,消息通过 Yii::t()
包装以支持消息翻译,如果您不使用 i18n,则应定义它们的默认消息源。
'i18n' => [ 'translations' => [ '*' => [ 'class' => 'yii\i18n\PhpMessageSource' ], ], ],
配置
'components' => [ 'auth' => [ 'class' => 'yiicod\auth\Auth', ], ] 'bootstrap' => ['auth']
使用
将 yiicod\auth\controllers\WebUserController 复制到控制器文件夹。之后,您可以使用操作
/** * 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(), ], ] ); }