datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.7 KiB
113 lines
3.7 KiB
<?php
|
|
// auth related routes, using the web middleware
|
|
|
|
use App\Models\User;
|
|
use SocialNorm\Exceptions\ApplicationRejectedException;
|
|
use SocialNorm\Exceptions\InvalidAuthorizationCodeException;
|
|
use SocialNorm\ProviderUser;
|
|
|
|
Auth::routes();
|
|
|
|
Route::get('/auth/confirm-email', 'Auth\ConfirmEmailController@confirmEmailAndLogin')
|
|
->name('confirm-email')->middleware('auth');
|
|
|
|
Route::get('/auth/resend-email-confirmation', 'Auth\ConfirmEmailController@resendConfirmation')
|
|
->name('resend-email-confirmation');
|
|
|
|
// ----------------- SOCIAL LOGIN --------------------
|
|
|
|
if (!function_exists('_loginVia')) {
|
|
function _loginVia($method)
|
|
{
|
|
$wasLoggedIn = !guest();
|
|
|
|
try {
|
|
SocialAuth::login($method, function (User $user, ProviderUser $details) use ($wasLoggedIn) {
|
|
if ($user->exists && !$wasLoggedIn) {
|
|
// check if this identity already existed
|
|
if (!$user->socialIdentities()
|
|
->where('provider', $details->provider)
|
|
->where('provider_user_id', $details->id)
|
|
->exists()) {
|
|
Auth::logout();
|
|
|
|
abort(403,
|
|
"Account with this e-mail already exists. Add the identity
|
|
to the account manually after logging in through an existing
|
|
authentication method.");
|
|
}
|
|
}
|
|
|
|
// update user name first time user logs in
|
|
if (!$user->exists) {
|
|
if (!config('app.allow_regs')) {
|
|
abort(403, "Registrations are closed.");
|
|
}
|
|
|
|
$basename = $details->nickname ?: ($details->full_name ?: $details->email);
|
|
$user->name = $basename;
|
|
$cnt = 1;
|
|
while (User::where('name', $user->name)->exists()) {
|
|
$cnt++;
|
|
$user->name = $basename . $cnt;
|
|
}
|
|
|
|
$user->title = $basename;
|
|
}
|
|
|
|
// set e-mail from provider data, only if user e-mail is empty
|
|
if ("$user->email" === "") {
|
|
$user->email = $details->email;
|
|
}
|
|
$user->confirmed = true; // mark as confirmed, we trust the provider
|
|
});
|
|
} catch (ApplicationRejectedException $e) {
|
|
abort(401, $e->getMessage());
|
|
} catch (InvalidAuthorizationCodeException $e) {
|
|
abort(401, $e->getMessage());
|
|
}
|
|
|
|
if ($wasLoggedIn)
|
|
return redirect(route('account.edit'));
|
|
else
|
|
return Redirect::intended();
|
|
}
|
|
}
|
|
|
|
|
|
Route::get('/auth/github/authorize', function() {
|
|
return SocialAuth::authorize('github');
|
|
})->name('oauth-github-authorize');
|
|
|
|
Route::get('/auth/github/callback', function() {
|
|
return _loginVia('github');
|
|
})->name('oauth-github-callback');
|
|
|
|
|
|
Route::get('/auth/google/authorize', function() {
|
|
return SocialAuth::authorize('google');
|
|
})->name('oauth-google-authorize');
|
|
|
|
Route::get('/auth/google/callback', function() {
|
|
return _loginVia('google');
|
|
})->name('oauth-google-callback');
|
|
|
|
|
|
Route::get('/auth/facebook/authorize', function() {
|
|
return SocialAuth::authorize('facebook');
|
|
})->name('oauth-facebook-authorize');
|
|
|
|
Route::get('/auth/facebook/callback', function() {
|
|
return _loginVia('facebook');
|
|
})->name('oauth-facebook-callback');
|
|
|
|
|
|
/*
|
|
Route::get('/auth/stack/authorize', function() {
|
|
return SocialAuth::authorize('stack');
|
|
})->name('oauth-stack-authorize');
|
|
|
|
Route::get('/auth/stack/callback', function() {
|
|
return _loginVia('stack');
|
|
})->name('oauth-stack-callback');
|
|
*/
|
|
|