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,18 @@
|
||||
#include "user.h"
|
||||
#include "jwt.h"
|
||||
#include "utils.h"
|
||||
|
||||
void verify_token(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
const request_with_token *data = check_body(hm);
|
||||
if (data->error != nullptr) {
|
||||
mg_http_reply(c, 403, "", "{%m:%m}", MG_ESC("error"), MG_ESC(data->error));
|
||||
return;
|
||||
}
|
||||
const bool valid = jwt_verifyJWT(data->token, JWT_DEFAULT_SECRET);
|
||||
if (!valid) {
|
||||
mg_http_reply(c, 403, "", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("invalid token"));
|
||||
return;
|
||||
}
|
||||
mg_http_reply(c, 200, "", "{%m:%m}", MG_ESC("valid"), MG_ESC("true"));
|
||||
}
|
||||
Reference in new issue
Block a user