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:
2026-11-29 09:58:11 +02:00
co-authored by Claude Sonnet 5.5
parent 87e38260dc
commit 32c33e2a64
55 changed files with 1660 additions and 194 deletions
@@ -0,0 +1,87 @@
<?php
use App\Modules\Shared\Domain\ValueObjects\EmailAddress;
use App\Modules\Users\Application\Contracts\SecretHasher;
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
use App\Modules\Users\Application\UseCases\LoginPins;
use App\Modules\Users\Domain\Contracts\LoginSecrets;
use App\Modules\Users\Domain\Entities\UserAccount;
use App\Modules\Users\Domain\Enums\Role;
use App\Modules\Users\Domain\Exceptions\WrongPassword;
use App\Modules\Users\Domain\ValueObjects\PersonName;
use Tests\Fakes\FakeClock;
use Tests\Fakes\FakeTransactionManager;
use Tests\Fakes\InMemoryUserAccountRepository;
beforeEach(function () {
$this->users = new InMemoryUserAccountRepository;
$this->userId = $this->users->save(UserAccount::register(new PersonName('Olli'), new EmailAddress('[email protected]'), Role::Employee))->id();
$this->secrets = new class implements LoginSecrets
{
/** @var array<int, string> */
public array $passwords = [];
/** @var array<int, string> */
public array $pins = [];
public function passwordHashOf(int $userId): ?string
{
return $this->passwords[$userId] ?? null;
}
public function pinHashOf(int $userId): ?string
{
return $this->pins[$userId] ?? null;
}
public function storePinHash(int $userId, ?string $hash): void
{
if ($hash === null) {
unset($this->pins[$userId]);
} else {
$this->pins[$userId] = $hash;
}
}
};
$this->secrets->passwords[$this->userId] = 'hashed:Salasana-123!';
$hasher = new class implements SecretHasher
{
public function hash(string $secret): string
{
return 'hashed:'.$secret;
}
public function check(string $secret, string $hash): bool
{
return $hash === 'hashed:'.$secret;
}
};
$this->clock = new FakeClock(new DateTimeImmutable('2027-05-31'));
$this->pins = new LoginPins($this->secrets, $hasher, new CheckLoginAllowed($this->users, $this->clock), new FakeTransactionManager);
});
it('sets a PIN code only with the right password and verifies it', function () {
expect(fn () => $this->pins->set($this->userId, 'väärä', '2468'))->toThrow(WrongPassword::class);
$this->pins->set($this->userId, 'Salasana-123!', '2468');
expect($this->secrets->pins[$this->userId])->toBe('hashed:2468')
->and($this->pins->verify($this->userId, '2468'))->toBeTrue()
->and($this->pins->verify($this->userId, '1111'))->toBeFalse()
->and($this->pins->verify(999, '2468'))->toBeFalse();
});
it('refuses a right PIN code of an intern whose last day has passed', function () {
$internId = $this->users->save(UserAccount::register(new PersonName('Ida'), new EmailAddress('[email protected]'), Role::Intern, new DateTimeImmutable('2027-05-31'), $this->userId))->id();
$this->secrets->passwords[$internId] = 'hashed:Salasana-123!';
$this->pins->set($internId, 'Salasana-123!', '1357');
expect($this->pins->verify($internId, '1357'))->toBeTrue();
$this->clock->today = new DateTimeImmutable('2027-06-01');
expect($this->pins->verify($internId, '1357'))->toBeFalse();
});