Class frontend\models\ResetPasswordForm
Inheritance | frontend\models\ResetPasswordForm » yii\base\Model |
---|---|
Source Code | https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/models/ResetPasswordForm.php |
Password reset form
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$password | frontend\models\ResetPasswordForm |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | Creates a form model given a token. | frontend\models\ResetPasswordForm |
resetPassword() | Resets password. | frontend\models\ResetPasswordForm |
rules() | frontend\models\ResetPasswordForm |
Property Details
Method Details
Creates a form model given a token.
public void __construct ( $token, $config = [] ) | ||
$token | string | |
$config | array |
Name-value pairs that will be used to initialize the object properties |
throws | \yii\base\InvalidArgumentException |
if token is empty or not valid |
---|
public function __construct($token, $config = [])
{
if (empty($token) || !is_string($token)) {
throw new InvalidArgumentException('Password reset token cannot be blank.');
}
$this->_user = User::findByPasswordResetToken($token);
if (!$this->_user) {
throw new InvalidArgumentException('Wrong password reset token.');
}
parent::__construct($config);
}
Resets password.
public boolean resetPassword ( ) | ||
return | boolean |
If password was reset. |
---|
public function resetPassword()
{
$user = $this->_user;
$user->setPassword($this->password);
$user->removePasswordResetToken();
$user->generateAuthKey();
return $user->save(false);
}
public void rules ( ) |
public function rules()
{
return [
['password', 'required'],
['password', 'string', 'min' => Yii::$app->params['user.passwordMinLength']],
];
}