Inheritance: extends yii\base\Model
Example #1
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $this->layout = 'login';
     $model = new LoginForm();
     $passResetModel = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         if ($passResetModel->load(Yii::$app->request->post()) && $passResetModel->validate()) {
             /*Yii::$app->mailer->compose()
                  ->setFrom('*****@*****.**')
                  ->setTo('*****@*****.**')
                  ->setSubject('Email sent from Yii2-Swiftmailer')
             	 ->setTextBody('asdfasdasd')
                  ->send();*/
             if ($passResetModel->sendEmail()) {
                 Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
                 return $this->goHome();
             } else {
                 Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
                 return $this->goBack();
             }
         } else {
             return $this->render('login', ['model' => $model, 'passResetModel' => $passResetModel]);
         }
     }
 }
Example #2
0
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #3
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Данные для восстановления отправлены на Ваш E-mail');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'К сожалению, такой адрес не существует');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 public function testSendEmailSuccessfully()
 {
     $userFixture = $this->tester->grabFixture('user', 0);
     $model = new PasswordResetRequestForm();
     $model->email = $userFixture['email'];
     $user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
     expect_that($model->sendEmail());
     expect_that($user->password_reset_token);
     $emailMessage = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $emailMessage)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($emailMessage->getTo())->hasKey($model->email);
     expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']);
 }
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->getSession()->setFlash('resultSentMail', 'Проверьте ваш Email для дальнейших инструкций.');
             return $this->redirect(Yii::$app->request->referrer);
             //return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('resultSentMail', 'Мы не смогли обновить пароль для вашего Email.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 public function testSendEmailCorrectUser()
 {
     $model = new PasswordResetRequestForm();
     $model->email = $this->user[0]['email'];
     $user = User::findOne(['password_reset_token' => $this->user[0]['password_reset_token']]);
     expect('email sent', $model->sendEmail())->true();
     expect('user has valid token', $user->password_reset_token)->notNull();
     $this->specify('message has correct format', function () use($model) {
         expect('message file exists', file_exists($this->getMessageFile()))->true();
         $message = file_get_contents($this->getMessageFile());
         expect('message "from" is correct', $message)->contains(Yii::$app->params['supportEmail']);
         expect('message "to" is correct', $message)->contains($model->email);
     });
 }
Example #7
0
 public function actionRequestPasswordReset()
 {
     $this->title = '找回密码' . ' - ' . Yii::$app->name;
     $this->description = '';
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->getSession()->setFlash('success', '邮件发送成功!请检查您的电子邮箱以获得进一步操作说明。');
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('error', '很抱歉,我们无法提供密码重置邮件。');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #8
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'RESET_PASSWORD_CHECK_MAIL_INSTRUCTIONS'));
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'ERROR_SEND_EMAIL'));
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 public function actionRequestPasswordReset($type = 'sms', $step = '1')
 {
     if ($type === 'sms') {
         $session = Yii::$app->session;
         $session->open();
         if ($step !== '2') {
             $model = new PasswordResetMobileRequestForm();
             if ($model->load(Yii::$app->request->post()) && $model->validate()) {
                 if ($model->sendMsg()) {
                     $session['passwordResetTimeout'] = time() + 900;
                     // 15 minutes
                     $session['passwordResetMobile'] = $model->mobile;
                     return $this->redirect(['request-password-reset', 'type' => $type, 'step' => '2']);
                 } else {
                     $session->setFlash('smsFailure', '对不起,验证码发送失败。');
                 }
             }
         } elseif (isset($session['passwordResetTimeout']) && $session['passwordResetTimeout'] >= time()) {
             $model = new PasswordResetVerifyForm();
             $model->load(Yii::$app->request->post());
             if (Yii::$app->request->isAjax) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($model);
             }
             if (Yii::$app->request->isPost && $model->validate()) {
                 if ($model->generateToken()) {
                     $model->clearSession();
                     return $this->redirect(['reset-password', 'token' => $model->user->password_reset_token]);
                 } else {
                     $session->setFlash('resetErr', '操作失败,请稍后再试!');
                 }
             }
         } else {
             $session->setFlash('resetAgain', '对不起,请您重新开始一次。');
             return $this->redirect(['request-password-reset', 'type' => $type]);
         }
     } elseif ($type === 'email') {
         $model = new PasswordResetRequestForm();
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             if ($model->sendEmail()) {
                 Yii::$app->getSession()->setFlash('emailSent', '我们已经为您发送了一条链接,请进入邮箱查看。');
                 return $this->refresh();
             } else {
                 Yii::$app->getSession()->setFlash('emailFailure', '对不起,我们无法对您的账户进行重置密码操作。');
             }
         }
     } else {
         throw new BadRequestHttpException('参数错误!');
     }
     return $this->render('requestPasswordResetToken', ['model' => $model, 'type' => $type, 'step' => $step]);
 }
Example #10
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Первый этап успешно завершён. Мы отправили дальнейшие инструкции на ваш email.');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'К сожалению, вы указали незарегистрированный email.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #11
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     $model->email = Yii::$app->user->identity->email;
     $model->password = Yii::$app->security->generateRandomString(6);
     if ($model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Check your email for new password.');
             return $this->redirect(["site/user"]);
         } else {
             Yii::$app->session->setFlash('error', 'Sorry, we are unable to set up new password for email provided.');
             return $this->redirect(["site/user"]);
         }
     }
 }
