for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace site\models;
use common\models\User;
use yii\base\InvalidArgumentException;
use yii\base\Model;
use Yii;
/**
* Password reset form
*/
class ResetPasswordForm extends Model
{
public $password;
* @var \common\models\User
private $_user;
* 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\InvalidArgumentException if token is empty or not valid
public function __construct($token, \common\models\User $user, $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);
* @inheritdoc
public function rules()
return [
['password', 'required'],
['password', 'string', 'min' => 6],
];
* Resets password.
* @return boolean if password was reset.
public function resetPassword()
$user = $this->_user;
$user->password = $this->password;
$user->removePasswordResetToken();
return $user->save();