Commit 5f9b4bc7 authored by Zohten's avatar Zohten

more comments

parent ac16a6ca
......@@ -22,14 +22,17 @@ class UserController extends Controller
$httpMethod=$this->request->getHttpMethod();
$uriParams=$this->request->getUriParams();
switch($httpMethod) {
switch ($httpMethod) {
case 'GET':
// If there is a uriParams, it is the /user/{id} endpoint
if ($uriParams) {
return $this->getUser($uriParams[0]);
}
// Else, it is the /user endpoint
return $this->getAllUsers();
break;
case 'PUT':
// If there is a uriParams, it is the /user/{id} endpoint
if ($uriParams) {
$body = $this->request->getData();
return $this->updateUser(array_merge($body, ['id'=>$uriParams[0]]));
......@@ -71,6 +74,7 @@ class UserController extends Controller
*/
protected function updateUser($array)
{
// Token phase
try {
$jwt_token = $this->request->getJwtToken();
$decodedJWT = JWT::decode($jwt_token, JWT_BACKEND_KEY, array('HS256'));
......@@ -84,10 +88,13 @@ class UserController extends Controller
return Response::unauthorizedResponse($jsonResult);
}
// Auth phase
if ($decodedJWT->data->id != $array['id']) {
$message = json_encode(["message" => "You don't have access to this account."]);
return Response::unauthorizedResponse($message);
}
// Update phase
User::updateUser($array);
$message = json_encode(["message" => 'User succesfully updated !']);
......
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