2FAuth/app/Http/Middleware/Authenticate.php

52 lines
1.5 KiB
PHP
Raw Normal View History

2019-05-20 07:37:41 +02:00
<?php
namespace App\Http\Middleware;
use Illuminate\Support\Facades\App;
2019-05-20 07:37:41 +02:00
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Determine if the user is logged in to any of the given guards.
*
* @param \Illuminate\Http\Request $request
* @param array $guards
* @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
$proxyGuard = 'reverse-proxy-guard';
if (config('auth.defaults.guard') === $proxyGuard) {
$guards = [$proxyGuard];
}
}
foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
$this->auth->shouldUse($guard);
2022-11-22 15:15:52 +01:00
// We now have an authenticated user so we override the locale already set
// by the SetLanguage global middleware
$lang = $this->auth->guard()->user()->preferences['lang'] ?? null;
if ($lang && in_array($lang, config('2fauth.locales')) && !App::isLocale($lang)) {
App::setLocale($lang);
}
return;
}
}
$this->unauthenticated($request, $guards);
}
2022-11-22 15:15:52 +01:00
}