Fixed 500 error when linking discord accounts
This commit is contained in:
parent
4d0c9deab9
commit
cb4ade5a5d
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Configuration;
|
use App\Models\Configuration;
|
||||||
use App\Models\DiscordUser;
|
use App\Models\DiscordUser;
|
||||||
|
use App\Models\Voucher;
|
||||||
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;
|
||||||
|
@ -28,11 +29,22 @@ class SocialiteController extends Controller
|
||||||
|
|
||||||
$discord = Socialite::driver('discord')->user();
|
$discord = Socialite::driver('discord')->user();
|
||||||
$discordUser = DiscordUser::find($discord->id);
|
$discordUser = DiscordUser::find($discord->id);
|
||||||
|
|
||||||
$botToken = env('DISCORD_BOT_TOKEN');
|
$botToken = env('DISCORD_BOT_TOKEN');
|
||||||
$guildId = env('DISCORD_GUILD_ID');
|
$guildId = env('DISCORD_GUILD_ID');
|
||||||
$roleId = env('DISCORD_ROLE_ID');
|
$roleId = env('DISCORD_ROLE_ID');
|
||||||
|
|
||||||
|
//save / update discord_users
|
||||||
|
if (is_null($discordUser)) {
|
||||||
|
//create discord user in db
|
||||||
|
DiscordUser::create(array_merge($discord->user, ['user_id' => Auth::user()->id]));
|
||||||
|
//update user
|
||||||
|
Auth::user()->increment('credits', Configuration::getValueByKey('CREDITS_REWARD_AFTER_VERIFY_DISCORD'));
|
||||||
|
Auth::user()->increment('server_limit', Configuration::getValueByKey('SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD'));
|
||||||
|
Auth::user()->update(['discord_verified_at' => now()]);
|
||||||
|
} else {
|
||||||
|
$discordUser->update($discord->user);
|
||||||
|
}
|
||||||
|
|
||||||
//force user into discord server
|
//force user into discord server
|
||||||
//TODO Add event on failure, to notify ppl involved
|
//TODO Add event on failure, to notify ppl involved
|
||||||
if (!empty($guildId) && !empty($botToken)) {
|
if (!empty($guildId) && !empty($botToken)) {
|
||||||
|
@ -56,18 +68,6 @@ class SocialiteController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (is_null($discordUser)) {
|
|
||||||
//create discord user in db
|
|
||||||
DiscordUser::create(array_merge($discord->user, ['user_id' => Auth::user()->id]));
|
|
||||||
//update user
|
|
||||||
Auth::user()->increment('credits', Configuration::getValueByKey('CREDITS_REWARD_AFTER_VERIFY_DISCORD'));
|
|
||||||
Auth::user()->increment('server_limit', Configuration::getValueByKey('SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD'));
|
|
||||||
Auth::user()->update(['discord_verified_at' => now()]);
|
|
||||||
} else {
|
|
||||||
$discordUser->update($discord->user);
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->route('profile.index')->with(
|
return redirect()->route('profile.index')->with(
|
||||||
'success',
|
'success',
|
||||||
'Discord account linked!'
|
'Discord account linked!'
|
||||||
|
|
|
@ -5,13 +5,25 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Spatie\Activitylog\Traits\LogsActivity;
|
|
||||||
|
|
||||||
class DiscordUser extends Model
|
class DiscordUser extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $guarded = [];
|
protected $fillable = [
|
||||||
|
"id",
|
||||||
|
"user_id",
|
||||||
|
"username",
|
||||||
|
"avatar",
|
||||||
|
"discriminator",
|
||||||
|
"public_flags",
|
||||||
|
"flags",
|
||||||
|
"locale",
|
||||||
|
"mfa_enabled",
|
||||||
|
"premium_type",
|
||||||
|
"email",
|
||||||
|
"verified",
|
||||||
|
];
|
||||||
|
|
||||||
public $incrementing = false;
|
public $incrementing = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue