/**
* @param Request $request
* @param $provider
* @return \Illuminate\Http\RedirectResponse|mixed
* @throws GeneralException
*/
public function login(Request $request, $provider)
{
//If the provider is not an acceptable third party than kick back
if (!in_array($provider, $this->helper->getAcceptedProviders())) {
return redirect()->route('frontend.index')->withFlashDanger(trans('auth.socialite.unacceptable', ['provider' => $provider]));
}
/**
* The first time this is hit, request is empty
* It's redirected to the provider and then back here, where request is populated
* So it then continues creating the user
*/
if (!$request->all()) {
return $this->getAuthorizationFirst($provider);
}
/**
* Create the user if this is a new social account or find the one that is already there
*/
$user = $this->user->findOrCreateSocial($this->getSocialUser($provider), $provider);
/**
* User has been successfully created or already exists
* Log the user in
*/
auth()->login($user, true);
/**
* User authenticated, check to see if they are active.
*/
if (!access()->user()->isActive()) {
access()->logout();
throw new GeneralException(trans('exceptions.frontend.auth.deactivated'));
}
/**
* Throw an event in case you want to do anything when the user logs in
*/
event(new UserLoggedIn($user));
/**
* Set session variable so we know which provider user is logged in as, if ever needed
*/
session([config('access.socialite_session_name') => $provider]);
/**
* Return to the intended url or default to the class property
*/
return redirect()->intended(route('frontend.index'));
}