clean up social login verifications
This commit is contained in:
@@ -93,4 +93,35 @@ class ConnectedAccountController extends Controller
|
|||||||
throw new Exception('Please provide a valid social provider.');
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Models\ConnectedAccount;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use App\Models\ConnectedAccountVerification;
|
|
||||||
|
|
||||||
class VerifyConnectedAccountController extends Controller
|
|
||||||
{
|
|
||||||
|
|
||||||
public function __invoke(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'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,7 @@ class VerifyConnectedAccountNotification extends Notification implements ShouldQ
|
|||||||
->greeting('Welcome back!')
|
->greeting('Welcome back!')
|
||||||
->subject("Connect your $provider account with Investbrain")
|
->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:")
|
->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.');
|
->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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ Route::get('/terms', [TermsOfServiceController::class, 'show'])->name('terms.sho
|
|||||||
Route::get('/privacy', [PrivacyPolicyController::class, 'show'])->name('policy.show');
|
Route::get('/privacy', [PrivacyPolicyController::class, 'show'])->name('policy.show');
|
||||||
|
|
||||||
// social login routes
|
// 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}', [ConnectedAccountController::class, 'redirectToProvider'])->name('oauth.redirect');
|
||||||
Route::get('auth/{provider}/callback', [ConnectedAccountController::class, 'handleProviderCallback']);
|
Route::get('auth/{provider}/callback', [ConnectedAccountController::class, 'handleProviderCallback']);
|
||||||
|
|||||||
Reference in New Issue
Block a user