Class frontend\models\ResetPasswordForm

Inheritancefrontend\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

Hide inherited properties

Property Type Description Defined By
$password frontend\models\ResetPasswordForm

Public Methods

Hide inherited 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

Hide inherited properties

$password public property
public $password null

Method Details

Hide inherited methods

__construct() public method

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);
}

            
resetPassword() public method

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);
}

            
rules() public method

public void rules ( )

                public function rules()
{
    return [
        ['password', 'required'],
        ['password', 'string', 'min' => Yii::$app->params['user.passwordMinLength']],
    ];
}