Exemplo n.º 1
0
 public function rules()
 {
     // Get the parent fules.
     $rules = parent::rules();
     // Replace the password validator.
     $rules['passwordValidate'] = ['password', function ($attribute) {
         $error = Yii::t('user', 'Invalid login or password');
         $user = $this->user;
         if ($user === null) {
             $this->addError($attribute, $error);
             return;
         }
         $validPass = false;
         $password = $this->password;
         $hash = $user->password_hash;
         // Try to validate hash, might throw if hash is invalid.
         try {
             $validPass = Password::validate($password, $hash);
         } catch (InvalidParamException $e) {
             // Do nothing.
         }
         // If a valid and modern hash, return now.
         if ($validPass) {
             return;
         }
         // Validate against legacy hashes.
         if ($this->validLegacyHash($password, $hash, $user)) {
             $user->resetPassword($this->password);
         } else {
             $this->addError($attribute, $error);
         }
     }];
     // Return the modified rules.
     return $rules;
 }
 public function rules()
 {
     $rules = parent::rules();
     $rules['activationValidate'] = ['login', function ($attribute) {
         if ($this->user !== null) {
             if (!$this->user->esActivo) {
                 $this->addError($attribute, \Yii::t('core', 'An admin must activate your account '));
             }
         }
     }];
     return $rules;
 }
 /** @inheritdoc */
 public function rules()
 {
     return array_replace_recursive(parent::rules(), ['requiredFields' => [['email', 'password'], 'required'], 'loginTrim' => ['email', 'trim'], 'emailPattern' => ['email', 'email'], 'confirmationValidate' => ['email', 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' => ['rememberMe', 'boolean']]);
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function rules()
 {
     $rules = parent::rules();
     return ArrayHelper::merge($rules, ['backendLoginValidate' => ['login', function ($attribute) {
         if ($this->user !== null && $this->user->getRole()->exists() && ($role = $this->user->getRole()->one())) {
             /** @var $role Role */
             if ($role->is_backend_login == 0) {
                 if (Module::hasMultiLanguage()) {
                     $this->addError($attribute, RoleHelper::translate('invalid_login_or_password'));
                 } else {
                     $this->addError($attribute, Yii::t('role', 'Invalid login or password'));
                 }
             }
         }
     }]]);
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     $rules = parent::rules();
     return $rules;
 }