Files
Toiminnanohjaus/app/Modules/Users/Presentation/Http/Middleware/EnsureAccountIsUsable.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

45 lines
1.5 KiB
PHP

<?php
namespace App\Modules\Users\Presentation\Http\Middleware;
use App\Models\User;
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
/**
* Ends the session of a signed-in user who has been deactivated or whose
* internship has ended since they signed in.
*/
class EnsureAccountIsUsable
{
public function __construct(private CheckLoginAllowed $checkLoginAllowed) {}
public function handle(Request $request, Closure $next): Response
{
$userId = Auth::id();
if ($userId !== null && ! $this->checkLoginAllowed->execute((int) $userId)) {
$user = $request->user();
$locale = $user instanceof User ? $user->locale->value : null;
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
// The login page explains why, in the language the user had chosen.
if ($locale !== null) {
$request->session()->put(SetLocale::SESSION_KEY, $locale);
}
// The reason goes in the URL: Livewire follows this redirect with
// fetch first, which would consume a flashed message.
return redirect()->route(UseConsoleSession::isConsole($request) ? 'console.login' : 'login', ['access' => 'ended']);
}
return $next($request);
}
}