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:
@@ -4,6 +4,13 @@ use App\Modules\Inventory\Presentation\Http\Controllers\DownloadInventoryCount;
|
||||
use App\Modules\Inventory\Presentation\Http\Controllers\ShowStockItemImage;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
// Pictures on the machine console, which has its own session (paths under console/).
|
||||
Route::middleware(['web', 'auth', 'can:inventory.view'])
|
||||
->get('/console/inventory/items/{item}/image/{size}', ShowStockItemImage::class)
|
||||
->whereNumber('item')
|
||||
->whereIn('size', ['full', 'thumbnail'])
|
||||
->name('inventory.items.console-image');
|
||||
|
||||
Route::middleware(['web', 'auth', 'can:inventory.view'])
|
||||
->prefix('inventory')
|
||||
->name('inventory.')
|
||||
|
||||
@@ -24,7 +24,7 @@ use App\Modules\Users\Application\Contracts\Clock;
|
||||
|
||||
/**
|
||||
* Machine maintenance (spec 19.5): maintenance items are kept by
|
||||
* management; counter readings and maintenance done are recorded by
|
||||
* management; counter usage and maintenance done are recorded by
|
||||
* anyone using the machine. A maintenance record starts the item's
|
||||
* intervals again and uses up its stock item; a mistaken record is
|
||||
* cancelled by management, never deleted.
|
||||
@@ -98,50 +98,52 @@ final class MachineMaintenance
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a counter's reading, e.g. the machine's own total counter.
|
||||
* Records how much of a counter one job used (spec 19.5): counters are
|
||||
* cumulative, so the usage is added to the counter's latest reading.
|
||||
*
|
||||
* @return int The counter's new reading.
|
||||
*
|
||||
* @throws CounterNotFound
|
||||
* @throws InvalidReading
|
||||
*/
|
||||
public function recordReading(int $counterId, string $reading, int $actorUserId): int
|
||||
public function recordUsage(int $counterId, string $usage, int $actorUserId): int
|
||||
{
|
||||
$milli = Reading::parse($reading) ?? throw new InvalidReading;
|
||||
$usageMilli = Reading::parse($usage);
|
||||
|
||||
$this->transactions->run(function () use ($counterId, $milli, $actorUserId): void {
|
||||
if ($usageMilli === null || $usageMilli <= 0) {
|
||||
throw new InvalidReading;
|
||||
}
|
||||
|
||||
return $this->transactions->run(function () use ($counterId, $usageMilli, $actorUserId): int {
|
||||
$this->maintenance->machineOfCounter($counterId) ?? throw new CounterNotFound;
|
||||
$this->maintenance->addReading($counterId, $milli, $actorUserId, $this->clock->now());
|
||||
});
|
||||
$reading = ($this->maintenance->latestReading($counterId) ?? 0) + $usageMilli;
|
||||
$this->maintenance->addReading($counterId, $reading, $actorUserId, $this->clock->now());
|
||||
|
||||
return $milli;
|
||||
return $reading;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Records maintenance done (Huolto tehty) with the counter's reading
|
||||
* (the latest one when not given) and uses up the item's stock item.
|
||||
* Records maintenance done (Huolto tehty) at the counter's latest
|
||||
* reading and uses up the item's stock item. This resets the item: the
|
||||
* whole counter interval is left again, counted from this reading, and
|
||||
* the time interval starts again from today.
|
||||
*
|
||||
* @return array{recordId: int, stockRecorded: bool}
|
||||
*
|
||||
* @throws MaintenanceItemNotFound
|
||||
* @throws InvalidReading
|
||||
*/
|
||||
public function recordMaintenance(int $itemId, int $actorUserId, string $reading = '', ?string $note = null): array
|
||||
public function recordMaintenance(int $itemId, int $actorUserId, ?string $note = null): array
|
||||
{
|
||||
$readingMilli = Reading::parse($reading);
|
||||
$note = $note === null ? '' : trim($note);
|
||||
|
||||
return $this->transactions->run(function () use ($itemId, $actorUserId, $readingMilli, $note): array {
|
||||
return $this->transactions->run(function () use ($itemId, $actorUserId, $note): array {
|
||||
$item = $this->maintenance->findItem($itemId) ?? throw new MaintenanceItemNotFound;
|
||||
$now = $this->clock->now();
|
||||
$readingMilli = $item->counterId() === null
|
||||
? null
|
||||
: ($this->maintenance->latestReading($item->counterId()) ?? $item->baselineMilli());
|
||||
|
||||
if ($item->counterId() !== null) {
|
||||
if ($readingMilli !== null) {
|
||||
$this->maintenance->addReading($item->counterId(), $readingMilli, $actorUserId, $now);
|
||||
} else {
|
||||
$readingMilli = $this->maintenance->latestReading($item->counterId()) ?? $item->baselineMilli();
|
||||
}
|
||||
}
|
||||
|
||||
$recordId = $this->maintenance->addRecord($itemId, $now, $actorUserId, $item->counterId() === null ? null : $readingMilli, $note === '' ? null : mb_substr($note, 0, 2000));
|
||||
$recordId = $this->maintenance->addRecord($itemId, $this->clock->now(), $actorUserId, $readingMilli, $note === '' ? null : mb_substr($note, 0, 2000));
|
||||
|
||||
$stockRecorded = $item->stockItemId() === null
|
||||
|| $this->materials->use($item->stockItemId(), (int) $item->stockQuantityMilli(), $item->machineId(), $recordId, $actorUserId);
|
||||
|
||||
@@ -12,7 +12,8 @@ use DateTimeImmutable;
|
||||
/**
|
||||
* Works out a maintenance item's state from what has accumulated since its
|
||||
* last maintenance (spec 19.5). The counter interval counts the counter's
|
||||
* latest reading minus its reading at the last maintenance; the time
|
||||
* latest reading minus its reading at the last maintenance, so a
|
||||
* maintenance starts the whole interval again; the time
|
||||
* interval counts calendar periods from the day of the last maintenance.
|
||||
* With both, maintenance is due when either is. The advance warning
|
||||
* applies to both, but not to daily maintenance.
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Modules\Machines\Presentation\Livewire\Concerns;
|
||||
|
||||
use App\Modules\Machines\Application\DTOs\CounterSummary;
|
||||
use App\Modules\Machines\Application\DTOs\MaintenanceItemStatus;
|
||||
use App\Modules\Machines\Domain\ValueObjects\Reading;
|
||||
|
||||
/**
|
||||
* Texts of a maintenance item's state, shared by the machine page and the
|
||||
@@ -68,4 +70,17 @@ trait DescribesMaintenance
|
||||
|
||||
return implode(__('machines.maintenance.or'), $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* E.g. "Laskuriin Tulosteet lisätty 350 kpl, laskuri nyt 20 350 kpl."
|
||||
*/
|
||||
public function usageSaved(CounterSummary $counter, string $usage, int $readingMilli): string
|
||||
{
|
||||
return __('machines.maintenance.usage_saved', [
|
||||
'counter' => $counter->name,
|
||||
'usage' => $this->reading((int) Reading::parse($usage)),
|
||||
'reading' => $this->reading($readingMilli),
|
||||
'unit' => __('machines.counter_units.'.$counter->unit->value),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ use App\Modules\Machines\Application\DTOs\MaintenanceItemStatus;
|
||||
use App\Modules\Machines\Application\DTOs\QueueRow;
|
||||
use App\Modules\Machines\Application\UseCases\MachineMaintenance;
|
||||
use App\Modules\Machines\Application\UseCases\MachineWorkList;
|
||||
use App\Modules\Machines\Domain\Enums\CounterUnit;
|
||||
use App\Modules\Machines\Domain\ValueObjects\Reading;
|
||||
use App\Modules\Machines\Presentation\Livewire\Concerns\DescribesMaintenance;
|
||||
use App\Modules\Sales\Application\Contracts\QuickSaleOrderQueries;
|
||||
use App\Modules\Sales\Application\DTOs\OrderLineSummary;
|
||||
@@ -36,8 +38,9 @@ use Livewire\Component;
|
||||
* for the tablet or touch screen next to a machine. It shows today's work
|
||||
* list (late rows of earlier days included; the next day can be viewed),
|
||||
* lets the user start and finish tasks, record the material used with
|
||||
* large item buttons, frequent items first, record today's hours, counter
|
||||
* readings and maintenance. Touch targets are at least 44 × 44 px. The
|
||||
* large item buttons, frequent items first, record today's hours (which
|
||||
* are suggested as the usage of the machine's hour counters), counter
|
||||
* usage and maintenance. Touch targets are at least 44 × 44 px. The
|
||||
* view refreshes itself, and the Refresh button fetches the latest state
|
||||
* at once and tells what changed.
|
||||
*/
|
||||
@@ -85,15 +88,15 @@ new #[Layout('layouts.console')] class extends Component
|
||||
public string $hours = '';
|
||||
|
||||
/**
|
||||
* Usage typed, by counter id.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public array $readings = [];
|
||||
public array $usage = [];
|
||||
|
||||
#[Locked]
|
||||
public ?int $recordingItemId = null;
|
||||
|
||||
public string $recordReading = '';
|
||||
|
||||
#[Locked]
|
||||
public string $message = '';
|
||||
|
||||
@@ -487,35 +490,55 @@ new #[Layout('layouts.console')] class extends Component
|
||||
}
|
||||
|
||||
$this->message = __('machines.console.hours_saved', ['hours' => $this->hours, 'title' => $task->title, 'total' => $total]);
|
||||
$this->suggestHourCounters($this->hours);
|
||||
$this->hours = '';
|
||||
}
|
||||
|
||||
public function saveReading(int $counterId, MachineMaintenance $maintenance): void
|
||||
/**
|
||||
* Hours just booked on the machine are suggested as the usage of its
|
||||
* hour counters; nothing is recorded until the user saves the counter.
|
||||
*/
|
||||
private function suggestHourCounters(string $hours): void
|
||||
{
|
||||
$milli = Reading::parse($hours);
|
||||
|
||||
if ($milli === null || $milli <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->machine->counters as $counter) {
|
||||
if ($counter->unit === CounterUnit::Hour) {
|
||||
$this->usage[$counter->id] = str_replace("\u{00A0}", '', $this->reading($milli));
|
||||
$this->message .= ' '.__('machines.console.hour_suggestion', ['hours' => $this->reading($milli), 'counter' => $counter->name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function saveUsage(int $counterId, MachineMaintenance $maintenance): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
$this->resetErrorBag('readings.'.$counterId);
|
||||
$this->resetErrorBag('usage.'.$counterId);
|
||||
|
||||
$counter = collect($this->machine->counters)->firstWhere('id', $counterId) ?? abort(404);
|
||||
$usage = $this->usage[$counterId] ?? '';
|
||||
|
||||
try {
|
||||
$milli = $maintenance->recordReading($counterId, $this->readings[$counterId] ?? '', (int) auth()->id());
|
||||
$milli = $maintenance->recordUsage($counterId, $usage, (int) auth()->id());
|
||||
} catch (DomainException) {
|
||||
$this->addError('readings.'.$counterId, __('machines.maintenance.errors.reading'));
|
||||
$this->addError('usage.'.$counterId, __('machines.maintenance.errors.usage'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->message = __('machines.maintenance.reading_saved', ['counter' => $counter->name, 'reading' => $this->reading($milli), 'unit' => __('machines.counter_units.'.$counter->unit->value)]);
|
||||
unset($this->readings[$counterId], $this->machine, $this->maintenance);
|
||||
$this->message = $this->usageSaved($counter, $usage, $milli);
|
||||
unset($this->usage[$counterId], $this->machine, $this->maintenance);
|
||||
}
|
||||
|
||||
public function startMaintenance(int $itemId): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$item = collect($this->maintenance)->firstWhere('id', $itemId) ?? abort(404);
|
||||
$this->recordingItemId = $itemId;
|
||||
$this->recordReading = $item->readingMilli === null ? '' : str_replace("\u{00A0}", '', $this->reading($item->readingMilli));
|
||||
$this->recordingItemId = (collect($this->maintenance)->firstWhere('id', $itemId) ?? abort(404))->id;
|
||||
$this->js("setTimeout(() => document.getElementById('maintenance-confirm')?.focus())");
|
||||
}
|
||||
|
||||
@@ -526,11 +549,9 @@ new #[Layout('layouts.console')] class extends Component
|
||||
$item = collect($this->maintenance)->firstWhere('id', $this->recordingItemId) ?? abort(404);
|
||||
|
||||
try {
|
||||
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id(), $item->counterId === null ? '' : $this->recordReading);
|
||||
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id());
|
||||
} catch (DomainException) {
|
||||
$this->addError('recordReading', __('machines.maintenance.errors.reading'));
|
||||
|
||||
return;
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$this->message = __('machines.maintenance.recorded', ['name' => $item->name]).($result['stockRecorded'] ? '' : ' '.__('machines.maintenance.stock_not_recorded'));
|
||||
@@ -612,14 +633,8 @@ new #[Layout('layouts.console')] class extends Component
|
||||
<x-icon name="arrow-path" class="size-6" aria-hidden="true" />
|
||||
{{ __('machines.console.refresh') }}
|
||||
</button>
|
||||
<form method="POST" action="{{ route('logout') }}">
|
||||
@csrf
|
||||
<input type="hidden" name="return_to" value="{{ route('machines.console', $machine->id) }}">
|
||||
<button type="submit" 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>
|
||||
</form>
|
||||
<livewire:users::pin-switch :return-to="route('machines.console', $machine->id)" />
|
||||
{{-- The normal user interface has a session of its own (Users' UseConsoleSession). --}}
|
||||
<a href="{{ route('machines.show', $machine->id) }}" class="{{ $touch }} border border-zinc-300 text-zinc-100 hover:bg-zinc-700">
|
||||
<x-icon name="arrow-left" class="size-6" aria-hidden="true" />
|
||||
{{ __('machines.console.back') }}
|
||||
@@ -811,7 +826,7 @@ new #[Layout('layouts.console')] class extends Component
|
||||
aria-label="{{ __('inventory.task.choose', ['item' => $item->name, 'balance' => $this->quantity($item->balanceMilli, $item->unit)]) }}"
|
||||
>
|
||||
@if ($item->hasImage)
|
||||
<img src="{{ route('inventory.items.image', [$item->id, 'thumbnail']) }}" alt="" class="h-14 w-full rounded object-cover" />
|
||||
<img src="{{ route('inventory.items.console-image', [$item->id, 'thumbnail']) }}" alt="" class="h-14 w-full rounded object-cover" />
|
||||
@endif
|
||||
<span class="font-semibold break-words">{{ $item->name }}</span>
|
||||
<span class="text-base">{{ $this->quantity($item->balanceMilli, $item->unit) }}</span>
|
||||
@@ -847,23 +862,24 @@ new #[Layout('layouts.console')] class extends Component
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
@if ($machine->counters !== [] || $this->maintenance !== [])
|
||||
<section aria-labelledby="console-maintenance-heading" class="space-y-3">
|
||||
<h2 id="console-maintenance-heading" class="text-xl font-semibold">{{ __('machines.console.counters_and_maintenance') }}</h2>
|
||||
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
@foreach ($machine->counters as $counter)
|
||||
<form wire:key="console-counter-{{ $counter->id }}" wire:submit="saveReading({{ $counter->id }})" class="flex flex-wrap items-end gap-2 rounded-lg border border-zinc-300 p-3 dark:border-zinc-600" novalidate>
|
||||
<form wire:key="console-counter-{{ $counter->id }}" wire:submit="saveUsage({{ $counter->id }})" class="flex flex-wrap items-end gap-2 rounded-lg border border-zinc-300 p-3 dark:border-zinc-600" novalidate>
|
||||
<div class="min-w-40 flex-1">
|
||||
<x-input
|
||||
id="console-reading-{{ $counter->id }}"
|
||||
wire:model="readings.{{ $counter->id }}"
|
||||
id="console-usage-{{ $counter->id }}"
|
||||
wire:model="usage.{{ $counter->id }}"
|
||||
inputmode="decimal"
|
||||
:label="$counter->name.' ('.__('machines.counter_units.'.$counter->unit->value).')'"
|
||||
:label="__('machines.console.usage', ['counter' => $counter->name, 'unit' => __('machines.counter_units.'.$counter->unit->value)])"
|
||||
:hint="$counter->readingMilli === null ? __('machines.maintenance.no_reading') : __('machines.console.latest', ['reading' => $this->reading($counter->readingMilli)])"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" class="{{ $primary }}" aria-label="{{ __('machines.maintenance.save_reading_named', ['counter' => $counter->name]) }}">{{ __('machines.maintenance.save_reading') }}</button>
|
||||
<button type="submit" class="{{ $primary }}" aria-label="{{ __('machines.maintenance.save_usage_named', ['counter' => $counter->name]) }}">{{ __('machines.maintenance.save_usage') }}</button>
|
||||
</form>
|
||||
@endforeach
|
||||
</div>
|
||||
@@ -878,11 +894,6 @@ new #[Layout('layouts.console')] class extends Component
|
||||
</p>
|
||||
@if ($recordingItemId === $item->id)
|
||||
<form wire:submit="recordMaintenance" class="flex flex-wrap items-end gap-2" novalidate>
|
||||
@if ($item->counterId !== null)
|
||||
<div class="w-40">
|
||||
<x-input id="maintenance-reading" wire:model="recordReading" inputmode="decimal" :label="__('machines.maintenance.reading_at', ['counter' => (string) $item->counterName])" autocomplete="off" />
|
||||
</div>
|
||||
@endif
|
||||
<button type="submit" id="maintenance-confirm" class="{{ $primary }}">{{ __('machines.maintenance.confirm_done') }}</button>
|
||||
</form>
|
||||
@else
|
||||
@@ -895,4 +906,5 @@ new #[Layout('layouts.console')] class extends Component
|
||||
@endforeach
|
||||
</ul>
|
||||
</section>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@@ -128,7 +128,7 @@ new class extends Component
|
||||
@endunless
|
||||
</p>
|
||||
</div>
|
||||
<x-link :href="route('machines.console', $machine->id)" class="text-sm">{{ __('machines.index.console_named', ['name' => $machine->name]) }}</x-link>
|
||||
<x-link :href="route('console.handoff', ['to' => route('machines.console', $machine->id)])" blank class="text-sm">{{ __('machines.index.console_named', ['name' => $machine->name]) }}<span class="sr-only"> ({{ __('layout.opens_in_new_window') }})</span></x-link>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
||||
@@ -19,9 +19,11 @@ use Livewire\Component;
|
||||
|
||||
/**
|
||||
* A machine's counters, maintenance items and maintenance history on its
|
||||
* page (spec 19.5). Anyone using the machine records counter readings and
|
||||
* maintenance done (the reading prefilled); management keeps the items
|
||||
* and cancels mistaken records. The history is filtered by item and days.
|
||||
* page (spec 19.5). Anyone using the machine records how much of a
|
||||
* counter a job used (counters are cumulative) and maintenance done;
|
||||
* management keeps the items and cancels mistaken records. The history is
|
||||
* filtered by item and days. Without counters and maintenance items the
|
||||
* sections are left out, except the add button for management.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
@@ -31,17 +33,15 @@ new class extends Component
|
||||
public int $machineId;
|
||||
|
||||
/**
|
||||
* Readings typed, by counter id.
|
||||
* Usage typed, by counter id.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public array $readings = [];
|
||||
public array $usage = [];
|
||||
|
||||
#[Locked]
|
||||
public ?int $recordingItemId = null;
|
||||
|
||||
public string $recordReading = '';
|
||||
|
||||
public string $recordNote = '';
|
||||
|
||||
public string $historyItem = '';
|
||||
@@ -100,37 +100,36 @@ new class extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function saveReading(int $counterId, MachineMaintenance $maintenance): void
|
||||
public function saveUsage(int $counterId, MachineMaintenance $maintenance): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
$this->resetErrorBag('readings.'.$counterId);
|
||||
$this->resetErrorBag('usage.'.$counterId);
|
||||
|
||||
$counter = collect($this->machine->counters)->firstWhere('id', $counterId) ?? abort(404);
|
||||
$usage = $this->usage[$counterId] ?? '';
|
||||
|
||||
try {
|
||||
$milli = $maintenance->recordReading($counterId, $this->readings[$counterId] ?? '', (int) auth()->id());
|
||||
$milli = $maintenance->recordUsage($counterId, $usage, (int) auth()->id());
|
||||
} catch (InvalidReading) {
|
||||
$this->addError('readings.'.$counterId, __('machines.maintenance.errors.reading'));
|
||||
$this->addError('usage.'.$counterId, __('machines.maintenance.errors.usage'));
|
||||
|
||||
return;
|
||||
} catch (CounterNotFound) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$this->message = __('machines.maintenance.reading_saved', ['counter' => $counter->name, 'reading' => $this->reading($milli), 'unit' => __('machines.counter_units.'.$counter->unit->value)]);
|
||||
unset($this->readings[$counterId], $this->machine, $this->items);
|
||||
$this->message = $this->usageSaved($counter, $usage, $milli);
|
||||
unset($this->usage[$counterId], $this->machine, $this->items);
|
||||
}
|
||||
|
||||
public function startRecord(int $itemId): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$item = $this->item($itemId);
|
||||
$this->recordingItemId = $itemId;
|
||||
$this->recordReading = $item->readingMilli === null ? '' : str_replace("\u{00A0}", '', $this->reading($item->readingMilli));
|
||||
$this->recordingItemId = $this->item($itemId)->id;
|
||||
$this->recordNote = '';
|
||||
$this->resetErrorBag();
|
||||
$this->js("setTimeout(() => document.getElementById('record-reading')?.focus() ?? document.getElementById('record-note')?.focus())");
|
||||
$this->js("setTimeout(() => document.getElementById('record-note')?.focus())");
|
||||
}
|
||||
|
||||
public function cancelRecording(): void
|
||||
@@ -147,11 +146,7 @@ new class extends Component
|
||||
$item = $this->item((int) $this->recordingItemId);
|
||||
|
||||
try {
|
||||
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id(), $item->counterId === null ? '' : $this->recordReading, $this->recordNote);
|
||||
} catch (InvalidReading) {
|
||||
$this->addError('recordReading', __('machines.maintenance.errors.reading'));
|
||||
|
||||
return;
|
||||
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id(), $this->recordNote);
|
||||
} catch (MaintenanceItemNotFound) {
|
||||
abort(404);
|
||||
}
|
||||
@@ -231,17 +226,17 @@ new class extends Component
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
<form wire:submit="saveReading({{ $counter->id }})" class="flex flex-wrap items-end gap-2" novalidate>
|
||||
<form wire:submit="saveUsage({{ $counter->id }})" class="flex flex-wrap items-end gap-2" novalidate>
|
||||
<div class="w-40">
|
||||
<x-input
|
||||
id="reading-{{ $counter->id }}"
|
||||
wire:model="readings.{{ $counter->id }}"
|
||||
id="usage-{{ $counter->id }}"
|
||||
wire:model="usage.{{ $counter->id }}"
|
||||
inputmode="decimal"
|
||||
:label="__('machines.maintenance.new_reading', ['unit' => __('machines.counter_units.'.$counter->unit->value)])"
|
||||
:label="__('machines.maintenance.usage', ['unit' => __('machines.counter_units.'.$counter->unit->value)])"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</div>
|
||||
<x-button submit sm :text="__('machines.maintenance.save_reading')" :aria-label="__('machines.maintenance.save_reading_named', ['counter' => $counter->name])" />
|
||||
<x-button submit sm :text="__('machines.maintenance.save_usage')" :aria-label="__('machines.maintenance.save_usage_named', ['counter' => $counter->name])" />
|
||||
</form>
|
||||
</li>
|
||||
@endforeach
|
||||
@@ -249,6 +244,9 @@ new class extends Component
|
||||
</section>
|
||||
@endif
|
||||
|
||||
@php($hasMaintenance = $this->machine->counters !== [] || $this->items !== [])
|
||||
|
||||
@if ($hasMaintenance || auth()->user()?->can('machines.manage'))
|
||||
<section aria-labelledby="maintenance-heading" class="space-y-3">
|
||||
<h2 id="maintenance-heading" class="text-xl font-semibold">{{ __('machines.maintenance.items') }}</h2>
|
||||
@can('machines.manage')
|
||||
@@ -292,11 +290,6 @@ new class extends Component
|
||||
@if ($item->isActive)
|
||||
@if ($recordingItemId === $item->id)
|
||||
<form wire:submit="record" class="flex flex-wrap items-end gap-2" novalidate>
|
||||
@if ($item->counterId !== null)
|
||||
<div class="w-40">
|
||||
<x-input id="record-reading" wire:model="recordReading" inputmode="decimal" :label="__('machines.maintenance.reading_at', ['counter' => (string) $item->counterName])" autocomplete="off" />
|
||||
</div>
|
||||
@endif
|
||||
<div class="min-w-48 flex-1">
|
||||
<x-input id="record-note" wire:model="recordNote" :label="__('machines.maintenance.note')" autocomplete="off" maxlength="2000" />
|
||||
</div>
|
||||
@@ -312,7 +305,9 @@ new class extends Component
|
||||
</ul>
|
||||
@endif
|
||||
</section>
|
||||
@endif
|
||||
|
||||
@if ($hasMaintenance)
|
||||
<section aria-labelledby="history-heading" class="space-y-3">
|
||||
<h2 id="history-heading" class="text-xl font-semibold">{{ __('machines.maintenance.history') }}</h2>
|
||||
<div class="grid gap-3 sm:grid-cols-3">
|
||||
@@ -358,6 +353,7 @@ new class extends Component
|
||||
</ul>
|
||||
@endif
|
||||
</section>
|
||||
@endif
|
||||
|
||||
@can('machines.manage')
|
||||
<x-confirm-dialog id="cancel-record-dialog" :title="__('machines.maintenance.cancel_title')">
|
||||
|
||||
@@ -258,7 +258,8 @@ new class extends Component
|
||||
<p class="text-sm whitespace-pre-line">{{ $machine->description }}</p>
|
||||
@endif
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<x-button :href="route('machines.console', $machine->id)" sm icon="device-tablet" :text="__('machines.show.console')" />
|
||||
{{-- The console opens in its own window with its own session, signed in as the same user. --}}
|
||||
<x-button :href="route('console.handoff', ['to' => route('machines.console', $machine->id)])" target="_blank" sm icon="arrow-top-right-on-square" :text="__('machines.show.console')" :aria-label="__('machines.show.console').' ('.__('layout.opens_in_new_window').')'" />
|
||||
@can('machines.manage')
|
||||
<x-button :href="route('machines.edit', $machine->id)" wire:navigate subtle color="black" sm icon="pencil" :text="__('machines.show.edit')" />
|
||||
@endcan
|
||||
|
||||
@@ -16,5 +16,10 @@ Route::middleware(['web', 'auth', 'can:machines.use'])
|
||||
});
|
||||
|
||||
Route::livewire('/{machine}', 'machines::show')->whereNumber('machine')->name('show');
|
||||
Route::livewire('/{machine}/console', 'machines::console')->whereNumber('machine')->name('console');
|
||||
});
|
||||
|
||||
// The console has its own session (Users' UseConsoleSession: paths under console/).
|
||||
Route::livewire('/console/machines/{machine}', 'machines::console')
|
||||
->middleware(['web', 'auth', 'can:machines.use'])
|
||||
->whereNumber('machine')
|
||||
->name('machines.console');
|
||||
|
||||
@@ -385,7 +385,7 @@ new class extends Component
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<x-button wire:click="startComplete({{ $line->id }})" subtle color="black" sm icon="check" :text="__('sales.orders.complete_step')" :aria-label="__('sales.orders.complete_step_named', ['number' => $order->pickupNumber, 'product' => $line->productName])" />
|
||||
@if ($line->currentMachineId() !== null)
|
||||
<x-link :href="route('machines.console', $line->currentMachineId())" class="text-sm">{{ __('sales.orders.open_console', ['machine' => $this->machineNames[$line->currentMachineId()] ?? '']) }}</x-link>
|
||||
<x-link :href="route('console.handoff', ['to' => route('machines.console', $line->currentMachineId())])" blank class="text-sm">{{ __('sales.orders.open_console', ['machine' => $this->machineNames[$line->currentMachineId()] ?? '']) }}<span class="sr-only"> ({{ __('layout.opens_in_new_window') }})</span></x-link>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Users\Application\Contracts;
|
||||
|
||||
/**
|
||||
* One-way hashing of passwords and PIN codes.
|
||||
*/
|
||||
interface SecretHasher
|
||||
{
|
||||
public function hash(string $secret): string;
|
||||
|
||||
public function check(string $secret, string $hash): bool;
|
||||
}
|
||||
@@ -36,6 +36,14 @@ interface UserAccountQueries
|
||||
*/
|
||||
public function activeUserOptions(): array;
|
||||
|
||||
/**
|
||||
* Users who may sign in today and have a console PIN code, ordered by
|
||||
* name, for switching user on a machine console.
|
||||
*
|
||||
* @return list<UserOption>
|
||||
*/
|
||||
public function pinLoginOptions(): array;
|
||||
|
||||
/**
|
||||
* User names for many ids at once, active or not (for lists and history).
|
||||
*
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Users\Application\UseCases;
|
||||
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
use App\Modules\Users\Application\Contracts\SecretHasher;
|
||||
use App\Modules\Users\Domain\Contracts\LoginSecrets;
|
||||
use App\Modules\Users\Domain\Exceptions\InvalidLoginPin;
|
||||
use App\Modules\Users\Domain\Exceptions\WrongPassword;
|
||||
use App\Modules\Users\Domain\ValueObjects\LoginPin;
|
||||
|
||||
/**
|
||||
* Users' own PIN codes for switching user on a machine console (spec
|
||||
* 19.6): a user sets one with their password, and the console signs them
|
||||
* in with it while their account may sign in. Only the hash is stored.
|
||||
*/
|
||||
final class LoginPins
|
||||
{
|
||||
public function __construct(
|
||||
private LoginSecrets $secrets,
|
||||
private SecretHasher $hasher,
|
||||
private CheckLoginAllowed $loginAllowed,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws InvalidLoginPin
|
||||
* @throws WrongPassword
|
||||
*/
|
||||
public function set(int $userId, string $currentPassword, string $pin): void
|
||||
{
|
||||
$pin = new LoginPin($pin);
|
||||
$this->checkPassword($userId, $currentPassword);
|
||||
|
||||
$this->transactions->run(fn () => $this->secrets->storePinHash($userId, $this->hasher->hash($pin->value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WrongPassword
|
||||
*/
|
||||
public function remove(int $userId, string $currentPassword): void
|
||||
{
|
||||
$this->checkPassword($userId, $currentPassword);
|
||||
|
||||
$this->transactions->run(fn () => $this->secrets->storePinHash($userId, null));
|
||||
}
|
||||
|
||||
public function has(int $userId): bool
|
||||
{
|
||||
return $this->secrets->pinHashOf($userId) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the PIN code is the user's and the user may sign in today.
|
||||
*/
|
||||
public function verify(int $userId, string $pin): bool
|
||||
{
|
||||
$hash = $this->secrets->pinHashOf($userId);
|
||||
|
||||
return $hash !== null
|
||||
&& preg_match('/^\d{'.LoginPin::MIN_LENGTH.','.LoginPin::MAX_LENGTH.'}$/', trim($pin)) === 1
|
||||
&& $this->hasher->check(trim($pin), $hash)
|
||||
&& $this->loginAllowed->execute($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WrongPassword
|
||||
*/
|
||||
private function checkPassword(int $userId, string $password): void
|
||||
{
|
||||
$hash = $this->secrets->passwordHashOf($userId);
|
||||
|
||||
if ($hash === null || ! $this->hasher->check($password, $hash)) {
|
||||
throw new WrongPassword;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Users\Domain\Contracts;
|
||||
|
||||
/**
|
||||
* The hashes of a user's password and console PIN code.
|
||||
*/
|
||||
interface LoginSecrets
|
||||
{
|
||||
public function passwordHashOf(int $userId): ?string;
|
||||
|
||||
public function pinHashOf(int $userId): ?string;
|
||||
|
||||
/**
|
||||
* Stores the hash of the user's PIN code, or removes it with null.
|
||||
*/
|
||||
public function storePinHash(int $userId, ?string $hash): void;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Users\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class InvalidLoginPin extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The PIN code must be 4–6 digits.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Users\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class WrongPassword extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The current password is not correct.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Users\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Users\Domain\Exceptions\InvalidLoginPin;
|
||||
|
||||
/**
|
||||
* A user's own PIN code for switching user on a machine console: 4–6
|
||||
* digits. It is never stored as such, only its hash.
|
||||
*/
|
||||
final readonly class LoginPin
|
||||
{
|
||||
public const int MIN_LENGTH = 4;
|
||||
|
||||
public const int MAX_LENGTH = 6;
|
||||
|
||||
public string $value;
|
||||
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
if (preg_match('/^\d{'.self::MIN_LENGTH.','.self::MAX_LENGTH.'}$/', $value) !== 1) {
|
||||
throw new InvalidLoginPin;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Users\Infrastructure\Auth;
|
||||
|
||||
use App\Modules\Users\Application\Contracts\SecretHasher;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class LaravelSecretHasher implements SecretHasher
|
||||
{
|
||||
public function hash(string $secret): string
|
||||
{
|
||||
return Hash::make($secret);
|
||||
}
|
||||
|
||||
public function check(string $secret, string $hash): bool
|
||||
{
|
||||
return Hash::check($secret, $hash);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Users\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Users\Domain\Contracts\LoginSecrets;
|
||||
|
||||
class EloquentLoginSecrets implements LoginSecrets
|
||||
{
|
||||
public function passwordHashOf(int $userId): ?string
|
||||
{
|
||||
$hash = User::query()->whereKey($userId)->value('password');
|
||||
|
||||
return $hash === null ? null : (string) $hash;
|
||||
}
|
||||
|
||||
public function pinHashOf(int $userId): ?string
|
||||
{
|
||||
$hash = User::query()->whereKey($userId)->value('pin_hash');
|
||||
|
||||
return $hash === null ? null : (string) $hash;
|
||||
}
|
||||
|
||||
public function storePinHash(int $userId, ?string $hash): void
|
||||
{
|
||||
User::query()->whereKey($userId)->update(['pin_hash' => $hash]);
|
||||
}
|
||||
}
|
||||
+20
@@ -3,6 +3,7 @@
|
||||
namespace App\Modules\Users\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Application\DTOs\UserOption;
|
||||
use App\Modules\Users\Application\DTOs\UserSummary;
|
||||
@@ -12,6 +13,10 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class EloquentUserAccountQueries implements UserAccountQueries
|
||||
{
|
||||
public function __construct(
|
||||
private Clock $clock,
|
||||
) {}
|
||||
|
||||
public function findSummary(int $id): ?UserSummary
|
||||
{
|
||||
$model = User::query()->with(['supervisor:id,name', 'moneyPermissions'])->find($id);
|
||||
@@ -61,6 +66,21 @@ class EloquentUserAccountQueries implements UserAccountQueries
|
||||
->all();
|
||||
}
|
||||
|
||||
public function pinLoginOptions(): array
|
||||
{
|
||||
$today = $this->clock->today()->format('Y-m-d');
|
||||
|
||||
return User::query()
|
||||
->where('is_active', true)
|
||||
->whereNotNull('pin_hash')
|
||||
->where(fn (Builder $query) => $query->whereNull('employment_ends_on')->orWhereDate('employment_ends_on', '>=', $today))
|
||||
->orderBy('name')
|
||||
->get(['id', 'name', 'role'])
|
||||
->map(fn (User $model): UserOption => new UserOption($model->id, $model->name, $model->role))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
public function namesByIds(array $ids): array
|
||||
{
|
||||
return $ids === [] ? [] : User::query()->whereIn('id', $ids)->pluck('name', 'id')->all();
|
||||
|
||||
@@ -5,11 +5,15 @@ namespace App\Modules\Users\Infrastructure\Providers;
|
||||
use App\Models\User;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
use App\Modules\Users\Application\Contracts\PasswordLinkSender;
|
||||
use App\Modules\Users\Application\Contracts\SecretHasher;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Domain\Contracts\LoginSecrets;
|
||||
use App\Modules\Users\Domain\Contracts\UserAccountRepository;
|
||||
use App\Modules\Users\Domain\Enums\MoneyPermission;
|
||||
use App\Modules\Users\Infrastructure\Auth\LaravelPasswordLinkSender;
|
||||
use App\Modules\Users\Infrastructure\Auth\LaravelSecretHasher;
|
||||
use App\Modules\Users\Infrastructure\Auth\PasswordLinkMail;
|
||||
use App\Modules\Users\Infrastructure\Persistence\Repositories\EloquentLoginSecrets;
|
||||
use App\Modules\Users\Infrastructure\Persistence\Repositories\EloquentUserAccountQueries;
|
||||
use App\Modules\Users\Infrastructure\Persistence\Repositories\EloquentUserAccountRepository;
|
||||
use App\Modules\Users\Infrastructure\SystemClock;
|
||||
@@ -17,6 +21,7 @@ use App\Modules\Users\Presentation\Console\CreateAdminCommand;
|
||||
use App\Modules\Users\Presentation\Http\Listeners\StoreLocaleChosenBeforeLogin;
|
||||
use App\Modules\Users\Presentation\Http\Middleware\EnsureAccountIsUsable;
|
||||
use App\Modules\Users\Presentation\Http\Middleware\SetLocale;
|
||||
use App\Modules\Users\Presentation\Http\Middleware\UseConsoleSession;
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Contracts\Auth\CanResetPassword;
|
||||
@@ -42,6 +47,8 @@ class UsersServiceProvider extends ServiceProvider
|
||||
UserAccountRepository::class => EloquentUserAccountRepository::class,
|
||||
UserAccountQueries::class => EloquentUserAccountQueries::class,
|
||||
PasswordLinkSender::class => LaravelPasswordLinkSender::class,
|
||||
LoginSecrets::class => EloquentLoginSecrets::class,
|
||||
SecretHasher::class => LaravelSecretHasher::class,
|
||||
];
|
||||
|
||||
public function register(): void
|
||||
@@ -59,6 +66,9 @@ class UsersServiceProvider extends ServiceProvider
|
||||
$this->loadRoutesFrom($presentationPath.'/Routes/web.php');
|
||||
}
|
||||
|
||||
// The machine console's own session and guard; before the session starts.
|
||||
$router->prependMiddlewareToGroup('web', UseConsoleSession::class);
|
||||
|
||||
$router->pushMiddlewareToGroup('web', EnsureAccountIsUsable::class);
|
||||
|
||||
// Ends the user's other sessions when their password changes.
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Users\Presentation\Http\Controllers;
|
||||
|
||||
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
|
||||
use App\Modules\Users\Presentation\Http\Middleware\UseConsoleSession;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Opens the machine console in its own window signed in as the same user
|
||||
* (spec 19.6). The normal user interface makes a one-time key valid for a
|
||||
* minute; the console's own session (UseConsoleSession) takes it and signs
|
||||
* the user in there. After that the two sessions live apart.
|
||||
*/
|
||||
class ConsoleHandoff
|
||||
{
|
||||
public const int SECONDS = 60;
|
||||
|
||||
/**
|
||||
* In the normal user interface: a key for the console page in "to".
|
||||
*/
|
||||
public function start(Request $request): RedirectResponse
|
||||
{
|
||||
$to = (string) $request->query('to', '');
|
||||
abort_unless(UseConsoleSession::isConsoleUrl($to), 404);
|
||||
|
||||
$token = Str::random(40);
|
||||
Cache::put(self::cacheKey($token), ['user' => (int) $request->user()?->getAuthIdentifier(), 'to' => $to], self::SECONDS);
|
||||
|
||||
return redirect()->route('console.handoff.accept', $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* In the console's own session: signs in with the key once.
|
||||
*/
|
||||
public function accept(Request $request, string $token, CheckLoginAllowed $checkLoginAllowed): RedirectResponse
|
||||
{
|
||||
/** @var array{user: int, to: string}|null $handoff */
|
||||
$handoff = Cache::pull(self::cacheKey($token));
|
||||
|
||||
if ($handoff === null || ! $checkLoginAllowed->execute($handoff['user'])) {
|
||||
return redirect()->route('console.login');
|
||||
}
|
||||
|
||||
if (Auth::check()) {
|
||||
Auth::logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
}
|
||||
|
||||
Auth::loginUsingId($handoff['user']);
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->to($handoff['to']);
|
||||
}
|
||||
|
||||
private static function cacheKey(string $token): string
|
||||
{
|
||||
return 'console-handoff|'.hash('sha256', $token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Users\Presentation\Http\Controllers;
|
||||
|
||||
use App\Modules\Users\Presentation\Http\Middleware\SetLocale;
|
||||
use App\Modules\Users\Presentation\Http\Middleware\UseConsoleSession;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Signs out of the machine console's own session only (spec 19.6), e.g. to
|
||||
* sign in there with email and password; the normal user interface stays
|
||||
* signed in. The console's sign-in page returns to the console page.
|
||||
*/
|
||||
class ConsoleLogoutController
|
||||
{
|
||||
public function __invoke(Request $request): RedirectResponse
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
$returnTo = (string) $request->input('return_to', '');
|
||||
|
||||
Auth::logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
$request->session()->put(SetLocale::SESSION_KEY, $locale);
|
||||
|
||||
if (UseConsoleSession::isConsoleUrl($returnTo)) {
|
||||
$request->session()->put('url.intended', $returnTo);
|
||||
}
|
||||
|
||||
return redirect()->route('console.login');
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class EnsureAccountIsUsable
|
||||
|
||||
// The reason goes in the URL: Livewire follows this redirect with
|
||||
// fetch first, which would consume a flashed message.
|
||||
return redirect()->route('login', ['access' => 'ended']);
|
||||
return redirect()->route(UseConsoleSession::isConsole($request) ? 'console.login' : 'login', ['access' => 'ended']);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Users\Presentation\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Gives the machine console its own session (spec 19.6), so the console can
|
||||
* run in its own window or on a tablet next to the normal user interface
|
||||
* in the same browser: pages under console/ and the Livewire requests of
|
||||
* components rendered there use a session cookie of their own and the
|
||||
* "console" guard. Signing in or out on one side leaves the other alone,
|
||||
* and /login always signs in to the normal user interface.
|
||||
*
|
||||
* Runs before StartSession. A Livewire request tells where its component
|
||||
* was rendered by the path Livewire keeps in the snapshot (memo.path); it
|
||||
* can only choose between the browser's own sessions, and the CSRF token
|
||||
* of that session must still match.
|
||||
*/
|
||||
class UseConsoleSession
|
||||
{
|
||||
public const string PREFIX = 'console';
|
||||
|
||||
public const string GUARD = 'console';
|
||||
|
||||
public const string DEFAULT_GUARD = 'web';
|
||||
|
||||
public function __construct(private SessionManager $sessions) {}
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$console = self::isConsole($request);
|
||||
$cookie = (string) config('session.cookie');
|
||||
|
||||
$this->sessions->driver()->setName($console ? $cookie.'_console' : $cookie);
|
||||
Auth::shouldUse($console ? self::GUARD : self::DEFAULT_GUARD);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
public static function isConsole(Request $request): bool
|
||||
{
|
||||
if (self::isConsolePath($request->path())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $request->hasHeader('X-Livewire')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$snapshot = json_decode((string) $request->input('components.0.snapshot', ''), true);
|
||||
$path = is_array($snapshot) ? ($snapshot['memo']['path'] ?? null) : null;
|
||||
|
||||
return is_string($path) && self::isConsolePath($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a URL of this application is on the console.
|
||||
*/
|
||||
public static function isConsoleUrl(string $url): bool
|
||||
{
|
||||
$base = rtrim(url('/'), '/').'/';
|
||||
|
||||
return Str::startsWith($url, $base.self::PREFIX.'/') && ! Str::contains($url, ['\\', '@']);
|
||||
}
|
||||
|
||||
private static function isConsolePath(string $path): bool
|
||||
{
|
||||
$path = trim($path, '/');
|
||||
|
||||
return $path === self::PREFIX || str_starts_with($path, self::PREFIX.'/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Users\Presentation\Livewire\Concerns;
|
||||
|
||||
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Signing in with email and password, on the login page and on the
|
||||
* machine console's sign-in page: 5 failed attempts a minute per email and
|
||||
* address, 20 per address across all accounts (password spraying), and one
|
||||
* message for a wrong password and a disabled account. Signs in to the
|
||||
* request's guard (the console's own on console pages).
|
||||
*
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
*/
|
||||
trait SignsInWithPassword
|
||||
{
|
||||
public string $email = '';
|
||||
|
||||
public string $password = '';
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
protected function signInWithPassword(CheckLoginAllowed $checkLoginAllowed, bool $remember = false): void
|
||||
{
|
||||
$this->email = trim($this->email);
|
||||
|
||||
$this->validate(
|
||||
['email' => ['required', 'string', 'email'], 'password' => ['required', 'string']],
|
||||
[
|
||||
'email.required' => __('auth.email_required'),
|
||||
'email.email' => __('auth.email_invalid'),
|
||||
'password.required' => __('auth.password_required'),
|
||||
],
|
||||
);
|
||||
|
||||
$email = Str::lower(trim($this->email));
|
||||
$throttleKey = Str::transliterate($email.'|'.request()->ip());
|
||||
$ipThrottleKey = 'login-ip|'.request()->ip();
|
||||
|
||||
foreach ([$throttleKey => 5, $ipThrottleKey => 20] as $key => $maxAttempts) {
|
||||
if (RateLimiter::tooManyAttempts($key, $maxAttempts)) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.throttle', ['seconds' => RateLimiter::availableIn($key)]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$signedIn = Auth::attemptWhen(
|
||||
['email' => $email, 'password' => $this->password],
|
||||
fn ($user): bool => $checkLoginAllowed->execute($user->getAuthIdentifier()),
|
||||
$remember,
|
||||
);
|
||||
|
||||
if (! $signedIn) {
|
||||
RateLimiter::hit($throttleKey);
|
||||
RateLimiter::hit($ipThrottleKey);
|
||||
$this->reset('password');
|
||||
|
||||
// One message for a wrong password and a disabled account, so the
|
||||
// form never confirms that a disabled account's password is right.
|
||||
throw ValidationException::withMessages(['email' => __('auth.failed')]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($throttleKey);
|
||||
session()->regenerate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Users\Presentation\Livewire\Concerns;
|
||||
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Application\DTOs\UserOption;
|
||||
use App\Modules\Users\Application\UseCases\LoginPins;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Livewire\Attributes\Computed;
|
||||
|
||||
/**
|
||||
* Signing in with a user's own console PIN code (spec 19.6): the user picks
|
||||
* their name and types the PIN. Five wrong PIN codes lock the user's PIN
|
||||
* sign-in for 15 minutes, and one address may try 20 times a minute. Ends
|
||||
* the request's guard's earlier sign-in (the console's own on console
|
||||
* pages) and starts a new session for the user.
|
||||
*/
|
||||
trait SignsInWithPin
|
||||
{
|
||||
public string $userId = '';
|
||||
|
||||
public string $pin = '';
|
||||
|
||||
/**
|
||||
* @return list<UserOption>
|
||||
*/
|
||||
#[Computed]
|
||||
public function pinUsers(): array
|
||||
{
|
||||
return app(UserAccountQueries::class)->pinLoginOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool Whether the user is now signed in.
|
||||
*/
|
||||
protected function signInWithPin(LoginPins $pins): bool
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
|
||||
$user = collect($this->pinUsers)->firstWhere('id', (int) $this->userId);
|
||||
|
||||
if ($user === null) {
|
||||
$this->addError('userId', __('users.pin_switch.errors.user'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$userKey = 'pin-login|user|'.$user->id;
|
||||
$ipKey = 'pin-login|ip|'.request()->ip();
|
||||
|
||||
foreach ([[$userKey, 5], [$ipKey, 20]] as [$key, $max]) {
|
||||
if (RateLimiter::tooManyAttempts($key, $max)) {
|
||||
$this->addError('pin', __('users.pin_switch.errors.locked', ['minutes' => (int) ceil(RateLimiter::availableIn($key) / 60)]));
|
||||
$this->pin = '';
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RateLimiter::hit($ipKey, 60);
|
||||
|
||||
if (! $pins->verify($user->id, $this->pin)) {
|
||||
RateLimiter::hit($userKey, 900);
|
||||
$this->addError('pin', __('users.pin_switch.errors.pin'));
|
||||
$this->pin = '';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RateLimiter::clear($userKey);
|
||||
|
||||
if (Auth::check()) {
|
||||
Auth::logout();
|
||||
session()->invalidate();
|
||||
session()->regenerateToken();
|
||||
}
|
||||
|
||||
Auth::loginUsingId($user->id);
|
||||
session()->regenerate();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
|
||||
use App\Modules\Users\Application\UseCases\LoginPins;
|
||||
use App\Modules\Users\Presentation\Livewire\Concerns\SignsInWithPassword;
|
||||
use App\Modules\Users\Presentation\Livewire\Concerns\SignsInWithPin;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Signing in to the machine console's own session (spec 19.6), e.g. on a
|
||||
* tablet next to the machine: with the user's own PIN code or with email
|
||||
* and password. Returns to the console page that asked for it.
|
||||
*/
|
||||
new #[Layout('layouts.console')] class extends Component
|
||||
{
|
||||
use SignsInWithPassword;
|
||||
use SignsInWithPin;
|
||||
|
||||
public bool $accessEnded = false;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->accessEnded = request()->query('access') === 'ended';
|
||||
}
|
||||
|
||||
public function loginWithPin(LoginPins $pins): void
|
||||
{
|
||||
if ($this->signInWithPin($pins)) {
|
||||
$this->redirectIntended(route('machines.index'));
|
||||
}
|
||||
}
|
||||
|
||||
public function loginWithPassword(CheckLoginAllowed $checkLoginAllowed): void
|
||||
{
|
||||
$this->signInWithPassword($checkLoginAllowed);
|
||||
|
||||
$this->redirectIntended(route('machines.index'));
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title(__('users.console_login.title'));
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="mx-auto max-w-3xl space-y-6 p-3 sm:p-6">
|
||||
<h1 class="text-2xl font-semibold">{{ __('users.console_login.title') }}</h1>
|
||||
|
||||
<p>{{ __('users.console_login.intro') }}</p>
|
||||
|
||||
@if ($accessEnded)
|
||||
<x-alert role="status" color="yellow" light icon="exclamation-triangle" :text="__('auth.account_disabled')" />
|
||||
@elseif (session('status'))
|
||||
<x-alert role="status" color="green" light icon="information-circle" :text="session('status')" />
|
||||
@endif
|
||||
|
||||
<div class="grid gap-6 md:grid-cols-2">
|
||||
<section aria-labelledby="console-login-pin" class="space-y-4 rounded-lg border border-zinc-300 p-4 dark:border-zinc-600">
|
||||
<h2 id="console-login-pin" class="text-xl font-semibold">{{ __('users.console_login.with_pin') }}</h2>
|
||||
@if ($this->pinUsers === [])
|
||||
<p>{{ __('users.pin_switch.no_users') }}</p>
|
||||
@else
|
||||
<form wire:submit="loginWithPin" class="space-y-4" novalidate>
|
||||
<x-users.pin-fields :users="$this->pinUsers" />
|
||||
<x-button submit icon="arrow-right-end-on-rectangle" :text="__('users.pin_switch.submit')" class="w-full" />
|
||||
</form>
|
||||
@endif
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="console-login-password" class="space-y-4 rounded-lg border border-zinc-300 p-4 dark:border-zinc-600">
|
||||
<h2 id="console-login-password" class="text-xl font-semibold">{{ __('users.console_login.with_password') }}</h2>
|
||||
<form wire:submit="loginWithPassword" class="space-y-4" novalidate>
|
||||
<x-input id="console-login-email" wire:model="email" type="email" :label="__('auth.email')" autocomplete="username" required />
|
||||
<x-password-field id="console-login-password-field" wire:model="password" :label="__('auth.password_label')" autocomplete="current-password" required />
|
||||
<x-button submit :text="__('auth.login')" class="w-full" />
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,25 +1,12 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Modules\Users\Presentation\Livewire\Concerns\SignsInWithPassword;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public const int MAX_ATTEMPTS_PER_MINUTE = 5;
|
||||
|
||||
/**
|
||||
* Failed attempts from one address across all accounts, so one common
|
||||
* password cannot be tried on every account (password spraying).
|
||||
*/
|
||||
public const int MAX_ATTEMPTS_PER_IP_PER_MINUTE = 20;
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $password = '';
|
||||
use SignsInWithPassword;
|
||||
|
||||
public bool $remember = false;
|
||||
|
||||
@@ -37,47 +24,7 @@ new class extends Component
|
||||
|
||||
public function login(CheckLoginAllowed $checkLoginAllowed): void
|
||||
{
|
||||
$this->email = trim($this->email);
|
||||
|
||||
$this->validate(
|
||||
['email' => ['required', 'string', 'email'], 'password' => ['required', 'string']],
|
||||
[
|
||||
'email.required' => __('auth.email_required'),
|
||||
'email.email' => __('auth.email_invalid'),
|
||||
'password.required' => __('auth.password_required'),
|
||||
],
|
||||
);
|
||||
|
||||
$email = Str::lower(trim($this->email));
|
||||
$throttleKey = Str::transliterate($email.'|'.request()->ip());
|
||||
$ipThrottleKey = 'login-ip|'.request()->ip();
|
||||
|
||||
foreach ([$throttleKey => self::MAX_ATTEMPTS_PER_MINUTE, $ipThrottleKey => self::MAX_ATTEMPTS_PER_IP_PER_MINUTE] as $key => $maxAttempts) {
|
||||
if (RateLimiter::tooManyAttempts($key, $maxAttempts)) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.throttle', ['seconds' => RateLimiter::availableIn($key)]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$signedIn = Auth::attemptWhen(
|
||||
['email' => $email, 'password' => $this->password],
|
||||
fn ($user): bool => $checkLoginAllowed->execute($user->getAuthIdentifier()),
|
||||
$this->remember,
|
||||
);
|
||||
|
||||
if (! $signedIn) {
|
||||
RateLimiter::hit($throttleKey);
|
||||
RateLimiter::hit($ipThrottleKey);
|
||||
$this->reset('password');
|
||||
|
||||
// One message for a wrong password and a disabled account, so the
|
||||
// form never confirms that a disabled account's password is right.
|
||||
throw ValidationException::withMessages(['email' => __('auth.failed')]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($throttleKey);
|
||||
session()->regenerate();
|
||||
$this->signInWithPassword($checkLoginAllowed, $this->remember);
|
||||
|
||||
$this->redirectIntended(route('home'));
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -0,0 +1,101 @@
|
||||
<?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>
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Users\Presentation\Http\Controllers\ConsoleHandoff;
|
||||
use App\Modules\Users\Presentation\Http\Controllers\ConsoleLogoutController;
|
||||
use App\Modules\Users\Presentation\Http\Controllers\LogoutController;
|
||||
use App\Modules\Users\Presentation\Http\Controllers\SwitchLocaleController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -12,8 +14,17 @@ Route::middleware(['web', 'guest'])->group(function () {
|
||||
Route::livewire('/reset-password/{token}', 'users::reset-password')->name('password.reset');
|
||||
});
|
||||
|
||||
// The machine console's own session (UseConsoleSession: paths under console/).
|
||||
Route::middleware('web')->prefix('console')->name('console.')->group(function () {
|
||||
Route::livewire('/login', 'users::console-login')->middleware('guest')->name('login');
|
||||
Route::get('/handoff/{token}', [ConsoleHandoff::class, 'accept'])->middleware('throttle:30,1')->name('handoff.accept');
|
||||
Route::post('/logout', ConsoleLogoutController::class)->middleware('auth')->name('logout');
|
||||
});
|
||||
|
||||
Route::middleware(['web', 'auth'])->group(function () {
|
||||
Route::post('/logout', LogoutController::class)->name('logout');
|
||||
Route::livewire('/profile/pin', 'users::pin')->middleware('can:machines.use')->name('profile.pin');
|
||||
Route::get('/console-handoff', [ConsoleHandoff::class, 'start'])->middleware('throttle:30,1')->name('console.handoff');
|
||||
|
||||
Route::middleware('can:users.manage')
|
||||
->prefix('users')
|
||||
|
||||
Reference in New Issue
Block a user