diff --git a/src/Http/Controllers/DiscordController.php b/src/Http/Controllers/DiscordController.php index 20527e1..cd3a187 100644 --- a/src/Http/Controllers/DiscordController.php +++ b/src/Http/Controllers/DiscordController.php @@ -6,6 +6,7 @@ use Illuminate\Http\RedirectResponse; use App\Providers\RouteServiceProvider; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; use Jakyeru\Larascord\Http\Requests\StoreUserRequest; use Jakyeru\Larascord\Services\DiscordService; @@ -80,6 +81,14 @@ public function handle(StoreUserRequest $request): RedirectResponse | JsonRespon return $this->throwError('database_error', $e); } + // Verifying if the user is soft-deleted. + if (Schema::hasColumn('users', 'deleted_at')) { + if ($user->trashed()) { + DB::rollBack(); + return $this->throwError('user_deleted'); + } + } + // Verifying if the user has the required roles if "larascord.roles" is set. if (count(config('larascord.guild_roles'))) { // Verifying if the "guilds" and "guilds.members.read" scopes are set. diff --git a/src/Services/DiscordService.php b/src/Services/DiscordService.php index d6945da..ef1035d 100644 --- a/src/Services/DiscordService.php +++ b/src/Services/DiscordService.php @@ -6,6 +6,7 @@ use Exception; use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Schema; use Jakyeru\Larascord\Types\AccessToken; use Jakyeru\Larascord\Types\GuildMember; @@ -187,6 +188,15 @@ public function createOrUpdateUser(\Jakyeru\Larascord\Types\User $user): User throw new Exception('User access token is missing.'); } + if (Schema::hasColumn('users', 'deleted_at')) { + return User::withTrashed()->updateOrCreate( + [ + 'id' => $user->id, + ], + $user->toArray(), + ); + } + return User::updateOrCreate( [ 'id' => $user->id, diff --git a/src/config/config.php b/src/config/config.php index 58be6c5..db3f677 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -225,6 +225,10 @@ 'message' => 'An error occurred while trying to revoke your access token.', 'redirect' => '/' ], + 'user_deleted' => [ + 'message' => 'Your account is deleted and you can\'t log in.', + 'redirect' => '/' + ], ], /* diff --git a/src/database/migrations/2023_04_06_101123_add_roles_to_users_table.php b/src/database/migrations/2023_04_06_101123_add_roles_to_users_table.php index 9e195d6..0ed6c34 100644 --- a/src/database/migrations/2023_04_06_101123_add_roles_to_users_table.php +++ b/src/database/migrations/2023_04_06_101123_add_roles_to_users_table.php @@ -12,7 +12,7 @@ public function up(): void { Schema::table('users', function (Blueprint $table) { - $table->json('roles')->nullable(); + $table->json('roles')->nullable()->after('avatar'); }); } diff --git a/src/routes/larascord.php b/src/routes/larascord.php index bf8885f..41a7dab 100644 --- a/src/routes/larascord.php +++ b/src/routes/larascord.php @@ -21,6 +21,7 @@ . '&redirect_uri=' . config('larascord.redirect_uri') . '&response_type=code&scope=' . implode('%20', explode('&', config('larascord.scopes'))) . '&prompt=' . config('larascord.prompt', 'none')) + ->middleware(['web', 'guest']) ->name('login'); Route::get('/confirm-password', [ConfirmablePasswordController::class, 'show'])