X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/da1cea06ca5db56a9635bf8bb01da2516d601620..refs/pull/2716/head:/app/Http/Controllers/Auth/SocialController.php diff --git a/app/Http/Controllers/Auth/SocialController.php b/app/Http/Controllers/Auth/SocialController.php index 0c53c9233..447f0afc9 100644 --- a/app/Http/Controllers/Auth/SocialController.php +++ b/app/Http/Controllers/Auth/SocialController.php @@ -2,16 +2,17 @@ namespace BookStack\Http\Controllers\Auth; +use BookStack\Actions\ActivityType; use BookStack\Auth\Access\RegistrationService; use BookStack\Auth\Access\SocialAuthService; use BookStack\Exceptions\SocialDriverNotConfigured; use BookStack\Exceptions\SocialSignInAccountNotUsed; use BookStack\Exceptions\SocialSignInException; use BookStack\Exceptions\UserRegistrationException; +use BookStack\Facades\Theme; use BookStack\Http\Controllers\Controller; -use Illuminate\Http\RedirectResponse; +use BookStack\Theming\ThemeEvents; use Illuminate\Http\Request; -use Illuminate\Routing\Redirector; use Illuminate\Support\Str; use Laravel\Socialite\Contracts\User as SocialUser; @@ -31,12 +32,11 @@ class SocialController extends Controller $this->registrationService = $registrationService; } - /** * Redirect to the relevant social site. - * @throws \BookStack\Exceptions\SocialDriverNotConfigured + * @throws SocialDriverNotConfigured */ - public function getSocialLogin(string $socialDriver) + public function login(string $socialDriver) { session()->put('social-callback', 'login'); return $this->socialAuthService->startLogIn($socialDriver); @@ -47,7 +47,7 @@ class SocialController extends Controller * @throws SocialDriverNotConfigured * @throws UserRegistrationException */ - public function socialRegister(string $socialDriver) + public function register(string $socialDriver) { $this->registrationService->ensureRegistrationAllowed(); session()->put('social-callback', 'register'); @@ -60,7 +60,7 @@ class SocialController extends Controller * @throws SocialDriverNotConfigured * @throws UserRegistrationException */ - public function socialCallback(Request $request, string $socialDriver) + public function callback(Request $request, string $socialDriver) { if (!session()->has('social-callback')) { throw new SocialSignInException(trans('errors.social_no_action_defined'), '/login'); @@ -99,7 +99,7 @@ class SocialController extends Controller /** * Detach a social account from a user. */ - public function detachSocialAccount(string $socialDriver) + public function detach(string $socialDriver) { $this->socialAuthService->detachSocialAccount($socialDriver); session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => Str::title($socialDriver)])); @@ -113,7 +113,7 @@ class SocialController extends Controller protected function socialRegisterCallback(string $socialDriver, SocialUser $socialUser) { $socialUser = $this->socialAuthService->handleRegistrationCallback($socialDriver, $socialUser); - $socialAccount = $this->socialAuthService->fillSocialAccount($socialDriver, $socialUser); + $socialAccount = $this->socialAuthService->newSocialAccount($socialDriver, $socialUser); $emailVerified = $this->socialAuthService->driverAutoConfirmEmailEnabled($socialDriver); // Create an array of the user data to create a new user instance @@ -130,6 +130,8 @@ class SocialController extends Controller $user = $this->registrationService->registerUser($userData, $socialAccount, $emailVerified); auth()->login($user); + Theme::dispatch(ThemeEvents::AUTH_LOGIN, $socialDriver, $user); + $this->logActivity(ActivityType::AUTH_LOGIN, $user); $this->showSuccessNotification(trans('auth.register_success')); return redirect('/');