From 623312aba3c60d29ce3da288c9c8e382ed99ef1f Mon Sep 17 00:00:00 2001 From: Dave Roverts Date: Sat, 23 Jul 2022 14:26:01 +0200 Subject: [PATCH] feat: notify user if login fails for whatever reason --- .../Auth/VatsimConnectController.php | 39 ++++++++------- resources/views/login.blade.php | 48 ++++++++++--------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/Auth/VatsimConnectController.php b/app/Http/Controllers/Auth/VatsimConnectController.php index b2c47cab..870e56c9 100644 --- a/app/Http/Controllers/Auth/VatsimConnectController.php +++ b/app/Http/Controllers/Auth/VatsimConnectController.php @@ -5,6 +5,8 @@ use App\Enums\RoleKey; use App\Models\Role; use App\Models\User; +use Exception; +use Filament\Facades\Filament; use Illuminate\Support\Facades\Auth; use Laravel\Socialite\Facades\Socialite; @@ -12,25 +14,30 @@ class VatsimConnectController { public function callback() { - /** @var \SocialiteProviders\Manager\OAuth2\User $vatsimUser */ - $vatsimUser = Socialite::driver('vatsimconnect')->user(); + try { + /** @var \SocialiteProviders\Manager\OAuth2\User $vatsimUser */ + $vatsimUser = Socialite::driver('vatsimconnect')->user(); - $user = User::firstWhere('id', $vatsimUser->id); - if (!$user) { - $user = new User([ - 'id' => $vatsimUser->getId(), - 'role_id' => Role::firstWhere('key', RoleKey::USER)->id - ]); - } + $user = User::firstWhere('id', $vatsimUser->id); + if (!$user) { + $user = new User([ + 'id' => $vatsimUser->getId(), + 'role_id' => Role::firstWhere('key', RoleKey::USER)->id + ]); + } - $user->name = $vatsimUser->name; - $user->token = $vatsimUser->token; - $user->refresh_token = $vatsimUser->refreshToken; - $user->refresh_token_expires_at = now()->addSeconds($vatsimUser->expiresIn); - $user->saveQuietly(); + $user->name = $vatsimUser->name; + $user->token = $vatsimUser->token; + $user->refresh_token = $vatsimUser->refreshToken; + $user->refresh_token_expires_at = now()->addSeconds($vatsimUser->expiresIn); + $user->saveQuietly(); - Auth::login($user); + Auth::login($user); - return to_route('filament.pages.dashboard'); + return to_route('filament.pages.dashboard'); + } catch (Exception $e) { + Filament::notify('danger', __('Something went wrong, please try again')); + return to_route('filament.auth.login'); + } } } diff --git a/resources/views/login.blade.php b/resources/views/login.blade.php index 6fccf1bb..a70c118e 100644 --- a/resources/views/login.blade.php +++ b/resources/views/login.blade.php @@ -1,23 +1,25 @@ -
config('filament.dark_mode'), -])> -
-
config('filament.dark_mode'), - ])> -
- -
- -

- {{ __('filament::login.heading') }} -

- - - Login via VATSIM Connect - -
-
-
+
config('filament.dark_mode'), +])> +
+
config('filament.dark_mode'), + ])> +
+ +
+ +

+ {{ __('filament::login.heading') }} +

+ + + Login via VATSIM Connect + +
+
+ + +