Commit 0aaf1c25 authored by Zohten's avatar Zohten

added code getter for responses

parent 92de9aa7
......@@ -69,4 +69,8 @@ class Response
echo $this->body;
exit; // do we keep that?
}
public function getCode(){
return $this->code;
}
}
......@@ -38,11 +38,18 @@ class UserController extends Controller
return Response::errorResponse($message);
}
public function authUser($id, $allowAdmin=True){
/**
* Authentificate a user if he has the same id as the one in token, bypassed by admin
*
* @param int $id id of the User
* @return Response
*/
public function authUser($id){
// Token phase
$verifyArray = $this->request->verifyJwtToken();
if ($verifyArray['message']!=="Valid token.") {
return Response::unauthorizedResponse($jsonResult);
$message = json_encode($verifyArray['error']);
return Response::unauthorizedResponse($message);
}
// Auth phase
$data = $verifyArray['decodedJWT']->data;
......@@ -50,10 +57,13 @@ class UserController extends Controller
$message = json_encode(["message" => "You don't have access to this account."]);
return Response::unauthorizedResponse($message);
}
$message = json_encode(["message" => "Authentified."]);
return Response::okResponse($message);
}
/**
* Get all users in USER table
* GET all users in USER table
*
* @return Response
*/
......@@ -65,8 +75,9 @@ class UserController extends Controller
}
/**
* Get a specific user in USER table based on id
* GET a specific user in USER table based on id
*
* @param int $id id of the User
* @return Response
*/
protected function getUser($id)
......@@ -79,15 +90,16 @@ class UserController extends Controller
/**
* Update a specific user in USER table based on id
*
* @param array $array array containing id + fields to modify
* @return Response
*/
protected function updateUser($array)
{
// Auth with token phase
$authError = $this->authUser($array['id']);
if($authError){
if($this->authUser($array['id'])->getCode()!=200){
return authError;
}
// Update phase
User::updateUser($array);
......
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