bug delete user + /user/info

pull/3/head
remrem 1 year ago
parent 1024741b24
commit 1680f84a4e

@ -39,14 +39,16 @@ class UserGateway {
// Delete User: (1:OK, 2:Unauthorize, 3:No User)
public function deleteUser(string $uuid) : int {
$query = "DELETE FROM user WHERE id=:uuid;";
$query = "DELETE FROM user WHERE id=:uuid RETURNING row_count();";
try {
$this->con->executeQuery($query, array(
':uuid' => array($uuid, PDO::PARAM_STR)
));
$results = $this->con->getResults();
} catch (PDOException $e) {
return -1;
return -2;
}
if(count($results) === 0) return -1;
return 0;
}
@ -69,6 +71,21 @@ class UserGateway {
return json_encode($this->token->getNewJsonToken($results[0]['id']));
}
public function getInfo(string $uuid) {
$query = "SELECT email, username FROM user WHERE id=:uuid;";
try {
$this->con->executeQuery($query,array(
':uuid' => array($uuid, PDO::PARAM_STR)
));
$results = $this->con->getResults();
} catch(PDOException $e) {
return -2;
}
if(count($results) === 0) return -1;
return ["email" => $results[0]['email'], "username" => $results[0]['username']];
}
public function updateMail(string $uuid, string $new_email) {
$query = "UPDATE user SET email=:new_email WHERE id=:uuid;";
try {

@ -50,6 +50,8 @@ return function (App $app) {
return $res->withStatus(200);
case -1:
return $res->withStatus(404);
case -2:
return $res->withStatus(500);
}
return $res->withStatus(500);
});
@ -73,6 +75,25 @@ return function (App $app) {
return $res;
});
$app->get('/user/info', function(Request $req, Response $res) {
$token = $req->getHeader('Authorization')[0];
if(!(new Token)->verifyToken($token)) {
return $res->withStatus(401);
}
$uuid = (new Token)->getUuidFromToken($token);
$code = (new UserGateway)->getInfo($uuid);
switch($code) {
case -1:
return $res->withStatus(404);
case -2:
return $res->withStatus(500);
}
$res->getBody()->write(json_encode($code));
return $res;
});
// Update Mail
$app->put('/user/email', function(Request $req, Response $res) {
$token = $req->getHeader('Authorization')[0];

Loading…
Cancel
Save