Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 08cda7f

Browse files
committed
Prevent admin banning and banning same user multiple times
1 parent 3b35b38 commit 08cda7f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

app/Livewire/Admin/AdminDashboard.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ public function giveBadge(string $userId, string $badgeId): void
239239

240240
public function banUser(): Response|null
241241
{
242+
// Check if the user is already banned
243+
if (Banned::where('user_id', $this->user_id)->exists()) {
244+
session()->flash('error', 'User is already banned.');
245+
return null;
246+
}
247+
248+
// Check if the user is an admin
249+
$user = User::find($this->user_id);
250+
if ($user && $user->admin_rank > 0) {
251+
session()->flash('error', 'You cannot ban an admin.');
252+
return null;
253+
}
254+
242255
$ipBanService = new IpBanService();
243256
$result = $ipBanService->banUser($this->user_id, $this->reason);
244257

@@ -255,6 +268,12 @@ public function banUser(): Response|null
255268

256269
public function unbanUser(): void
257270
{
271+
// Check if the user is not banned
272+
if (!Banned::where('user_id', $this->uid)->exists()) {
273+
session()->flash('error', 'User is not banned.');
274+
return;
275+
}
276+
258277
$ipBanService = new IpBanService();
259278
$result = $ipBanService->unbanUser($this->uid);
260279

0 commit comments

Comments
 (0)