public function registrationScenario(RegistrationForm &$registrationForm)
 {
     $rules = ['trimUsername' => [['username'], 'filter', 'filter' => 'trim'], 'requiredFields' => [['username', 'password', 'confirmPassword'], 'required'], 'confirmPassword' => ['confirmPassword', 'compare', 'compareAttribute' => 'password'], 'uniqueUsername' => ['username', 'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username', 'message' => Yii::t('users', 'This username has already been taken')], 'usernameLength' => ['username', 'string', 'min' => 3, 'max' => 18]];
     if ($this->requireEmail === true) {
         $rules['emailRequired'] = ['email', 'required'];
         $rules['emailUnique'] = ['email', 'unique', 'targetClass' => User::className(), 'targetAttribute' => 'email', 'message' => Yii::t('users', 'This email address has already been taken')];
     }
     $this->addEmailRules($rules);
     $this->addPasswordRules($rules);
     return $rules;
 }
 public function rules()
 {
     return [[['email'], 'required'], [['email'], 'email'], [['email'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'email']];
 }