Ejemplo n.º 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 (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Password reset token cannot be blank.');
     }
     $this->_token = UserPasswordResetToken::findOne(['token' => $token]);
     if (!$this->_token) {
         throw new InvalidParamException('Wrong password reset token.');
     }
     parent::__construct($config);
 }
Ejemplo n.º 2
0
 public function getToken()
 {
     $user = $this->user;
     $token = UserPasswordResetToken::findOne(['user_id' => $user->id]);
     if ($token == null) {
         $token = new UserPasswordResetToken();
         $token->user_id = $user->id;
         $token->token = $user->generatePasswordResetToken();
         $token->save();
     }
     return $token;
 }