- Load stored users without re-checking role rules, so an intern whose supervisor was deleted no longer gets a 500 on every request; the rules apply again on the next change. - Refuse to deactivate or demote a supervisor of active interns (SupervisorHasInterns). - Lock active admin rows in the last-admin check so concurrent changes cannot remove every admin. - Creating a user survives mail failures: the error is reported and the admin is asked to resend the link (CreatedUserAccount result). - Session-ended redirect passes the reason in the URL (/login?access=ended), so Livewire requests also show it. - Same login message for a wrong password and a disabled account. - Forgot-password sends links only to users who may sign in today (RequestPasswordReset), with the same neutral message. - Use the default callout instead of the low-contrast warning variant. - Document make:class/make:test for module files in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
118 lines
3.8 KiB
PHP
118 lines
3.8 KiB
PHP
<?php
|
|
|
|
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Livewire\Component;
|
|
|
|
new class extends Component
|
|
{
|
|
public const int MAX_ATTEMPTS_PER_MINUTE = 5;
|
|
|
|
public string $email = '';
|
|
|
|
public string $password = '';
|
|
|
|
public bool $remember = false;
|
|
|
|
/**
|
|
* Set when EnsureAccountIsUsable ended the session. Passed in the URL,
|
|
* not flashed: a Livewire request that gets redirected here would
|
|
* consume a flash message before the browser shows the page.
|
|
*/
|
|
public bool $accessEnded = false;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->accessEnded = request()->query('access') === 'ended';
|
|
}
|
|
|
|
public function login(CheckLoginAllowed $checkLoginAllowed): void
|
|
{
|
|
$this->email = trim($this->email);
|
|
|
|
$this->validate(
|
|
['email' => ['required', 'string', 'email'], 'password' => ['required', 'string']],
|
|
[
|
|
'email.required' => __('auth.email_required'),
|
|
'email.email' => __('auth.email_invalid'),
|
|
'password.required' => __('auth.password_required'),
|
|
],
|
|
);
|
|
|
|
$email = Str::lower(trim($this->email));
|
|
$throttleKey = Str::transliterate($email.'|'.request()->ip());
|
|
|
|
if (RateLimiter::tooManyAttempts($throttleKey, self::MAX_ATTEMPTS_PER_MINUTE)) {
|
|
throw ValidationException::withMessages([
|
|
'email' => __('auth.throttle', ['seconds' => RateLimiter::availableIn($throttleKey)]),
|
|
]);
|
|
}
|
|
|
|
$signedIn = Auth::attemptWhen(
|
|
['email' => $email, 'password' => $this->password],
|
|
fn ($user): bool => $checkLoginAllowed->execute($user->getAuthIdentifier()),
|
|
$this->remember,
|
|
);
|
|
|
|
if (! $signedIn) {
|
|
RateLimiter::hit($throttleKey);
|
|
$this->reset('password');
|
|
|
|
// One message for a wrong password and a disabled account, so the
|
|
// form never confirms that a disabled account's password is right.
|
|
throw ValidationException::withMessages(['email' => __('auth.failed')]);
|
|
}
|
|
|
|
RateLimiter::clear($throttleKey);
|
|
session()->regenerate();
|
|
|
|
$this->redirectIntended(route('home'));
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('auth.login_title'));
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-md space-y-6 p-4 sm:p-6 sm:pt-16">
|
|
<flux:heading size="xl" level="1">{{ __('auth.login_title') }}</flux:heading>
|
|
|
|
@if ($accessEnded)
|
|
{{-- Not variant="warning": its yellow heading is only 2.8:1 on the light background. --}}
|
|
<flux:callout icon="exclamation-triangle" role="status" :heading="__('auth.account_disabled')" />
|
|
@elseif (session('status'))
|
|
<flux:callout variant="success" icon="information-circle" role="status" :heading="session('status')" />
|
|
@endif
|
|
|
|
<form wire:submit="login" class="space-y-6" novalidate>
|
|
<flux:input
|
|
wire:model="email"
|
|
type="email"
|
|
:label="__('auth.email')"
|
|
autocomplete="username"
|
|
required
|
|
/>
|
|
|
|
<flux:input
|
|
wire:model="password"
|
|
type="password"
|
|
:label="__('auth.password_label')"
|
|
autocomplete="current-password"
|
|
viewable
|
|
required
|
|
/>
|
|
|
|
<flux:checkbox wire:model="remember" :label="__('auth.remember')" />
|
|
|
|
<div class="flex flex-wrap items-center justify-between gap-4">
|
|
<flux:button type="submit" variant="primary">{{ __('auth.login') }}</flux:button>
|
|
<flux:link :href="route('password.request')" wire:navigate>{{ __('auth.forgot_password') }}</flux:link>
|
|
</div>
|
|
</form>
|
|
</div>
|