From 5555e95e48794736f203d6a06ee61d82beafc943 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Sun, 20 Oct 2024 09:41:25 -0500 Subject: [PATCH] clean up social login verifications --- .../ConnectedAccountController.php | 31 +++++++++++++ .../VerifyConnectedAccountController.php | 44 ------------------- .../VerifyConnectedAccountNotification.php | 2 +- routes/web.php | 2 +- 4 files changed, 33 insertions(+), 46 deletions(-) delete mode 100644 app/Http/Controllers/VerifyConnectedAccountController.php diff --git a/app/Http/Controllers/ConnectedAccountController.php b/app/Http/Controllers/ConnectedAccountController.php index 95e491f..21b1a07 100644 --- a/app/Http/Controllers/ConnectedAccountController.php +++ b/app/Http/Controllers/ConnectedAccountController.php @@ -93,4 +93,35 @@ class ConnectedAccountController extends Controller throw new Exception('Please provide a valid social provider.'); } } + + public function verify(string $verification_id) + { + + $verification = ConnectedAccountVerification::findOrFail($verification_id); + + if (!$verification->verified_at) { + + // mark request as verified + $verification->verified_at = now(); + $verification->save(); + + // mark user as verified + $user = User::where('email', $verification->email)->firstOrFail(); + $user->email_verified_at = now(); + $user->save(); + + // add connected account + $user->connectedAccounts()->create([ + ...$verification->connected_account, + ...[ + 'provider' => $verification->provider, + 'provider_id' => $verification->provider_id, + ] + ]); + + Auth::login($user); + } + + return redirect(route('dashboard')); + } } diff --git a/app/Http/Controllers/VerifyConnectedAccountController.php b/app/Http/Controllers/VerifyConnectedAccountController.php deleted file mode 100644 index adafcd8..0000000 --- a/app/Http/Controllers/VerifyConnectedAccountController.php +++ /dev/null @@ -1,44 +0,0 @@ -verified_at) { - - // mark request as verified - $verification->verified_at = now(); - $verification->save(); - - // mark user as verified - $user = User::where('email', $verification->email)->firstOrFail(); - $user->email_verified_at = now(); - $user->save(); - - // add connected account - $user->connectedAccounts()->create([ - ...$verification->connected_account, - ...[ - 'provider' => $verification->provider, - 'provider_id' => $verification->provider_id, - ] - ]); - - Auth::login($user); - } - - return redirect(route('dashboard')); - } -} diff --git a/app/Notifications/VerifyConnectedAccountNotification.php b/app/Notifications/VerifyConnectedAccountNotification.php index fd2d201..3cb3e67 100644 --- a/app/Notifications/VerifyConnectedAccountNotification.php +++ b/app/Notifications/VerifyConnectedAccountNotification.php @@ -41,7 +41,7 @@ class VerifyConnectedAccountNotification extends Notification implements ShouldQ ->greeting('Welcome back!') ->subject("Connect your $provider account with Investbrain") ->line("You recently attempted to log into an existing Investbrain account using $provider. To safeguard your Investbrain account, please confirm this was you by pressing the 'Connect $provider' button below:") - ->action("Connect $provider", route('verify_connected_account', ['verification_id' => $this->verification_id])) + ->action("Connect $provider", route('oauth.verify_connected_account', ['verification_id' => $this->verification_id])) ->line('If you do not recognize this activity, we recommend [changing your password]('.route('profile.show').') as soon as possible. Otherwise, you can disregard this message.'); } diff --git a/routes/web.php b/routes/web.php index 2a87908..962fc4e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -41,7 +41,7 @@ Route::get('/terms', [TermsOfServiceController::class, 'show'])->name('terms.sho Route::get('/privacy', [PrivacyPolicyController::class, 'show'])->name('policy.show'); // social login routes -Route::get('auth/verify/{verification_id}', VerifyConnectedAccountController::class)->name('verify_connected_account'); +Route::get('auth/verify/{verification_id}', [ConnectedAccountController::class, 'verify'])->name('oauth.verify_connected_account'); Route::get('auth/{provider}', [ConnectedAccountController::class, 'redirectToProvider'])->name('oauth.redirect'); Route::get('auth/{provider}/callback', [ConnectedAccountController::class, 'handleProviderCallback']);