added endpoints end refactor
This commit is contained in:
1 parent
22dc118616
commit
c4ea7a4293
15 files changed
+333
-87
No files matched your search
@@ -0,0 +1,36 @@
|
||||
#include "user.h"
|
||||
#include "jwt.h"
|
||||
#include "utils.h"
|
||||
|
||||
void get_user(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
request_with_token *requestdata = check_body(hm);
|
||||
const bool valid = jwt_verifyJWT(requestdata->token, JWT_DEFAULT_SECRET);
|
||||
if (!valid) {
|
||||
mg_http_reply(c, 403, "", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("invalid token"));
|
||||
return;
|
||||
}
|
||||
const User *user = new_user("username", "", "mail@example.com", "root", true);
|
||||
if (user == NULL) {
|
||||
mg_http_reply(c, 404, "", "{%m:%m}", MG_ESC("error"), MG_ESC("user not found"));
|
||||
return;
|
||||
}
|
||||
char responsedata[2048] = {0};
|
||||
snprintf(
|
||||
responsedata,
|
||||
sizeof(responsedata),
|
||||
"{\"id\": %d, \"username\": \"%s\", \"email\": \"%s\", \"group\": \"%s\", \"is_superuser\": %s}",
|
||||
user->id,
|
||||
user->username,
|
||||
user->email,
|
||||
user->group,
|
||||
user->is_superuser ? "true" : "false"
|
||||
);
|
||||
|
||||
mg_http_reply(
|
||||
c,
|
||||
200,
|
||||
"Content-Type: application/json\r\n",
|
||||
responsedata
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user