示例#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' => $this->module->modelMap['User']], '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'));
         }
     }]];
 }
示例#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', 'It looks like you need to confirm your email address'));
             }
             if ($this->user->getIsBanned()) {
                 $this->addError($attribute, Yii::t('user', 'Your account has been banned.'));
             }
         }
     }], 'rememberMe' => [['rememberMe'], 'boolean']];
 }
示例#3
0
 /** @inheritdoc */
 public function beforeSave($insert)
 {
     if ($insert) {
         $this->setAttribute('auth_key', Yii::$app->security->generateRandomString());
         if (Yii::$app instanceof WebApplication) {
             $this->setAttribute('signup_ip', Yii::$app->request->userIP);
         }
     }
     if (!empty($this->password)) {
         $this->setAttribute('password_hash', Password::hash($this->password));
     }
     return parent::beforeSave($insert);
 }