Ejemplo n.º 1
0
 /** @inheritdoc */
 public function rules()
 {
     return ['usernameRequired' => ['username', 'required'], 'usernameTrim' => ['username', 'filter', 'filter' => 'trim'], 'usernameLength' => ['username', 'string', 'min' => 3, 'max' => 255], 'usernamePattern' => ['username', 'match', 'pattern' => '/^[-a-zA-Z0-9_\\.@]+$/'], 'emailRequired' => ['email', 'required'], 'emailTrim' => ['email', 'filter', 'filter' => 'trim'], 'emailPattern' => ['email', 'email'], 'emailUsernameUnique' => [['email', 'username'], 'unique', 'when' => function ($model, $attribute) {
         return $this->user->{$attribute} != $model->{$attribute};
     }, 'targetClass' => User::className()], 'newPasswordLength' => ['new_password', 'string', 'min' => 6], 'currentPasswordRequired' => ['current_password', 'required'], 'currentPasswordValidate' => ['current_password', function ($attr) {
         if (!Password::validate($this->{$attr}, $this->user->password_hash)) {
             $this->addError($attr, Yii::t('user', 'Current password is not valid'));
         }
     }]];
 }
Ejemplo n.º 2
0
 /** @inheritdoc */
 public function rules()
 {
     return ['requiredFields' => [['login', 'password'], 'required'], 'loginTrim' => ['login', 'trim'], 'passwordValidate' => ['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'));
         }
     }], 'confirmationValidate' => ['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' => ['rememberMe', 'boolean']];
 }