- $user = $this->userRepo->getByEmail($request->get('email'));
-
- try {
- $this->emailConfirmationService->sendConfirmation($user);
- } catch (Exception $e) {
- session()->flash('error', trans('auth.email_confirm_send_error'));
- return redirect('/register/confirm');
- }
-
- session()->flash('success', trans('auth.email_confirm_resent'));
- return redirect('/register/confirm');
- }
-
- /**
- * Redirect to the social site for authentication intended to register.
- * @param $socialDriver
- * @return mixed
- * @throws UserRegistrationException
- * @throws \BookStack\Exceptions\SocialDriverNotConfigured
- */
- public function socialRegister($socialDriver)
- {
- $this->checkRegistrationAllowed();
- session()->put('social-callback', 'register');
- return $this->socialAuthService->startRegister($socialDriver);
- }
-
- /**
- * The callback for social login services.
- * @param $socialDriver
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- * @throws SocialSignInException
- * @throws UserRegistrationException
- * @throws \BookStack\Exceptions\SocialDriverNotConfigured
- */
- public function socialCallback($socialDriver, Request $request)
- {
- if (!session()->has('social-callback')) {
- throw new SocialSignInException(trans('errors.social_no_action_defined'), '/login');
- }
-
- // Check request for error information
- if ($request->has('error') && $request->has('error_description')) {
- throw new SocialSignInException(trans('errors.social_login_bad_response', [
- 'socialAccount' => $socialDriver,
- 'error' => $request->get('error_description'),
- ]), '/login');
- }
-
- $action = session()->pull('social-callback');
-
- // Attempt login or fall-back to register if allowed.
- $socialUser = $this->socialAuthService->getSocialUser($socialDriver);
- if ($action == 'login') {
- try {
- return $this->socialAuthService->handleLoginCallback($socialDriver, $socialUser);
- } catch (SocialSignInAccountNotUsed $exception) {
- if ($this->socialAuthService->driverAutoRegisterEnabled($socialDriver)) {
- return $this->socialRegisterCallback($socialDriver, $socialUser);
- }
- throw $exception;
- }
- }
-
- if ($action == 'register') {
- return $this->socialRegisterCallback($socialDriver, $socialUser);
- }
-
- return redirect()->back();
- }
-
- /**
- * Detach a social account from a user.
- * @param $socialDriver
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function detachSocialAccount($socialDriver)
- {
- return $this->socialAuthService->detachSocialAccount($socialDriver);
- }
-
- /**
- * Register a new user after a registration callback.
- * @param string $socialDriver
- * @param SocialUser $socialUser
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- * @throws UserRegistrationException
- */
- protected function socialRegisterCallback(string $socialDriver, SocialUser $socialUser)
- {
- $socialUser = $this->socialAuthService->handleRegistrationCallback($socialDriver, $socialUser);
- $socialAccount = $this->socialAuthService->fillSocialAccount($socialDriver, $socialUser);
- $emailVerified = $this->socialAuthService->driverAutoConfirmEmailEnabled($socialDriver);
-
- // Create an array of the user data to create a new user instance
- $userData = [
- 'name' => $socialUser->getName(),
- 'email' => $socialUser->getEmail(),
- 'password' => str_random(30)
- ];
- return $this->registerUser($userData, $socialAccount, $emailVerified);