Files
Toiminnanohjaus/app/Modules/Users/Presentation/Livewire/⚡reset-password.blade.php
T
petriandClaude Opus 5.5 246e806c1c Add structured specification and show set-password links to admins
The customer answered the open questions in määrittely.txt. Collect the
answers into docs/maarittely.md: roles and permission table, money
visibility, customer job fields and enum keys, Kanban, tasks, time
entries, expenses, pricing, Fennoa billing export, data model, revised
phases with phase 1 in detail, and remaining open questions. CLAUDE.md
now points to it.

Apply the answers that change the Users module:
- Passwords need 12+ characters with mixed case, a number and a symbol,
  with a Finnish message for each rule.
- When an admin creates a user or asks for a new link, the set-password
  link is emailed and also shown to the admin to copy, even if the email
  fails. The link lives only in the page state. users:create-admin
  prints it too. Self-service "forgot password" stays as it was.
- The copy field uses x-input + x-button with a status message, because
  x-clipboard has an unlabelled input and a changing button name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 17:22:43 +02:00

105 lines
3.2 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
{
#[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'),
],
);
$status = Password::reset(
[
'email' => Str::lower(trim($this->email)),
'password' => $this->password,
'password_confirmation' => $this->password_confirmation,
'token' => $this->token,
],
function ($user, string $password): void {
$user->forceFill(['password' => $password, 'remember_token' => Str::random(60)])->save();
event(new PasswordReset($user));
},
);
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>