getClassMap()->get(User::class); return [ // username rules 'usernameLength' => ['username', 'string', 'min' => 3, 'max' => 255], 'usernameTrim' => ['username', 'filter', 'filter' => 'trim'], 'usernamePattern' => ['username', 'match', 'pattern' => $user->usernameRegex], 'usernameRequired' => ['username', 'required'], 'usernameUnique' => [ 'username', 'unique', 'targetClass' => $user, 'message' => Yii::t('user', 'This username has already been taken') ], // email rules 'emailTrim' => ['email', 'filter', 'filter' => 'trim'], 'emailRequired' => ['email', 'required'], 'emailPattern' => ['email', 'email'], 'emailUnique' => [ 'email', 'unique', 'targetClass' => $user, 'message' => Yii::t('user', 'This email address has already been taken') ], // password rules 'passwordRequired' => ['password', 'required', 'skipOnEmpty' => $this->module->enableGeneratingPassword], 'passwordLength' => ['password', 'string', 'min' => 6, 'max' => 72], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'email' => Yii::t('user', 'Email'), 'username' => Yii::t('user', 'Username'), 'password' => Yii::t('user', 'Password'), ]; } /** * Registers a new user account. If registration was successful it will set flash message. * * @return bool */ public function register() { if (!$this->validate()) { return false; } /** @var User $user */ $user = Yii::createObject(User::className()); $user->setScenario('register'); $this->loadAttributes($user); if (!$user->register()) { return false; } Yii::$app->session->setFlash( 'info', Yii::t( 'user', 'Your account has been created and a message with further instructions has been sent to your email' ) ); return true; } /** * Loads attributes to the user model. You should override this method if you are going to add new fields to the * registration form. You can read more in special guide. * * By default this method set all attributes of this model to the attributes of User model, so you should properly * configure safe attributes of your User model. * * @param User $user */ protected function loadAttributes(User $user) { $user->setAttributes($this->attributes); } }