Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JakyeRU committed Aug 15, 2023
2 parents 7a03580 + 5059ed6 commit 7d4e4a6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Http/Controllers/DiscordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/Services/DiscordService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '/'
],
],

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->json('roles')->nullable();
$table->json('roles')->nullable()->after('avatar');
});
}

Expand Down
1 change: 1 addition & 0 deletions src/routes/larascord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

1 comment on commit 7d4e4a6

@vercel
Copy link

@vercel vercel bot commented on 7d4e4a6 Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.