Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. public function actionChangePassword()
  2.     {
  3.         $model = new PasswordForm;
  4.         $modelUser = Yii::$app->user->identity;
  5.  
  6.         if ($model->load(Yii::$app->request->post())) {
  7.             if ($model->validate()) {
  8.                 try {
  9.                     $modelUser->password_hash = Password::hash(['PasswordForm']['newpass']);
  10.                     if ($modelUser->save()) {
  11.                         \Yii::$app->getSession()->setFlash('success', 'Пароль изменен');
  12.                         return $this->redirect(['/user/main/settings']);
  13.                     } else {
  14.                         \Yii::$app->getSession()->setFlash('error', 'Возникла ошибка при сохранении');
  15.                         return $this->redirect(['/user/main/settings']);
  16.                     }
  17.                 } catch (Exception $exception) {
  18.  
  19.                 }
  20.             } else {
  21.                 \Yii::$app->getSession()->setFlash('error', 'Возникла ошибка');
  22.                 return $this->redirect(['/user/main/settings']);
  23.             }
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement