add column unique numbering scheme, more efficient selects
This commit is contained in:
+49
-44
@@ -16,58 +16,63 @@ Route::get('/auth/resend-email-confirmation', 'Auth\ConfirmEmailController@resen
|
||||
|
||||
// ----------------- SOCIAL LOGIN --------------------
|
||||
|
||||
function _loginVia($method) {
|
||||
$wasLoggedIn = !guest();
|
||||
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();
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
// update user name first time user logs in
|
||||
if (!$user->exists) {
|
||||
if (!config('app.allow_regs')) {
|
||||
abort(403, "Registrations are closed.");
|
||||
}
|
||||
|
||||
// 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());
|
||||
$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('profile.manage-oauth'));
|
||||
else
|
||||
return Redirect::intended();
|
||||
}
|
||||
|
||||
if ($wasLoggedIn)
|
||||
return redirect(route('profile.manage-oauth'));
|
||||
else
|
||||
return Redirect::intended();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Route::get('/auth/github/authorize', function() {
|
||||
|
||||
Reference in New Issue
Block a user