- Dark indigo header and tinted page background; the mobile main menu gets its own row, in the same order as the keyboard reaches it. - Page titles with an icon chip (x-page-title, x-page, x-page-header) and card sections (x-panel, the card utility); x-table styled as a card with an indigo header row in AppServiceProvider::styleTables(). - Job and task statuses, late work, unapproved hours and stock states as badges with icon and text (x-status-badge, x-jobs.status, x-jobs.task-status), never colour alone. - Empty lists as x-empty-state; dashboard quick link tiles, week hour bars and trend arrows; Kanban columns and task cards edged by status; calendar today column and bar accents; quick sale, reports and machine console restyled; signed-out pages show the app name. - Focus rings use the primary colour in both themes (white in the header). - Document the components in CLAUDE.md; test the status badges. Co-Authored-By: Claude Opus 5.5 <[email protected]>
140 lines
4.2 KiB
PHP
140 lines
4.2 KiB
PHP
<?php
|
|
|
|
use App\Modules\Users\Application\UseCases\LoginPins;
|
|
use App\Modules\Users\Domain\Exceptions\InvalidLoginPin;
|
|
use App\Modules\Users\Domain\Exceptions\WrongPassword;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* The user's own PIN code for switching user on a machine console (spec
|
|
* 19.6). Setting or removing it asks for the user's password, which may
|
|
* be wrong 5 times a minute, as on the login page.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
public string $currentPassword = '';
|
|
|
|
public string $pin = '';
|
|
|
|
public string $pinConfirmation = '';
|
|
|
|
#[Locked]
|
|
public string $message = '';
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->authorize('machines.use');
|
|
}
|
|
|
|
public function save(LoginPins $pins): void
|
|
{
|
|
$this->authorize('machines.use');
|
|
$this->resetErrorBag();
|
|
|
|
if (trim($this->pin) !== trim($this->pinConfirmation)) {
|
|
$this->addError('pinConfirmation', __('users.pin.errors.confirmation'));
|
|
|
|
return;
|
|
}
|
|
|
|
if ($this->passwordThrottled()) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$pins->set((int) auth()->id(), $this->currentPassword, $this->pin);
|
|
} catch (InvalidLoginPin) {
|
|
$this->addError('pin', __('users.pin.errors.pin'));
|
|
|
|
return;
|
|
} catch (WrongPassword) {
|
|
$this->wrongPassword();
|
|
|
|
return;
|
|
}
|
|
|
|
RateLimiter::clear($this->throttleKey());
|
|
|
|
$this->reset('currentPassword', 'pin', 'pinConfirmation');
|
|
$this->message = __('users.pin.saved');
|
|
}
|
|
|
|
public function remove(LoginPins $pins): void
|
|
{
|
|
$this->authorize('machines.use');
|
|
$this->resetErrorBag();
|
|
|
|
if ($this->passwordThrottled()) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$pins->remove((int) auth()->id(), $this->currentPassword);
|
|
} catch (WrongPassword) {
|
|
$this->wrongPassword();
|
|
|
|
return;
|
|
}
|
|
|
|
RateLimiter::clear($this->throttleKey());
|
|
|
|
$this->reset('currentPassword', 'pin', 'pinConfirmation');
|
|
$this->message = __('users.pin.removed');
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('users.pin.title'));
|
|
}
|
|
|
|
private function throttleKey(): string
|
|
{
|
|
return 'pin-password|'.auth()->id();
|
|
}
|
|
|
|
private function passwordThrottled(): bool
|
|
{
|
|
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
|
return false;
|
|
}
|
|
|
|
$this->addError('currentPassword', __('auth.throttle', ['seconds' => RateLimiter::availableIn($this->throttleKey())]));
|
|
$this->reset('currentPassword');
|
|
|
|
return true;
|
|
}
|
|
|
|
private function wrongPassword(): void
|
|
{
|
|
RateLimiter::hit($this->throttleKey());
|
|
$this->addError('currentPassword', __('users.pin.errors.password'));
|
|
$this->reset('currentPassword');
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-md space-y-6 p-4 sm:p-6">
|
|
<x-page-title icon="key">{{ __('users.pin.title') }}</x-page-title>
|
|
|
|
<p class="text-sm">{{ __('users.pin.intro') }}</p>
|
|
|
|
<p role="status" aria-live="polite" class="text-sm font-medium">
|
|
{{ $message !== '' ? $message : (app(LoginPins::class)->has((int) auth()->id()) ? __('users.pin.is_set') : __('users.pin.not_set')) }}
|
|
</p>
|
|
|
|
<form wire:submit="save" class="card space-y-4" novalidate>
|
|
<x-password-field id="current-password" wire:model="currentPassword" :label="__('users.pin.current_password')" autocomplete="current-password" />
|
|
<x-input id="pin" wire:model="pin" type="password" inputmode="numeric" maxlength="6" :label="__('users.pin.pin')" :hint="__('users.pin.pin_hint')" autocomplete="off" />
|
|
<x-input id="pin-confirmation" wire:model="pinConfirmation" type="password" inputmode="numeric" maxlength="6" :label="__('users.pin.pin_confirmation')" autocomplete="off" />
|
|
|
|
<div class="flex flex-wrap gap-3">
|
|
<x-button submit :text="__('users.pin.save')" />
|
|
@if (app(LoginPins::class)->has((int) auth()->id()))
|
|
<x-button wire:click="remove" subtle color="black" :text="__('users.pin.remove')" />
|
|
@endif
|
|
</div>
|
|
</form>
|
|
</div>
|