Yii2 - 登录后更改密码用户

时间:2017-05-10 07:26:38

标签: php yii2

我使用yii2开发了一个应用程序。然后我需要在afterLogin上验证我的用户以更改她/他的密码,因为我的用户模型中的用户默认定义为' 123456'。 如果仍然是123456,我想制作一个模态引导程序,以通知我的用户更改密码。

像这样的代码

public function actionCreate(){
    $model = new User();
    $model->scenario = 'create';

    if ($model->load(Yii::$app->request->post())) {
        $model->status = $model->status == 1 ? 10 : 0;
        $model->setPassword('123456');
        ....
}

所以,在config / web.php就像这样:

'user' => [
        'identityClass' => 'app\models\User',
        'on afterLogin' =>  ['app\events\AfterLoginEvent', 'handlePasswordForFirstTime'],
        // 'enableAutoLogin' => true,
    ],

在活动中,就像这样:

namespace app\events;
use Yii;
use app\models\User;

class AfterLoginEvent{
public static function handlePasswordForFirstTime($event){
    $user = new User();
    /*How to check if password still 123456*/
   }
}

全部谢谢。

1 个答案:

答案 0 :(得分:0)

只需验证密码

String biit = "READ";
相关问题