* #2 - wip * #2 - wip * #2 - ui fixes to login page * #2 - fix * #2 - fix * #2 - add title to login page * Apply suggestions from code review Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl> * #2 - cr fix * #2 - cr fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl>
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace Toby\Http\Controllers;
 | 
						|
 | 
						|
use Illuminate\Contracts\Auth\Factory as AuthFactory;
 | 
						|
use Illuminate\Database\Eloquent\ModelNotFoundException;
 | 
						|
use Laravel\Socialite\SocialiteManager;
 | 
						|
use Symfony\Component\HttpFoundation\RedirectResponse;
 | 
						|
use Toby\Models\User;
 | 
						|
 | 
						|
class GoogleController extends Controller
 | 
						|
{
 | 
						|
    public function redirect(SocialiteManager $socialiteManager): RedirectResponse
 | 
						|
    {
 | 
						|
        return $socialiteManager->driver("google")->redirect();
 | 
						|
    }
 | 
						|
 | 
						|
    public function callback(AuthFactory $auth, SocialiteManager $socialiteManager): RedirectResponse
 | 
						|
    {
 | 
						|
        $socialUser = $socialiteManager->driver("google")->user();
 | 
						|
 | 
						|
        try {
 | 
						|
            /** @var User $user */
 | 
						|
            $user = User::query()
 | 
						|
                ->where("email", $socialUser->getEmail())
 | 
						|
                ->firstOrFail();
 | 
						|
        } catch (ModelNotFoundException) {
 | 
						|
            return redirect()
 | 
						|
                ->route("login")
 | 
						|
                ->withErrors([
 | 
						|
                    "oauth" => __("User does not exist."),
 | 
						|
                ]);
 | 
						|
        }
 | 
						|
 | 
						|
        $auth->guard()->login($user, true);
 | 
						|
 | 
						|
        return redirect()->route("dashboard");
 | 
						|
    }
 | 
						|
}
 |