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]>
66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?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);
|
|
}
|
|
}
|