/** @inheritdoc */ public function rules() { return [[['login', 'password'], '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')); } }], ['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')); } // softal // if ($this->user->getIsLocked()) { // $this->addError($attribute, \Yii::t('user', 'Your account has been locked due to too many failed login attempts')); // } } }], ['rememberMe', 'boolean'], ['captcha', 'captcha', 'on' => 'captcha']]; }
/** @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)) { $this->setAttribute('password_hash', Password::hash($this->password)); } return parent::beforeSave($insert); }