2020-07-23 10:29:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
2020-12-10 12:13:33 +01:00
|
|
|
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)
|
|
|
|
|
{
|
2020-12-10 12:13:33 +01:00
|
|
|
// 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()) {
|
2020-12-10 12:13:33 +01:00
|
|
|
abort(404);
|
2021-03-19 21:40:10 +01:00
|
|
|
}
|
2020-07-23 10:29:36 +02:00
|
|
|
return route('login');
|
|
|
|
|
}
|
2020-12-10 12:13:33 +01:00
|
|
|
|
|
|
|
|
// Admin qui va sur la page de connexion client
|
2021-04-29 08:55:30 +02:00
|
|
|
if ($request->is('form-connexion')) {
|
2021-03-19 21:40:10 +01:00
|
|
|
if (Auth::check()) {
|
2020-12-10 12:13:33 +01:00
|
|
|
return redirect()->route('home');
|
2021-03-19 21:40:10 +01:00
|
|
|
}
|
2020-12-10 12:13:33 +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();
|
2021-04-29 08:55:30 +02:00
|
|
|
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-12-10 12:13:33 +01:00
|
|
|
}
|
2020-07-23 10:29:36 +02:00
|
|
|
}
|
|
|
|
|
}
|