User::class, 'message' => Yii::t('auth', 'This username has already been taken.')], ['username', 'string', 'min' => 2, 'max' => 255], ['email', 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'string', 'max' => 255], ['email', 'unique', 'targetClass' => User::class, 'message' => Yii::t('auth', 'This email address has already been taken.')], ['password', 'required'], ['password', 'string', 'min' => 6], ]; } /** * @return User|null * @throws Exception */ public function signup(): ?User { if (!$this->validate()) { return null; } $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); return $user->save() ? $user : null; } }