Example #1
0
 /**
  * Creates a form model given a token.
  *
  * @param  string                          $token
  * @param  array                           $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if ($token === '') {
         throw new InvalidParamException('Токен для сброса пароля не может быть пустым');
     }
     if (!($this->_user = User::findByPasswordResetToken($token))) {
         throw new InvalidParamException('Неправильный токен сброса пароля');
     }
     parent::__construct($config);
 }
 /**
  * Creates a form model given a token.
  *
  * @param string $token  Password reset token.
  * @param array  $config Name-value pairs that will be used to initialize the object properties.
  *
  * @throws \yii\base\InvalidParamException  If token is empty or not valid.
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException(Yii::t('app', 'Password reset token cannot be blank.'));
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException(Yii::t('app', 'Wrong password reset token.'));
     }
     parent::__construct($config);
 }
 /**
  * Validate token
  *
  * @param string $token
  * @return boolean
  */
 public function validateToken($token)
 {
     if (empty($token) || !is_string($token)) {
         return false;
     }
     $this->user = User::findByPasswordResetToken($token);
     if (!$this->user) {
         return false;
     }
     return true;
 }
 function __construct($key, $config = [])
 {
     if (empty($key) || !is_string($key)) {
         throw new InvalidParamException('Ключ не может быть пустым');
     }
     $this->_user = User::findByPasswordResetToken($key);
     if (!$this->_user) {
         throw new InvalidParamException('Неверный ключ');
     }
     parent::__construct($config);
 }
 /**
  * Creates a form model given a token.
  * @param  string                          $token
  * @param  array                           $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $password, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Ключ для восстановления пароля не найден.');
     }
     if (empty($password) || !is_string($password)) {
         throw new InvalidParamException('Пароль не задан.');
     }
     $this->_user = User::findByPasswordResetToken($token);
     $this->password = $password;
     if (!$this->_user) {
         throw new InvalidParamException('Неправильный ключ для восстановления пароля.');
     }
     parent::__construct($config);
 }
Example #6
0
 public function actionChangepass()
 {
     if (!($post = \Yii::$app->getRequest()->getBodyParams())) {
         throw new \yii\web\HttpException(400, 'No data was posted');
     }
     $model = User::findByPasswordResetToken($post['token']);
     if (!$model) {
         throw new \yii\web\HttpException(422, 'Password reset token is not valid');
     }
     $password = $post['password'];
     $validator = new \yii\validators\StringValidator(['min' => 3, 'max' => 12]);
     if (!$validator->validate($password, $error)) {
         throw new \yii\web\HttpException(422, $error);
     }
     $model->setPassword($post['password']);
     $model->removePasswordResetToken();
     $model->save();
     echo $model->username;
     exit('ok');
 }
Example #7
0
 public function actionReset($token)
 {
     $user = User::findByPasswordResetToken($token);
     $model = new ResetForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($user) {
             $user->removePasswordResetToken();
             $user->password = md5($model->password);
             $user->save();
             Yii::$app->getSession()->setFlash('success', 'Su password ha sido cambiado con éxito.');
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('warning', 'El token de seguridad es inválido o ya ha expirado.');
             return $this->goHome();
         }
     }
     return $this->render('reset', ['model' => $model]);
 }
 public function actionChangepass()
 {
     /*        echo \Yii::$app->session->get('role');
             exit('d');*/
     if (!($post = \Yii::$app->getRequest()->getBodyParams())) {
         throw new \yii\web\HttpException(400, 'Дані не отримані');
     }
     $model = User::findByPasswordResetToken($post['token']);
     if (!$model) {
         throw new \yii\web\HttpException(422, 'Ключ для відновлення паролю не є коректним');
     }
     $password = $post['password'];
     $validator = new \yii\validators\StringValidator(['min' => 3, 'max' => 12, 'tooShort' => 'Пароль повинен містити мінімум {min, number} символи', 'tooLong' => 'Пароль повинен містити не більше {max, number} символів']);
     if (!$validator->validate($password, $error)) {
         throw new \yii\web\HttpException(422, $error);
     }
     $model->setPassword($password);
     $model->removePasswordResetToken();
     $model->save();
     echo $model->username;
     exit('ok');
 }
Example #9
0
 /**
  * установить новый пароль
  * @param type $token
  * @return type
  */
 public function actionNewPassword($token)
 {
     $user = User::findByPasswordResetToken($token);
     if ($user) {
         $user->setNewPassword();
         Yii::$app->getSession()->setFlash('success', 'Новый пароль выслан на почту');
     } else {
         Yii::$app->getSession()->setFlash('error', 'Токен не действителен');
     }
     return $this->goHome();
 }
Example #10
0
 public function testFindByPasswordResetToken()
 {
     $user = $this->tester->grabFixture('user', 'user-1');
     expect_that($user = User::findByPasswordResetToken($user->password_reset_token));
     expect($user->username)->equals('superuser');
     expect_not(User::findByPasswordResetToken(999));
 }