/** @inheritdoc */ public function rules() { return [[['username', 'email'], 'required'], [['username', 'email'], 'filter', 'filter' => 'trim'], ['username', 'match', 'pattern' => '/^[a-zA-Z]\\w+$/'], ['username', 'string', 'min' => 3, 'max' => 20], ['email', 'email'], [['email', 'username'], 'unique', 'when' => function ($model, $attribute) { return $this->user->{$attribute} != $model->{$attribute}; }, 'targetClass' => $this->module->modelMap['User']], ['new_password', 'string', 'min' => 6], ['current_password', function ($attr) { if (!Password::validate($this->{$attr}, $this->user->password_hash)) { $this->addError($attr, \Yii::t('user', 'Current password is not valid')); } }], ['new_password', function ($attr) { if (!$this->current_password) { $this->addError('current_password', \Yii::t('user', 'Current password cannot be blank')); } }]]; }
/** @inheritdoc */ public function rules() { return [[['login', 'password', 'offsetFromUTC'], 'required'], ['login', 'trim'], ['password', function ($attribute) { if ($this->user === null || !Password::validate($this->password, $this->user->password_hash)) { $this->addError($attribute, \Yii::t('user', 'Invalid login or password')); // Add error for login -- we don't want to indicate if the username failed or password $this->addError('login', \Yii::t('user', 'Invalid login or password')); } }], ['login', function ($attribute) { if ($this->user !== null) { $confirmationRequired = $this->module->enableConfirmation && !$this->module->enableUnconfirmedLogin; if ($confirmationRequired && !$this->user->getIsConfirmed()) { $this->addError($attribute, \Yii::t('user', 'You need to confirm your email address')); } if ($this->user->getIsBlocked()) { $this->addError($attribute, \Yii::t('user', 'Your account has been blocked')); } } }], ['rememberMe', 'boolean']]; }
/** @inheritdoc */ public function beforeSave($insert) { if ($insert) { $this->setAttribute('auth_key', \Yii::$app->security->generateRandomString()); if (\Yii::$app instanceof \yii\web\Application) { $this->setAttribute('registration_ip', \Yii::$app->request->userIP); } } if (!empty($this->password)) { if (!empty($this->getOldAttribute('password_hash'))) { $this->passwordChanged = !Password::validate($this->password, $this->getOldAttribute('password_hash')); } $this->setAttribute('password_hash', Password::hash($this->password)); } return parent::beforeSave($insert); }