++ fix
This commit is contained in:
55
app/Http/Controllers/Auth/LoginController.php
Normal file
55
app/Http/Controllers/Auth/LoginController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Setting::isSetupComplete() || User::count() === 0) {
|
||||
return redirect()->route('setup.index');
|
||||
}
|
||||
|
||||
$credentials = $request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'string', 'min:6'],
|
||||
'remember' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$throttleKey = Str::transliterate(Str::lower($credentials['email']) . '|' . $request->ip());
|
||||
|
||||
if (RateLimiter::tooManyAttempts($throttleKey, 5)) {
|
||||
$seconds = RateLimiter::availableIn($throttleKey);
|
||||
|
||||
return back()
|
||||
->withErrors(['email' => "Troppi tentativi. Riprova tra {$seconds} secondi."])
|
||||
->withInput($request->only('email', 'remember'));
|
||||
}
|
||||
|
||||
if (! Auth::attempt([
|
||||
'email' => $credentials['email'],
|
||||
'password' => $credentials['password'],
|
||||
], $request->boolean('remember'))) {
|
||||
RateLimiter::hit($throttleKey);
|
||||
|
||||
return back()
|
||||
->withErrors(['email' => 'Credenziali non valide.'])
|
||||
->withInput($request->only('email', 'remember'));
|
||||
}
|
||||
|
||||
RateLimiter::clear($throttleKey);
|
||||
$request->session()->regenerate();
|
||||
activity()->causedBy(auth()->user())->log('login');
|
||||
|
||||
return redirect()->intended(route('dashboard'));
|
||||
}
|
||||
}
|
||||
7
app/Http/Controllers/Controller.php
Normal file
7
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user