- AuthenticateSession in the web group logs out a user's other sessions when their password changes. - Set-password links made by an admin use a new admin_links broker with its own password_setup_tokens table and a 72-hour expiry, so links handed over by hand don't expire in an hour. Forgot-password links keep 60 minutes. The reset page accepts both, and issuing or using a link ends the user's earlier links. - Admin links are emailed with PasswordSetupLinkNotification; the email body is shared with the forgot-password email via PasswordLinkMail. - Spec chapter 3 and CLAUDE.md describe the link lifetimes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
122 lines
3.8 KiB
PHP
122 lines
3.8 KiB
PHP
<?php
|
|
|
|
use Illuminate\Auth\Events\PasswordReset;
|
|
use Illuminate\Support\Facades\Password;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rules\Password as PasswordRule;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
new class extends Component
|
|
{
|
|
/**
|
|
* Password brokers in config/auth.php: forgot-password links, then links
|
|
* made by an admin.
|
|
*/
|
|
private const array BROKERS = ['users', 'admin_links'];
|
|
|
|
#[Locked]
|
|
public string $token = '';
|
|
|
|
public string $email = '';
|
|
|
|
public string $password = '';
|
|
|
|
public string $password_confirmation = '';
|
|
|
|
public function mount(string $token): void
|
|
{
|
|
$this->token = $token;
|
|
$this->email = (string) request()->query('email', '');
|
|
}
|
|
|
|
public function resetPassword(): void
|
|
{
|
|
$this->validate(
|
|
[
|
|
'email' => ['required', 'string', 'email'],
|
|
'password' => ['required', 'string', 'confirmed', PasswordRule::defaults()],
|
|
],
|
|
[
|
|
'email.required' => __('auth.email_required'),
|
|
'email.email' => __('auth.email_invalid'),
|
|
'password.required' => __('auth.password_required'),
|
|
'password.confirmed' => __('auth.password_mismatch'),
|
|
'password.min' => __('auth.password_too_short', ['min' => 12]),
|
|
'password.password.mixed' => __('auth.password_needs_mixed_case'),
|
|
'password.password.numbers' => __('auth.password_needs_number'),
|
|
'password.password.symbols' => __('auth.password_needs_symbol'),
|
|
],
|
|
);
|
|
|
|
$credentials = [
|
|
'email' => Str::lower(trim($this->email)),
|
|
'password' => $this->password,
|
|
'password_confirmation' => $this->password_confirmation,
|
|
'token' => $this->token,
|
|
];
|
|
|
|
// A forgot-password link (60 min) or a link made by an admin (72 h);
|
|
// each kind has its own broker. Using a link ends every other link.
|
|
foreach (self::BROKERS as $broker) {
|
|
$status = Password::broker($broker)->reset($credentials, function ($user, string $password): void {
|
|
foreach (self::BROKERS as $anyBroker) {
|
|
Password::broker($anyBroker)->deleteToken($user);
|
|
}
|
|
|
|
$user->forceFill(['password' => $password, 'remember_token' => Str::random(60)])->save();
|
|
|
|
event(new PasswordReset($user));
|
|
});
|
|
|
|
if ($status !== Password::INVALID_TOKEN) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($status !== Password::PASSWORD_RESET) {
|
|
$this->reset('password', 'password_confirmation');
|
|
$this->addError('email', __($status));
|
|
|
|
return;
|
|
}
|
|
|
|
session()->flash('status', __($status));
|
|
|
|
$this->redirectRoute('login');
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('auth.reset_title'));
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-md space-y-6 p-4 sm:p-6 sm:pt-16">
|
|
<h1 class="text-2xl font-semibold">{{ __('auth.reset_title') }}</h1>
|
|
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('auth.reset_intro') }}</p>
|
|
|
|
<form wire:submit="resetPassword" class="space-y-6" novalidate>
|
|
<x-input wire:model="email" type="email" :label="__('auth.email')" autocomplete="username" required />
|
|
|
|
<x-password-field
|
|
wire:model="password"
|
|
:label="__('auth.new_password')"
|
|
:hint="__('auth.password_rules')"
|
|
autocomplete="new-password"
|
|
required
|
|
/>
|
|
|
|
<x-password-field
|
|
wire:model="password_confirmation"
|
|
:label="__('auth.confirm_password')"
|
|
autocomplete="new-password"
|
|
required
|
|
/>
|
|
|
|
<x-button submit :text="__('auth.reset_submit')" />
|
|
</form>
|
|
</div>
|