hot fix
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 14s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 13s
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 14s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 13s
This commit is contained in:
+5
-6
@@ -3,39 +3,38 @@
|
||||
#include "utils.h"
|
||||
|
||||
void verify_token(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
const request_with_token *data = check_body(hm);
|
||||
request_with_token *data = check_body(hm);
|
||||
if (data->error != nullptr) {
|
||||
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC(data->error));
|
||||
free_request_with_token((request_with_token *) data);
|
||||
return;
|
||||
}
|
||||
const bool valid = jwt_verifyJWT(data->token, JWT_DEFAULT_SECRET);
|
||||
if (!valid) {
|
||||
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("invalid token"));
|
||||
free_request_with_token((request_with_token *) data);
|
||||
free_request_with_token(data);
|
||||
return;
|
||||
}
|
||||
cJSON *payload = jwt_get_payload(data->token);
|
||||
char *username =
|
||||
strdup(cJSON_GetObjectItem(payload, "username")->valuestring);
|
||||
if (!username) {
|
||||
free_request_with_token((request_with_token *) data);
|
||||
free_request_with_token(data);
|
||||
cJSON_Delete(payload);
|
||||
mg_http_reply(c, 500, HTTP_HEADERS, "{%m:false}", MG_ESC("valid"));
|
||||
return;
|
||||
}
|
||||
User *user = db_get_user_by_username(username);
|
||||
if (!user) {
|
||||
free_request_with_token((request_with_token *) data);
|
||||
free_request_with_token(data);
|
||||
cJSON_Delete(payload);
|
||||
free(username);
|
||||
mg_http_reply(c, 404, HTTP_HEADERS, "{%m:false}", MG_ESC("valid"));
|
||||
return;
|
||||
}
|
||||
mg_http_reply(c, 200, HTTP_HEADERS, "{%m:true}", MG_ESC("valid"));
|
||||
free_request_with_token((request_with_token *) data);
|
||||
free_request_with_token(data);
|
||||
free(username);
|
||||
free_user(user);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user