Authenticate.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Illuminate\Auth\Middleware\Authenticate as Middleware;
  4. use Illuminate\Support\Facades\App;
  5. class Authenticate extends Middleware
  6. {
  7. /**
  8. * Determine if the user is logged in to any of the given guards.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @param array $guards
  12. * @return void
  13. *
  14. * @throws \Illuminate\Auth\AuthenticationException
  15. */
  16. protected function authenticate($request, array $guards)
  17. {
  18. if (empty($guards)) {
  19. // Will retreive the default guard
  20. $guards = [null];
  21. } else {
  22. // We replace routes guard by the reverse proxy guard if necessary
  23. $proxyGuard = 'reverse-proxy-guard';
  24. if (config('auth.defaults.guard') === $proxyGuard) {
  25. $guards = [$proxyGuard];
  26. }
  27. }
  28. foreach ($guards as $guard) {
  29. if ($this->auth->guard($guard)->check()) {
  30. $this->auth->shouldUse($guard);
  31. // We now have an authenticated user so we override the locale already set
  32. // by the SetLanguage global middleware
  33. $lang = $this->auth->guard()->user()->preferences['lang'];
  34. if (in_array($lang, config('2fauth.locales')) && ! App::isLocale($lang)) {
  35. App::setLocale($lang);
  36. }
  37. return;
  38. }
  39. }
  40. $this->unauthenticated($request, $guards);
  41. }
  42. }