Files
Toiminnanohjaus/app/Modules/Users/Presentation/Livewire/⚡pin.blade.php
T
petriandClaude Sonnet 5.5 32c33e2a64 Give the machine console its own session with PIN sign-in, make counters cumulative
The console under console/ has its own session cookie and console guard
(UseConsoleSession), so signing out or changing user there leaves the
normal interface alone. Links open it in a new window through a one-time
handoff key; a signed-out console asks for a PIN code or password on its
own login page. Users set their 4-6 digit PIN on the profile's PIN page,
and the console's change user dialog takes it on a keypad; five wrong
PINs lock PIN sign-in for 15 minutes.

Machine counters are cumulative: users record how much a job used and it
is added to the latest reading. A maintenance record restarts the whole
counter interval from the reading at the record.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-29 09:58:11 +02:00

102 lines
3.3 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 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.
*/
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;
}
try {
$pins->set((int) auth()->id(), $this->currentPassword, $this->pin);
} catch (InvalidLoginPin) {
$this->addError('pin', __('users.pin.errors.pin'));
return;
} catch (WrongPassword) {
$this->addError('currentPassword', __('users.pin.errors.password'));
return;
}
$this->reset('currentPassword', 'pin', 'pinConfirmation');
$this->message = __('users.pin.saved');
}
public function remove(LoginPins $pins): void
{
$this->authorize('machines.use');
$this->resetErrorBag();
try {
$pins->remove((int) auth()->id(), $this->currentPassword);
} catch (WrongPassword) {
$this->addError('currentPassword', __('users.pin.errors.password'));
return;
}
$this->reset('currentPassword', 'pin', 'pinConfirmation');
$this->message = __('users.pin.removed');
}
public function render(): mixed
{
return $this->view()->title(__('users.pin.title'));
}
};
?>
<div class="mx-auto max-w-md space-y-6 p-4 sm:p-6">
<h1 class="text-2xl font-semibold">{{ __('users.pin.title') }}</h1>
<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="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>