A language picked on a signed-out page is now stored on the account when the user signs in (StoreLocaleChosenBeforeLogin), so the app does not switch back to the account default. EnsureAccountIsUsable keeps the user's language for the login page when it ends a disabled account's session. ChangePreferredLocale runs in a transaction like the other use cases, the language names come from layout.languages instead of the Locale enum, and the translation test also compares fi.json with en.json and rejects English files without a Finnish counterpart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
45 lines
1.4 KiB
PHP
45 lines
1.4 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('login', ['access' => 'ended']);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|