- 'password' => bcrypt($data['password']),
- ]);
- }
-
- /**
- * The registrations flow for all users.
- * @param array $userData
- * @param bool|false|SocialAccount $socialAccount
- * @param bool $emailVerified
- * @return RedirectResponse|Redirector
- * @throws UserRegistrationException
- */
- protected function registerUser(array $userData, $socialAccount = false, $emailVerified = false)
- {
- $registrationRestrict = setting('registration-restrict');
-
- if ($registrationRestrict) {
- $restrictedEmailDomains = explode(',', str_replace(' ', '', $registrationRestrict));
- $userEmailDomain = $domain = mb_substr(mb_strrchr($userData['email'], "@"), 1);
- if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
- throw new UserRegistrationException(trans('auth.registration_email_domain_invalid'), '/register');
- }
- }
-
- $newUser = $this->userRepo->registerNew($userData, $emailVerified);
- if ($socialAccount) {
- $newUser->socialAccounts()->save($socialAccount);
- }
-
- if ((setting('registration-confirmation') || $registrationRestrict) && !$emailVerified) {
- $newUser->save();
-
- try {
- $this->emailConfirmationService->sendConfirmation($newUser);
- } catch (Exception $e) {
- session()->flash('error', trans('auth.email_confirm_send_error'));
- }
-
- return redirect('/register/confirm');
- }
-
- auth()->login($newUser);
- session()->flash('success', trans('auth.register_success'));
- return redirect($this->redirectPath());
- }
-
- /**
- * Show the page to tell the user to check their email
- * and confirm their address.
- */
- public function getRegisterConfirmation()
- {
- return view('auth.register-confirm');
- }
-
- /**
- * Confirms an email via a token and logs the user into the system.
- * @param $token
- * @return RedirectResponse|Redirector
- * @throws ConfirmationEmailException
- * @throws Exception
- */
- public function confirmEmail($token)
- {
- try {
- $userId = $this->emailConfirmationService->checkTokenAndGetUserId($token);
- } catch (Exception $exception) {
-
- if ($exception instanceof UserTokenNotFoundException) {
- session()->flash('error', trans('errors.email_confirmation_invalid'));
- return redirect('/register');
- }
-
- if ($exception instanceof UserTokenExpiredException) {
- $user = $this->userRepo->getById($exception->userId);
- $this->emailConfirmationService->sendConfirmation($user);
- session()->flash('error', trans('errors.email_confirmation_expired'));
- return redirect('/register/confirm');
- }
-
- throw $exception;
- }
-
- $user = $this->userRepo->getById($userId);
- $user->email_confirmed = true;
- $user->save();
-
- auth()->login($user);
- session()->flash('success', trans('auth.email_confirm_success'));
- $this->emailConfirmationService->deleteByUser($user);
-
- return redirect($this->redirectPath);
- }
-
- /**
- * Shows a notice that a user's email address has not been confirmed,
- * Also has the option to re-send the confirmation email.
- * @return View
- */
- public function showAwaitingConfirmation()
- {
- return view('auth.user-unconfirmed');
- }
-
- /**
- * Resend the confirmation email
- * @param Request $request
- * @return View
- */
- public function resendConfirmation(Request $request)
- {
- $this->validate($request, [
- 'email' => 'required|email|exists:users,email'