Example #1
0
 /**
  * Активация восстановления пароля
  *
  * @param string $code
  *
  * @return Response
  * @throws Exception
  */
 public function actionPassword_recover_activate($code)
 {
     $row = PasswordRecoverDispatcher::query(['code' => $code])->one();
     if ($row === false) {
         throw new Exception('Не верный код активации');
     }
     $user = User::find($row['parent_id']);
     if (is_null($user)) {
         throw new Exception('Пользователь не найден');
     }
     $model = new \app\models\Form\PasswordNew();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->action($user)) {
         PasswordRecoverDispatcher::delete($row['parent_id']);
         Yii::$app->user->login($user);
         Yii::$app->session->setFlash('contactFormSubmitted');
         return $this->goHome();
     } else {
         return $this->render(['model' => $model]);
     }
 }