50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class Authenticate extends Middleware
|
|
{
|
|
/**
|
|
* Get the path the user should be redirected to when they are not authenticated.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return string|null
|
|
*/
|
|
protected function redirectTo($request)
|
|
{
|
|
// Client qui essaye d'accéder au BO
|
|
if ($request->is('bo', 'bo/*')) {
|
|
if (Auth::guard('customer')->check()) {
|
|
abort(404);
|
|
}
|
|
return route('login');
|
|
}
|
|
|
|
// Admin qui va sur la page de connexion client
|
|
if ($request->is('form-connexion')) {
|
|
if (Auth::check()) {
|
|
return redirect()->route('home');
|
|
}
|
|
}
|
|
|
|
if (! $request->expectsJson()) {
|
|
if ($request->is('bo', 'bo/*')) {
|
|
if (!Auth::check()) {
|
|
Session::put('url.intended', url()->current());
|
|
Session::save();
|
|
return route('form-connexion');
|
|
}
|
|
} else {
|
|
if (!Auth::guard('customer')->check()) {
|
|
Session::put('url.intended', url()->current());
|
|
Session::save();
|
|
return route('form-connexion');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|