public function actionPreset()
 {
     $model = new ResetPasswordForm();
     $success = false;
     if (Yii::app()->request->isPostRequest) {
         $model->email = Yii::app()->request->getPost('myemail');
         if ($model->validate()) {
             $success = true;
             Mail::send($model->email, 'reset your ' . Yii::app()->name . ' password', 'preset_mail', ['salt' => $model->salt]);
         }
     }
     $this->render('preset', ['model' => $model, 'success' => $success]);
 }
 /**
  * Resets password.
  *
  * @param string $token
  * @return mixed
  * @throws BadRequestHttpException
  */
 public function actionResetPassword($token)
 {
     try {
         $model = new ResetPasswordForm($token);
     } catch (InvalidParamException $e) {
         throw new BadRequestHttpException($e->getMessage());
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
         Yii::$app->session->setFlash('success', 'New password was saved.');
         return $this->goHome();
     }
     return $this->render('resetPassword', ['model' => $model]);
 }
Beispiel #3
0
 /**
  * Displays the Reset Password page.
  */
 public function actionResetPassword()
 {
     $model = new ResetPasswordForm();
     // Collect user input data
     if (isset($_POST['ResetPasswordForm'])) {
         $model->attributes = $_POST['ResetPasswordForm'];
         // Validate user input
         if ($model->validate()) {
             // Search {{user}} table for current user
             $user = User::model()->find('id=' . Yii::app()->user->getId());
             if ($user == Null) {
                 throw new CHttpException(403, "Invalid request.");
             }
             // Update user's password and salt
             $user->password = $model->password;
             // Store password as a hashed string with salt
             $user->protectPassword();
             // Reset the flag to avoid resetting the second time
             $user->flags &= ~User::FLAG_PASSWORD_RESETTED;
             // Update user record
             if (!$user->save()) {
                 throw new CHttpException(403, "Couldn't update user info.");
             }
             // Redirect to user's profile page
             $this->redirect(array('user/view', 'id' => Yii::app()->user->getId()));
         }
     }
     // Display the Recover Password form
     $this->layout = '//layouts/column1';
     $this->render('resetPassword', array('model' => $model));
 }
Beispiel #4
0
 public function actionResetPassword()
 {
     if (isset($_GET['forgot_key'])) {
         $forgotKey = $_GET['forgot_key'];
     } else {
         $url = Yii::app()->createUrl('site/login');
         $this->redirect($url);
     }
     $user = User::model()->findByAttributes(array('user_key' => $forgotKey));
     if ($user == null) {
         $url = Yii::app()->createUrl('user/forgotpassword');
         $this->redirect($url);
     } else {
         $form = new ResetPasswordForm();
         // collect user input data
         if (isset($_POST['ResetPasswordForm'])) {
             $form->attributes = $_POST['ResetPasswordForm'];
             if ($form->validate()) {
                 $user->password = $user->encrypt($form->password);
                 $user->user_key = NULL;
                 $user->save(false);
                 Yii::app()->user->setFlash('resetSuccess', 'Password has been reset');
                 $url = Yii::app()->createUrl('site/login');
                 $this->redirect($url);
             }
         }
     }
     // display the reset password form
     $this->render('resetpassword', array('model' => $form));
 }
Beispiel #5
0
 public function actionReset()
 {
     $token = trim($_GET['token']);
     $model = new ResetPasswordForm();
     if (isset($_POST['ResetPasswordForm'])) {
         $model->attributes = $_POST['ResetPasswordForm'];
         if ($model->validate() && $model->reset()) {
             $str = '密码重置成功,请试着登录下!';
             Yii::app()->user->setFlash('success', $str);
             $this->redirect(array('s/signin'));
         }
     } else {
         $record = User::model()->findByAttributes(array('token' => $token));
         $model->token = $record->token;
         if ($record == null) {
             throw new CHttpException(404, 'The requested Reset Password does not exist.');
             exit;
         }
     }
     $this->_pageTitle = '重新设置密码' . API::lchart();
     $this->render('reset', array('record' => $record, 'model' => $model));
 }
 public function actionResetPassword()
 {
     $model = new ResetPasswordForm();
     if (!$model->checkCode()) {
         $this->redirect(Yii::app()->homeUrl);
     }
     // collect user input data
     if (isset($_POST['ResetPasswordForm'])) {
         $model->attributes = $_POST['ResetPasswordForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate()) {
             if ($model->changePassword()) {
                 $model->clear();
                 Yii::app()->user->logout(false);
                 Yii::app()->user->setFlash('success', Yii::t('common', 'Password is changed successfully. Log in with your new password.'));
                 $this->redirect(array('/site/login'));
             } else {
                 Yii::app()->user->setFlash('error', Yii::t('common', 'Something goes wrong'));
             }
         }
     }
     $this->pageTitle = array('Reset Password');
     $this->render('resetPassword', array('model' => $model));
 }
Beispiel #7
0
 public function actionReset()
 {
     $token = trim($_GET['token']);
     $model = new ResetPasswordForm();
     if (isset($_POST['ResetPasswordForm'])) {
         $model->attributes = $_POST['ResetPasswordForm'];
         if ($model->validate() && $model->reset()) {
             echo 'reset ok';
         }
     } else {
         $record = User::model()->findByAttributes(array('token' => $token));
         $model->token = $record->token;
         if ($record == null) {
             echo 'f**k';
             exit;
         }
     }
     $this->render('reset', array('record' => $record, 'model' => $model));
 }