Skip to content

Commit 6bac8ac

Browse files
committed
Ratelimiting auth + small styling changes
1 parent b4d256a commit 6bac8ac

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

app/Http/Controllers/Account/AuthController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,27 @@ public function logout()
2424
public function processLogin(LoginRequest $request)
2525
{
2626
$credentials = $request->only('email', 'password');
27+
$key = 'login-attempt:' . $request->ip();
28+
$attemptsPerHour = 5;
29+
30+
if (\RateLimiter::tooManyAttempts($key, $attemptsPerHour)) {
31+
return back()
32+
->withInput($request->only('email'))
33+
->withErrors([
34+
'email' => 'Too many login attempts. Please try again later.',
35+
]);
36+
}
2737

2838
if (auth()->attempt($credentials, $request->boolean('remember'))) {
2939
session()->regenerate();
3040

41+
\RateLimiter::clear($key);
42+
3143
return redirect()->intended('/account');
3244
}
3345

46+
\RateLimiter::increment($key, 3600);
47+
3448
return back()
3549
->withInput($request->only('email'))
3650
->withErrors([

app/Policies/SupportTicketPolicy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SupportTicketPolicy
1010
{
1111
public function closeTicket(User $user, SupportTicket $supportTicket): bool
1212
{
13-
return $supportTicket->user_id == $user->id;
13+
return $supportTicket->user_id === $user->id;
1414
}
1515

1616
/**

app/Providers/AppServiceProvider.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public function register(): void
2424
*/
2525
public function boot(): void
2626
{
27-
$this->registerSharedViewVariables()
28-
->registerRateLimiters();
27+
$this->registerSharedViewVariables();
2928
}
3029

3130
private function registerSharedViewVariables(): static
@@ -41,11 +40,4 @@ private function registerSharedViewVariables(): static
4140

4241
return $this;
4342
}
44-
45-
private function registerRateLimiters()
46-
{
47-
RateLimiter::for('login', function (Request $request) {
48-
return Limit::perMinute(5)->by($request->input('email') . '|' . $request->ip());
49-
});
50-
}
5143
}

resources/views/support/tickets/index.blade.php

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
</header>
1010

1111
{{-- Support ticket table --}}
12-
<div class="flex justify-end mb-4">
13-
<a href="#" class="inline-flex items-center rounded-md bg-violet-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-violet-700 dark:bg-violet-700 dark:hover:bg-violet-600 transition duration-200">
12+
<div class="flex justify-center md:justify-end mb-4">
13+
<a href="#" class="w-full md:w-auto inline-flex items-center justify-center rounded-md bg-violet-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-violet-700 dark:bg-violet-700 dark:hover:bg-violet-600 transition duration-200">
1414
<svg xmlns="http://www.w3.org/2000/svg" class="mr-2 h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
1515
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1616
</svg>
1717
Submit a new request
1818
</a>
1919
</div>
20-
<div class="overflow-x-auto rounded-lg border border-gray-200 dark:border-gray-700 mb-10">
21-
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
20+
<div class="rounded-lg border border-gray-200 dark:border-gray-700 mb-10">
21+
<!-- Desktop Table View (hidden on mobile, visible md and up) -->
22+
<table class="hidden md:table min-w-full divide-y divide-gray-200 dark:divide-gray-700">
2223
<thead class="bg-gray-50 dark:bg-gray-800">
2324
<tr>
2425
<th scope="col" class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400">
@@ -64,17 +65,56 @@
6465
@endforelse
6566
</tbody>
6667
</table>
68+
69+
<!-- Mobile Card View (visible on mobile, hidden md and up) -->
70+
<div class="md:hidden">
71+
@forelse($supportTickets as $ticket)
72+
<div class="p-4 border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900">
73+
<div class="flex flex-col space-y-3">
74+
<!-- Subject (Priority on mobile) -->
75+
<div class="text-sm font-medium text-gray-900 dark:text-white">
76+
{{ $ticket->subject }}
77+
</div>
78+
79+
<!-- Status (Priority on mobile) -->
80+
<div class="flex items-center">
81+
<span class="text-xs text-gray-500 dark:text-gray-400 mr-2">Status:</span>
82+
<span class="inline-flex rounded-full bg-green-100 px-2.5 py-0.5 text-xs font-medium text-green-800 dark:bg-green-900/30 dark:text-green-300">
83+
{{ $ticket->status->translated() }}
84+
</span>
85+
</div>
86+
87+
<!-- Ticket ID (Less priority on mobile) -->
88+
<div class="flex items-center">
89+
<span class="text-xs text-gray-500 dark:text-gray-400 mr-2">Ticket ID:</span>
90+
<a href="{{ route('support.tickets.show', $ticket) }}" class="text-violet-600 text-sm">#{{ $ticket->mask }}</a>
91+
</div>
92+
93+
<!-- Actions -->
94+
<div class="pt-2">
95+
<a href="{{ route('support.tickets.show', $ticket) }}" class="inline-block rounded-md bg-violet-600 px-3 py-1.5 text-xs font-medium text-white shadow-sm hover:bg-violet-700 dark:bg-violet-700 dark:hover:bg-violet-600 transition duration-200">
96+
View ticket
97+
</a>
98+
</div>
99+
</div>
100+
</div>
101+
@empty
102+
<div class="p-4 bg-white dark:bg-gray-900 text-sm font-medium text-gray-900 dark:text-white">
103+
No tickets found.
104+
</div>
105+
@endforelse
106+
</div>
67107

68108
@if ($supportTickets->hasPages())
69-
<div class="p-5">
109+
<div class="px-3 py-4 md:p-5">
70110
{{ $supportTickets->links() }}
71111
</div>
72112
@endif
73113
</div>
74114
{{-- Additional Support Information --}}
75-
<div class="mt-20 rounded-xl bg-gradient-to-br from-[#FFF0DC] to-[#E8EEFF] p-8 dark:from-blue-900/10 dark:to-[#4c407f]/25">
76-
<h2 class="mb-4 text-2xl font-medium">Need more help?</h2>
77-
<p class="text-lg text-gray-700 dark:text-gray-300">
115+
<div class="mt-12 md:mt-20 rounded-xl bg-gradient-to-br from-[#FFF0DC] to-[#E8EEFF] p-4 md:p-8 dark:from-blue-900/10 dark:to-[#4c407f]/25">
116+
<h2 class="mb-3 md:mb-4 text-xl md:text-2xl font-medium">Need more help?</h2>
117+
<p class="text-base md:text-lg text-gray-700 dark:text-gray-300">
78118
Check out our <a href="/docs" class="font-medium text-violet-600 hover:text-violet-700 dark:text-violet-400 dark:hover:text-violet-300">documentation</a> for comprehensive guides and tutorials to help you get the most out of NativePHP.
79119
</p>
80120
</div>

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
->name('login');
9494

9595
Route::post('/login', [AuthController::class, 'processLogin'])
96-
->middleware('guest')
96+
->middleware(['guest'])
9797
->withoutMiddleware(['auth:web'])
9898
->name('login.process');
9999

0 commit comments

Comments
 (0)