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:
1 parent
1d616c3841
commit
fbc5ba375d
1 file changed
+5
-6
+5
-6
@@ -3,39 +3,38 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
void verify_token(struct mg_connection *c, struct mg_http_message *hm) {
|
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) {
|
if (data->error != nullptr) {
|
||||||
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
||||||
MG_ESC(data->error));
|
MG_ESC(data->error));
|
||||||
free_request_with_token((request_with_token *) data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const bool valid = jwt_verifyJWT(data->token, JWT_DEFAULT_SECRET);
|
const bool valid = jwt_verifyJWT(data->token, JWT_DEFAULT_SECRET);
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
mg_http_reply(c, 403, HTTP_HEADERS, "{%m:%m}", MG_ESC("error"),
|
||||||
MG_ESC("invalid token"));
|
MG_ESC("invalid token"));
|
||||||
free_request_with_token((request_with_token *) data);
|
free_request_with_token(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cJSON *payload = jwt_get_payload(data->token);
|
cJSON *payload = jwt_get_payload(data->token);
|
||||||
char *username =
|
char *username =
|
||||||
strdup(cJSON_GetObjectItem(payload, "username")->valuestring);
|
strdup(cJSON_GetObjectItem(payload, "username")->valuestring);
|
||||||
if (!username) {
|
if (!username) {
|
||||||
free_request_with_token((request_with_token *) data);
|
free_request_with_token(data);
|
||||||
cJSON_Delete(payload);
|
cJSON_Delete(payload);
|
||||||
mg_http_reply(c, 500, HTTP_HEADERS, "{%m:false}", MG_ESC("valid"));
|
mg_http_reply(c, 500, HTTP_HEADERS, "{%m:false}", MG_ESC("valid"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
User *user = db_get_user_by_username(username);
|
User *user = db_get_user_by_username(username);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
free_request_with_token((request_with_token *) data);
|
free_request_with_token(data);
|
||||||
cJSON_Delete(payload);
|
cJSON_Delete(payload);
|
||||||
free(username);
|
free(username);
|
||||||
mg_http_reply(c, 404, HTTP_HEADERS, "{%m:false}", MG_ESC("valid"));
|
mg_http_reply(c, 404, HTTP_HEADERS, "{%m:false}", MG_ESC("valid"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mg_http_reply(c, 200, HTTP_HEADERS, "{%m:true}", MG_ESC("valid"));
|
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(username);
|
||||||
free_user(user);
|
free_user(user);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user