ldc-legaulois/app/Http/Middleware/Authenticate.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2020-07-23 10:29:36 +02:00
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Support\Facades\Auth;
2021-03-08 11:24:20 +01:00
use Illuminate\Support\Facades\Session;
2020-07-23 10:29:36 +02:00
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
2022-02-10 16:14:58 +01:00
* @param \Illuminate\Http\Request $request
2020-07-23 10:29:36 +02:00
* @return string|null
*/
protected function redirectTo($request)
{
// Client qui essaye d'accéder au BO
if ($request->is('bo', 'bo/*')) {
2021-03-19 21:40:10 +01:00
if (Auth::guard('customer')->check()) {
abort(404);
2021-03-19 21:40:10 +01:00
}
2020-07-23 10:29:36 +02:00
return route('login');
}
// Admin qui va sur la page de connexion client
if ($request->is('form-connexion')) {
2021-03-19 21:40:10 +01:00
if (Auth::check()) {
return redirect()->route('home');
2021-03-19 21:40:10 +01:00
}
}
if (! $request->expectsJson()) {
2021-03-08 11:24:20 +01:00
if ($request->is('bo', 'bo/*')) {
if (!Auth::check()) {
Session::put('url.intended', url()->current());
Session::save();
return route('form-connexion');
2021-03-08 11:24:20 +01:00
}
} else {
if (!Auth::guard('customer')->check()) {
Session::put('url.intended', url()->current());
Session::save();
return route('form-connexion');
}
}
}
2020-07-23 10:29:36 +02:00
}
}