++ fix
This commit is contained in:
@@ -3,47 +3,16 @@
|
||||
namespace App\Livewire\Auth;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
|
||||
class Login extends Component
|
||||
{
|
||||
public string $email = '';
|
||||
public string $password = '';
|
||||
public bool $remember = false;
|
||||
|
||||
protected function rules(): array
|
||||
public function mount()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email',
|
||||
'password' => 'required|min:6',
|
||||
];
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$throttleKey = Str::transliterate(Str::lower($this->email) . '|' . request()->ip());
|
||||
|
||||
if (RateLimiter::tooManyAttempts($throttleKey, 5)) {
|
||||
$seconds = RateLimiter::availableIn($throttleKey);
|
||||
$this->addError('email', "Troppi tentativi. Riprova tra {$seconds} secondi.");
|
||||
return;
|
||||
if (! Setting::isSetupComplete() || User::count() === 0) {
|
||||
return redirect()->route('setup.index');
|
||||
}
|
||||
|
||||
if (!Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) {
|
||||
RateLimiter::hit($throttleKey);
|
||||
$this->addError('email', 'Credenziali non valide.');
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::clear($throttleKey);
|
||||
session()->regenerate();
|
||||
activity()->causedBy(auth()->user())->log('login');
|
||||
|
||||
return redirect()->intended(route('dashboard'));
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -6,6 +6,7 @@ use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class Wizard extends Component
|
||||
@@ -33,11 +34,11 @@ class Wizard extends Component
|
||||
|
||||
public function mount()
|
||||
{
|
||||
if (Setting::isSetupComplete()) {
|
||||
if (Setting::isSetupComplete() && User::count() > 0) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
||||
$this->needsAdmin = User::count() <= 1;
|
||||
$this->needsAdmin = User::count() === 0;
|
||||
|
||||
$setting = Setting::first();
|
||||
if ($setting) {
|
||||
@@ -107,10 +108,17 @@ class Wizard extends Component
|
||||
'password' => Hash::make($this->admin_password),
|
||||
]);
|
||||
$admin->assignRole('amministratore');
|
||||
Auth::login($admin);
|
||||
request()->session()->regenerate();
|
||||
}
|
||||
|
||||
session()->flash('success', 'Setup completato con successo!');
|
||||
return redirect()->route('dashboard');
|
||||
|
||||
if (auth()->check()) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
Reference in New Issue
Block a user