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]>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Users\Application\UseCases\LoginPins;
|
||||
use App\Modules\Users\Presentation\Http\Middleware\UseConsoleSession;
|
||||
use App\Modules\Users\Presentation\Livewire\Concerns\SignsInWithPin;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* "Vaihda käyttäjä" on a machine console (spec 19.6): the next user picks
|
||||
* their name and types their own PIN code. The console has its own session
|
||||
* (UseConsoleSession), so this changes only the console's user. Users
|
||||
* without a PIN code sign in with their email and password on the
|
||||
* console's sign-in page, back to the console.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use SignsInWithPin;
|
||||
|
||||
/**
|
||||
* The console to return to, given by the console page.
|
||||
*/
|
||||
#[Locked]
|
||||
public string $returnTo = '';
|
||||
|
||||
public function mount(string $returnTo): void
|
||||
{
|
||||
abort_unless(UseConsoleSession::isConsoleUrl($returnTo) && ! str_contains($returnTo, '?'), 404);
|
||||
|
||||
$this->returnTo = $returnTo;
|
||||
}
|
||||
|
||||
public function switchUser(LoginPins $pins): void
|
||||
{
|
||||
if ($this->signInWithPin($pins)) {
|
||||
$this->redirect($this->returnTo);
|
||||
}
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view();
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
@php
|
||||
$touch = 'inline-flex min-h-11 min-w-11 items-center justify-center gap-2 rounded-lg px-4 py-2 font-medium focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400';
|
||||
@endphp
|
||||
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
id="pin-switch-open"
|
||||
x-on:click="document.getElementById('pin-switch-dialog').showModal()"
|
||||
class="{{ $touch }} border border-zinc-300 text-zinc-100 hover:bg-zinc-700"
|
||||
>
|
||||
<x-icon name="user-circle" class="size-6" aria-hidden="true" />
|
||||
{{ __('machines.console.change_user') }}
|
||||
</button>
|
||||
|
||||
<x-confirm-dialog id="pin-switch-dialog" :title="__('users.pin_switch.title')" class="text-base">
|
||||
@if ($this->pinUsers === [])
|
||||
<p>{{ __('users.pin_switch.no_users') }}</p>
|
||||
@else
|
||||
<form id="pin-switch-form" wire:submit="switchUser" class="space-y-4" novalidate>
|
||||
<x-users.pin-fields :users="$this->pinUsers" />
|
||||
</form>
|
||||
@endif
|
||||
|
||||
<form method="POST" action="{{ route('console.logout') }}" class="mt-4 border-t border-zinc-300 pt-3 dark:border-zinc-600">
|
||||
@csrf
|
||||
<input type="hidden" name="return_to" value="{{ $returnTo }}">
|
||||
<button type="submit" class="text-sm font-medium text-primary-700 underline hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:text-primary-300">{{ __('users.pin_switch.with_password') }}</button>
|
||||
</form>
|
||||
|
||||
<x-slot:actions>
|
||||
@if ($this->pinUsers !== [])
|
||||
<x-button wire:click="switchUser" icon="arrow-right-end-on-rectangle" :text="__('users.pin_switch.submit')" />
|
||||
@endif
|
||||
</x-slot:actions>
|
||||
</x-confirm-dialog>
|
||||
</div>
|
||||
Reference in New Issue
Block a user