mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-09 21:42:57 +00:00
50 lines
923 B
PHP
50 lines
923 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\RolesEnum;
|
|
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::where('email', $user->getEmail())->first();
|
|
if ($authUser == null)
|
|
{
|
|
$authUser = User::create([
|
|
'email' => $user->getEmail(),
|
|
'name' => $user->getName(),
|
|
]);
|
|
// $authUser->assignRole(RolesEnum::MEMBER);
|
|
}
|
|
|
|
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('/');
|
|
}
|
|
}
|