public function register() { if (!$this->validate()) { return false; } $user = new User(); $user->attributes = $this->attributes; $user->password = $user->passwordToHash($this->password); $user->role = UserRole::USER; if (!$user->save()) { $this->addErrors($user->getErrors()); return false; } \Yii::$app->mailer->compose('@app/auth/mail/registration', ['user' => $user])->setTo($user->email)->send(); return true; }