55 lignes
Pas d'EOL
2 Kio
PHP
55 lignes
Pas d'EOL
2 Kio
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Http\Utility\routeCollector;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Response;
|
|
|
|
use App\Http\Utility\debug;
|
|
|
|
|
|
class RouteControl extends routeCollector{
|
|
|
|
private function hasGlobalSysAdminRestriction($routeConfig){
|
|
return array_key_exists('globalRestriction',$routeConfig) && in_array('sys_admin',$routeConfig['globalRestriction']);
|
|
}
|
|
|
|
private function hasRouteSysAdminRestriction($routeConfig){
|
|
return array_key_exists('routeRestriction',$routeConfig) && in_array('sys_admin',$routeConfig['routeRestriction']);
|
|
}
|
|
|
|
private function hasGlobalAdminRestriction($routeConfig){
|
|
return array_key_exists('globalRestriction',$routeConfig) && in_array('admin',$routeConfig['globalRestriction']);
|
|
}
|
|
|
|
private function hasRouteAdminRestriction($routeConfig){
|
|
return array_key_exists('routeRestriction',$routeConfig) && in_array('admin',$routeConfig['routeRestriction']);
|
|
}
|
|
|
|
private function userIsAllowed($routeConfig,$user){
|
|
if(
|
|
($this->hasGlobalSysAdminRestriction($routeConfig) && isset($user['isSysAdmin']) && !$user['isSysAdmin']) ||
|
|
($this->hasRouteSysAdminRestriction($routeConfig) && isset($user['isSysAdmin']) && !$user['isSysAdmin']) ||
|
|
($this->hasGlobalAdminRestriction($routeConfig) && isset($user['isAdmin']) && !$user['isAdmin']) ||
|
|
($this->hasRouteAdminRestriction($routeConfig) && isset($user['isAdmin']) && !$user['isAdmin'])
|
|
|
|
)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public function handle($request, Closure $next, $routeMarker){
|
|
$routeConfig=parent::routeConfig($routeMarker);
|
|
if($routeConfig===false){
|
|
debug::consign("Configuration de route erronée, Marker de route : $routeMarker",'ROUTING','ERROR');
|
|
}
|
|
|
|
if($this->userIsAllowed($routeConfig,session('user')))
|
|
return $next($request);
|
|
|
|
abort(403, 'Unauthorized access');
|
|
}
|
|
} |