Merge pull request #431 from 1day2die/fix_Discord_double_bug
Fix Discord-Sync bug
This commit is contained in:
commit
dba08e8d6f
|
@ -7,6 +7,7 @@ use App\Models\DiscordUser;
|
|||
use App\Models\Settings;
|
||||
use App\Models\User;
|
||||
use App\Models\Voucher;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
|
@ -36,13 +37,25 @@ class SocialiteController extends Controller
|
|||
$roleId = config("SETTINGS::DISCORD:ROLE_ID");
|
||||
|
||||
//save / update discord_users
|
||||
|
||||
//check if discord account is already linked to an cpgg account
|
||||
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
|
||||
DiscordUser::create(array_merge($discord->user, ['user_id' => Auth::user()->id]));
|
||||
|
||||
//update user
|
||||
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()->update(['discord_verified_at' => now()]);
|
||||
|
||||
} else {
|
||||
$user->discordUser->update($discord->user);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue