2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
2023-02-25 21:12:10 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
|
|
|
class Authenticate extends Middleware
|
|
|
|
{
|
2022-03-24 14:58:30 +01:00
|
|
|
/**
|
|
|
|
* Determine if the user is logged in to any of the given guards.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\AuthenticationException
|
|
|
|
*/
|
|
|
|
protected function authenticate($request, array $guards)
|
|
|
|
{
|
|
|
|
if (empty($guards)) {
|
|
|
|
// Will retreive the default guard
|
|
|
|
$guards = [null];
|
2022-11-22 15:15:52 +01:00
|
|
|
} else {
|
|
|
|
// We replace routes guard by the reverse proxy guard if necessary
|
2022-03-24 14:58:30 +01:00
|
|
|
$proxyGuard = 'reverse-proxy-guard';
|
2022-03-19 00:14:20 +01:00
|
|
|
|
2022-05-19 15:50:06 +02:00
|
|
|
if (config('auth.defaults.guard') === $proxyGuard) {
|
|
|
|
$guards = [$proxyGuard];
|
2022-03-24 14:58:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($guards as $guard) {
|
|
|
|
if ($this->auth->guard($guard)->check()) {
|
2022-09-07 17:54:27 +02:00
|
|
|
$this->auth->shouldUse($guard);
|
2022-11-22 15:15:52 +01:00
|
|
|
|
2023-02-17 17:12:53 +01:00
|
|
|
// We now have an authenticated user so we override the locale already set
|
|
|
|
// by the SetLanguage global middleware
|
2023-03-15 11:46:37 +01:00
|
|
|
$lang = $this->auth->guard()->user()->preferences['lang'];
|
2023-02-17 17:12:53 +01:00
|
|
|
|
2023-03-15 11:46:37 +01:00
|
|
|
if (in_array($lang, config('2fauth.locales')) && ! App::isLocale($lang)) {
|
2023-02-17 17:12:53 +01:00
|
|
|
App::setLocale($lang);
|
|
|
|
}
|
|
|
|
|
2022-09-07 17:54:27 +02:00
|
|
|
return;
|
2022-03-24 14:58:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->unauthenticated($request, $guards);
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|