Esempio n. 1
0
 /**
  * Sends an email to the specified email address using the information collected by this model.
  *
  * @param  string $email the target email address
  *
  * @return boolean whether the model passes validation
  *
  * @throws \cs\web\Exception
  */
 public function send()
 {
     if ($this->validate()) {
         $user = User::find(['email' => strtolower($this->email)]);
         if (is_null($user)) {
             throw new Exception('Пользователь не найден');
         }
         $fields = \app\service\PasswordRecoverDispatcher::insert($user->getId());
         Yii::info($fields, 'cap\\recover');
         \cs\Application::mail($this->email, 'Восстановление пароля', 'password_recover', ['user' => $user, 'url' => Url::to(['auth/password_recover_activate', 'code' => $fields['code']], true), 'datetime' => Yii::$app->formatter->asDatetime($fields['date_finish'])]);
         return true;
     } else {
         return false;
     }
 }
Esempio n. 2
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]);
     }
 }