コード例 #1
0
 /**
  * [actionChangePassword Ubah password jika change password date null]
  * @return url
  */
 public function actionChangePassword()
 {
     // $this->layout='login';
     $model = new LoginForm(['scenario' => 'changePassword']);
     $session = new Session();
     $username = $session->get('user_id');
     if ($model->load(Yii::$app->request->post()) && $model->updatePassword()) {
         $user = User::find()->where(['username' => $model->username])->one();
         $user->setPassword($model->new_password);
         $user->change_pass_date = date('Y-m-d H:i:s');
         $user->generateAuthKey();
         if ($user->save()) {
             return $this->goHome();
         }
     } else {
         Yii::$app->user->logout();
         return $this->render('change-password', ['model' => $model, 'username' => $username]);
     }
 }