Fix review findings in login and user management
- 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]>
This commit is contained in:
@@ -17,6 +17,18 @@ new class extends Component
|
||||
|
||||
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);
|
||||
@@ -39,15 +51,9 @@ new class extends Component
|
||||
]);
|
||||
}
|
||||
|
||||
$accountDisabled = false;
|
||||
|
||||
$signedIn = Auth::attemptWhen(
|
||||
['email' => $email, 'password' => $this->password],
|
||||
function ($user) use ($checkLoginAllowed, &$accountDisabled): bool {
|
||||
$accountDisabled = ! $checkLoginAllowed->execute($user->getAuthIdentifier());
|
||||
|
||||
return ! $accountDisabled;
|
||||
},
|
||||
fn ($user): bool => $checkLoginAllowed->execute($user->getAuthIdentifier()),
|
||||
$this->remember,
|
||||
);
|
||||
|
||||
@@ -55,9 +61,9 @@ new class extends Component
|
||||
RateLimiter::hit($throttleKey);
|
||||
$this->reset('password');
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __($accountDisabled ? 'auth.account_disabled' : 'auth.failed'),
|
||||
]);
|
||||
// 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);
|
||||
@@ -76,7 +82,10 @@ new class extends Component
|
||||
<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 (session('status'))
|
||||
@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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user