Commit 344fc7b0 authored by thibaut-felten's avatar thibaut-felten

Doc + Security

parent b7301862
...@@ -47,14 +47,22 @@ class UserController extends Controller { ...@@ -47,14 +47,22 @@ class UserController extends Controller {
protected function getUser($id) protected function getUser($id)
{ {
$user = User::getUserById($id); $user = User::getUserById($id);
if($user == Array()){
$response = new Response(200,json_encode($user)); $response = Response::errorInParametersResponse("User not found");
}else{
$response = new Response(200,json_encode($user));
}
return $response; return $response;
} }
protected function deleteUser($id){ protected function deleteUser($id){
User::deleteUser($id); $user = User::getUserById($id);
$response = Response::okResponse("User deleted"); if($user == Array()){
$response = Response::errorInParametersResponse("User not found");
}else{
User::deleteUser($id);
$response = Response::okResponse("User deleted");
}
return $response; return $response;
} }
...@@ -113,8 +121,13 @@ class UserController extends Controller { ...@@ -113,8 +121,13 @@ class UserController extends Controller {
protected function createUser($data) protected function createUser($data)
{ {
$user = User::createUser(array( "login" => $data['USER_LOGIN'], "password" => $data['USER_PASSWORD'], "role" => $data['USER_ROLE'], "email" => $data['USER_EMAIL'],"lastname" => $data['USER_LASTNAME'],"firstname" => $data['USER_FIRSTNAME'])); if(array_key_exists("USER_LOGIN", $data) && array_key_exists("USER_PASSWORD", $data) && array_key_exists("USER_ROLE", $data) && array_key_exists("USER_EMAIL", $data) && array_key_exists("USER_LASTNAME", $data) && array_key_exists("USER_FIRSTNAME", $data)){
$response = new Response(200,json_encode($user)); $user = User::createUser(array( "login" => $data['USER_LOGIN'], "password" => $data['USER_PASSWORD'], "role" => $data['USER_ROLE'], "email" => $data['USER_EMAIL'],"lastname" => $data['USER_LASTNAME'],"firstname" => $data['USER_FIRSTNAME']));
$response = new Response(200,json_encode($user));
}else{
$response = Response::errorInParametersResponse("Parameters missing");
}
return $response; return $response;
} }
} }
...@@ -16,3 +16,13 @@ Used to delete a user account. ...@@ -16,3 +16,13 @@ Used to delete a user account.
**Content example** **Content example**
`"User deleted"` `"User deleted"`
## Error Response
### Mauvais id
**Code** : `400 Bad Request`
**Content example**
`"User not found"`
...@@ -26,3 +26,13 @@ Used to retrieve the information of one user ...@@ -26,3 +26,13 @@ Used to retrieve the information of one user
"USER_ROLE": "1" "USER_ROLE": "1"
} }
``` ```
## Error Response
### Mauvais identifiant
**Code** : `400 Bad Request`
**Content example**
`"User not found"`
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment