Update SocialiteController.php
This commit is contained in:
parent
8908f4af8f
commit
272c75a071
|
@ -7,6 +7,7 @@ use App\Models\DiscordUser;
|
||||||
use App\Models\Settings;
|
use App\Models\Settings;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Voucher;
|
use App\Models\Voucher;
|
||||||
|
use Exception;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Laravel\Socialite\Facades\Socialite;
|
use Laravel\Socialite\Facades\Socialite;
|
||||||
|
@ -36,13 +37,25 @@ class SocialiteController extends Controller
|
||||||
$roleId = config("SETTINGS::DISCORD:ROLE_ID");
|
$roleId = config("SETTINGS::DISCORD:ROLE_ID");
|
||||||
|
|
||||||
//save / update discord_users
|
//save / update discord_users
|
||||||
|
|
||||||
|
//check if discord account is already linked to an cpgg account
|
||||||
if (is_null($user->discordUser)) {
|
if (is_null($user->discordUser)) {
|
||||||
|
$discordLinked = DiscordUser::where('id', '=', $discord->id)->first();
|
||||||
|
if ($discordLinked !== null) {
|
||||||
|
return redirect()->route('profile.index')->with(
|
||||||
|
'error',
|
||||||
|
'Discord account already linked!'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//create discord user in db
|
//create discord user in db
|
||||||
DiscordUser::create(array_merge($discord->user, ['user_id' => Auth::user()->id]));
|
DiscordUser::create(array_merge($discord->user, ['user_id' => Auth::user()->id]));
|
||||||
|
|
||||||
//update user
|
//update user
|
||||||
Auth::user()->increment('credits', config('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD'));
|
Auth::user()->increment('credits', config('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD'));
|
||||||
Auth::user()->increment('server_limit', config('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD'));
|
Auth::user()->increment('server_limit', config('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD'));
|
||||||
Auth::user()->update(['discord_verified_at' => now()]);
|
Auth::user()->update(['discord_verified_at' => now()]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$user->discordUser->update($discord->user);
|
$user->discordUser->update($discord->user);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue