Merge branch 'master' into dist/envole/6/master

This commit is contained in:
Arnaud Fornerot 2020-07-06 11:54:32 +02:00
commit 5cdd0a6703
2 changed files with 90 additions and 4 deletions

View File

@ -29,6 +29,19 @@ use Cadoles\CoreBundle\Form\UserType;
class RestController extends Controller
{
public function loginAction($key,Request $request)
{
$output=[];
// Vérification de la clé
$realkey = $this->getParameter("apikeyninegate");
if($key!=$realkey) {
$output["error"]="error key";
return new Response(json_encode($output), 400);
}
return new Response(json_encode($output), 200);
}
public function userAction($key, $login, Request $request)
{
@ -66,7 +79,7 @@ class RestController extends Controller
// Construction de la réponse
$output["user"]["firstname"] = $user->getFirstname();
$output["user"]["lasttname"] = $user->getLastname();
$output["user"]["lastname"] = $user->getLastname();
$output["user"]["email"] = $user->getEmail();
$output["user"]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar();
$output["user"]["niveau01"] = $user->getNiveau01()->getLabel();
@ -127,10 +140,71 @@ class RestController extends Controller
}
}
// Retour
return new Response(json_encode($output), 200);
}
public function usersAction($key, Request $request)
{
// Vérification de la clé
$realkey = $this->getParameter("apikeyninegate");
if($key!=$realkey) {
$output["error"]="error key";
return new Response(json_encode($output), 400);
}
$weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/";
$em = $this->getDoctrine()->getManager();
$output = [];
$users=$em->getRepository('CadolesCoreBundle:User')->findAll();
foreach($users as $user) {
// Construction de la réponse
$output[$user->getId()]["id"] = $user->getId();
$output[$user->getId()]["username"] = $user->getUsername();
$output[$user->getId()]["firstname"] = $user->getFirstname();
$output[$user->getId()]["lastname"] = $user->getLastname();
$output[$user->getId()]["email"] = $user->getEmail();
$output[$user->getId()]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar();
$output[$user->getId()]["role"] = $user->getRole();
}
// Retour
return new Response(json_encode($output), 200);
}
public function groupsAction($key, Request $request)
{
// Vérification de la clé
$realkey = $this->getParameter("apikeyninegate");
if($key!=$realkey) {
$output["error"]="error key";
return new Response(json_encode($output), 400);
}
$em = $this->getDoctrine()->getManager();
$output = [];
$groups=$em->getRepository('CadolesCoreBundle:Group')->findAll();
foreach($groups as $group) {
// Construction de la réponse
$output[$group->getId()]["id"] = $group->getId();
$output[$group->getId()]["name"] = $group->getLabel();
$output[$group->getId()]["users"] = [];
$usergroups=$group->getUsers();
foreach($usergroups as $usergroup) {
$user=$usergroup->getUser();
$output[$group->getId()]["users"][$user->getId()]["id"]=$user->getId();
$output[$group->getId()]["users"][$user->getId()]["username"]=$user->getUsername();
}
}
// Retour
return new Response(json_encode($output), 200);
}
}

View File

@ -492,6 +492,18 @@ cadoles_core_config_statistic:
defaults: { _controller: CadolesCoreBundle:Statistic:list }
#== REST ==================================================================================================================
cadoles_core_rest_login:
path: /rest/login/{key}
defaults: { _controller: CadolesCoreBundle:Rest:login }
cadoles_core_rest_user:
path: /rest/user/{key}/{login}
defaults: { _controller: CadolesCoreBundle:Rest:user }
defaults: { _controller: CadolesCoreBundle:Rest:user }
cadoles_core_rest_users:
path: /rest/users/{key}
defaults: { _controller: CadolesCoreBundle:Rest:users }
cadoles_core_rest_groups:
path: /rest/groups/{key}
defaults: { _controller: CadolesCoreBundle:Rest:groups }