-
- /**
- * The callback for social login services.
- * @param $socialDriver
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- * @throws SocialSignInException
- */
- public function socialCallback($socialDriver)
- {
- if (session()->has('social-callback')) {
- $action = session()->pull('social-callback');
- if ($action == 'login') {
- return $this->socialAuthService->handleLoginCallback($socialDriver);
- } elseif ($action == 'register') {
- return $this->socialRegisterCallback($socialDriver);
- }
- } else {
- throw new SocialSignInException('No action defined', '/login');
- }
- 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 $socialDriver
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- * @throws UserRegistrationException
- */
- protected function socialRegisterCallback($socialDriver)
- {
- $socialUser = $this->socialAuthService->handleRegistrationCallback($socialDriver);
- $socialAccount = $this->socialAuthService->fillSocialAccount($socialDriver, $socialUser);
-
- // 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);
- }
-
-
-}
\ No newline at end of file