Example #12
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', Lang::t('page/siteLogin', 'reset1Success'));
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', Lang::t('page/siteLogin', 'reset1Error'));
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #13
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $this->view->registerCssFile('/css/shortPage.css');
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Проверьте почиовый ящик и следуйте инструкциям.');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'Извините, мы не смогли отправить Вам письмо с новым паролем.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #14
0
 public function actionRequestPasswordReset()
 {
     if (!Yii::$app->request->isAjax) {
         return $this->goHome();
     }
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             $erros = ActiveForm::validate($model);
             if (!empty($erros)) {
                 return $erros;
             }
             if (!Yii::$app->request->post('send')) {
                 return $erros;
             }
             if (!$model->sendEmail()) {
                 $erros = [Html::getInputId($model, 'email') => [0 => "Не удалось отправить письмо."]];
                 return $erros;
             } else {
                 Yii::$app->response->statusText = 'send=' . Url::toRoute(['site/request-password-reset-notify']);
                 Yii::$app->response->send();
             }
         }
     }
     return $this->renderAjax('requestPasswordResetToken', ['model' => $model]);
 }
Example #15
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', I18n::t('Your password reset request submitted successfully'));
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', I18n::t('Unable to reset password for email provided') . '. ' . I18n::t('Please try again'));
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #16
0
 public function actionRequestPasswordReset()
 {
     $this->layout = 'login';
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Проверьте вашу электронную почту для получения дальнейших инструкций.'));
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'К сожалению, мы не в состоянии сбросить пароль. Пожалуйста попробуйте позже... Если проблема будет повторятся, обратитесь в службу поддержки.'));
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #17
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'Password_reset_success'));
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Error_sending_email'));
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #18
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $this->layout = 'empty_layout';
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Проверьте свой почтовый ящик для дальнейших инструкция.');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'Извините, сброс пароля невозможен из-за неверно указанного e-mail.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->addFlash('success', Yii::t('frontend', 'Check your email for further instructions.'));
             return $this->goHome();
         } else {
             Yii::$app->session->addFlash('error', Yii::t('frontend', 'Sorry, we are unable to send reset password email. Please contact site administrator for more details.'));
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Verifique seu e-mail para obter mais instruções.');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'Desculpe, mas não foi possível redefinir a senha para o email fornecido.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->success == 'true') {
             Yii::$app->getSession()->setFlash('success', ['type' => 'success', 'duration' => 5000, 'icon' => 'glyphicon glyphicon-envelope', 'message' => $model->message, 'title' => 'Reestablecer contraseña', 'positonY' => 'top', 'positonX' => 'center']);
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('danger', ['type' => 'danger', 'duration' => 5000, 'icon' => 'glyphicon glyphicon-exclamation-sign', 'message' => $model->message, 'title' => 'Reestablecer contraseña', 'positonY' => 'top', 'positonX' => 'center']);
             return $this->goHome();
         }
     }
     return $this->renderAjax('requestPasswordResetToken', ['model' => $model]);
 }
Example #22
0
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->getSession()->setFlash('success', 'Cek Inbox email anda untuk mengikuti langkah selanjutnya.');
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('error', 'Maaf permintaan reset passwword gagal');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     $model->load(Yii::$app->request->post());
     $model->validate();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
         } else {
             Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
         }
     } else {
         Yii::$app->session->setFlash('error', 'Sorry, no user with the email provided.');
     }
     return $this->redirect(['site/login']);
     /*return $this->render('requestPasswordResetToken', [
           'model' => $model,
       ]);*/
 }
Example #24
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestpassword()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post())) {
         if (User::findByUsername($model->email)) {
             $model->email = User::findByUsername($model->email)->email;
         }
         if ($model->validate()) {
             if ($model->sendEmail()) {
                 Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
                 echo 1;
                 // return $this->goHome();
             } else {
                 Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
                 echo 2;
             }
         } else {
             return false;
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #25
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', '邮件已发送,请注意查收!');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', '对不起,邮箱无法通过验证!');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #26
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             //                Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
             //                return $this->goHome();
             $info = "<div class='card'>我们给你的邮箱 <strong>" . $model->email . "</strong> 发送一封,请查收邮件,按邮件提示修改密码</div>";
         } else {
             $info = "<div class='card'>我们给你的邮箱 <strong>" . $model->email . "</strong> 发送修改密码的邮件失败,请检查邮箱是否正确,或者换一个邮箱</div>";
             //                Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
         }
         return $this->renderContent($info);
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #27
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Chequee su casilla de correo para continuar con el cambio de clave');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'No se puede continuar con la casilla de correo provista por Ud.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #28
0
 /**
  * Requests password reset.
  *
  * @return mixed
  */
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->session->setFlash('success', 'Проверьте свою электронную почту для получения дальнейших инструкций.');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'К сожалению, мы не можем сбросить пароль, попробуйте позднее.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->getSession()->setFlash('success', 'Проверьте вашу электронную почту.');
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('error', 'К сожалению, мы не в состоянии сбросить пароль для этой электронной почты.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }
Example #30
0
 public function actionRequestPasswordReset()
 {
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail()) {
             Yii::$app->getSession()->setFlash('success', '检查你的电子邮件.');
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('error', '对不起, 我们不能通过你的电子邮件更新密码');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }