Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 9s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 12s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 11s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make-Without-sqlite3 (push) Successful in 9s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake-Without-sqlite3 (push) Successful in 14s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson-Without-sqlite3 (push) Successful in 12s
29 lines
981 B
C
29 lines
981 B
C
#include "security/jwt.h"
|
|
#include "user.h"
|
|
#include "utils/utils.h"
|
|
|
|
void get_all_users(struct mg_connection *c, struct mg_http_message *hm) {
|
|
request_with_token *data = check_body(hm);
|
|
if (data->error != NULL) {
|
|
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
|
MG_ESC(data->error));
|
|
return;
|
|
}
|
|
if (!jwt_verifyJWT(data->token, JWT_DEFAULT_SECRET)) {
|
|
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
|
MG_ESC("invalid token"));
|
|
return;
|
|
}
|
|
cJSON *payload = jwt_get_payload(data->token);
|
|
bool is_superuser = cJSON_GetObjectItem(payload, "is_superuser")->valueint;
|
|
if (!is_superuser) {
|
|
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
|
MG_ESC("user is not superuser"));
|
|
return;
|
|
}
|
|
char *all_users = db_get_all_users();
|
|
mg_http_reply(c, 200, "Content-type: application/json\r\n", all_users);
|
|
free(all_users);
|
|
free_request_with_token(data);
|
|
}
|