mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
43 lines
727 B
PHP
43 lines
727 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Laravel\Socialite\Facades\Socialite;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
public function handleRedirect()
|
|
{
|
|
return Socialite::driver('authentik')->redirect();
|
|
}
|
|
|
|
public function handleCallback()
|
|
{
|
|
$user = Socialite::driver('authentik')->user();
|
|
|
|
$authUser = User::updateOrCreate(
|
|
[ 'email' => $user->getEmail() ],
|
|
);
|
|
|
|
if ($authUser)
|
|
{
|
|
if ($authUser->name == '')
|
|
{
|
|
$authUser->name = $user->getName();
|
|
$authUser->save();
|
|
}
|
|
Auth::login($authUser);
|
|
return redirect('/');
|
|
}
|
|
|
|
abort(401);
|
|
}
|
|
|
|
public function handleLogout()
|
|
{
|
|
Auth::logout();
|
|
return redirect('/');
|
|
}
|
|
}
|