fix role_admin route edispatcher/test
This commit is contained in:
parent
f974047a61
commit
81520d0d7d
|
@ -69,16 +69,28 @@ class ApiController extends Controller
|
|||
// Récupération UID
|
||||
$username = \phpCAS::getUser();
|
||||
$attributes = \phpCAS::getAttributes();
|
||||
|
||||
return $this->render('CadolesEdispatcherBundle:Test:test.html.twig',[
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'attributes' => $attributes,
|
||||
'groups' => $groups,
|
||||
'username' => $username,
|
||||
'datasource' => $datasource,
|
||||
]);
|
||||
if(isset($attributes[$this->getParameter('user_attr_cas_username')]))
|
||||
$login = $attributes[$this->getParameter('user_attr_cas_username')];
|
||||
$user=$em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$login]);
|
||||
if(!$user) {
|
||||
$output["error"]="user does not exist";
|
||||
return new Response(json_encode($output), 400);
|
||||
}
|
||||
$roles=($user?$user->getRoles():["ROLE_ANONYME"]);
|
||||
if (in_array("ROLE_ADMIN",$roles)) {
|
||||
return $this->render('CadolesEdispatcherBundle:Test:test.html.twig',[
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'attributes' => $attributes,
|
||||
'groups' => $groups,
|
||||
'username' => $username,
|
||||
'datasource' => $datasource,
|
||||
]);
|
||||
} else {
|
||||
$output["error"]="access not granted";
|
||||
return new Response(json_encode($output), 403);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue