mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-16 16:12:14 +11:00
🚚 moved CORS back
This commit is contained in:
parent
244852eb45
commit
85ee2167ff
3 changed files with 13 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <drogon/HttpController.h>
|
||||
#include "accept_filter.h"
|
||||
#include "admin_filter.h"
|
||||
#include "user_filter.h"
|
||||
|
||||
|
|
@ -46,13 +47,13 @@ public:
|
|||
#else
|
||||
METHOD_ADD(api::GetLog, "/v1/user/log", Get, Options);
|
||||
#endif
|
||||
METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "UserFilter"); //expects ["to"](string) and ["amount"](32 bits)
|
||||
METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "AcceptFilter", "UserFilter"); //expects ["to"](string) and ["amount"](32 bits)
|
||||
METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Get, Options, "UserFilter");
|
||||
|
||||
//Meta Usage
|
||||
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "UserFilter"); //expects ["new_pass"](string)
|
||||
METHOD_ADD(api::AdminChangePassword, "/v1/user/change_password", Patch, Options, "AdminFilter"); //expects ["name"](string) and ["new_pass"](string)
|
||||
METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "AdminFilter"); //expects ["name"](string) and ["amount"](32 bits)
|
||||
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "AcceptFilter", "UserFilter"); //expects ["new_pass"](string)
|
||||
METHOD_ADD(api::AdminChangePassword, "/v1/user/change_password", Patch, Options, "AcceptFilter", "AdminFilter"); //expects ["name"](string) and ["new_pass"](string)
|
||||
METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "AcceptFilter", "AdminFilter"); //expects ["name"](string) and ["amount"](32 bits)
|
||||
|
||||
//System Usage
|
||||
METHOD_ADD(api::Help, "/v1/help", Get, Options);
|
||||
|
|
@ -62,10 +63,10 @@ public:
|
|||
METHOD_ADD(api::AdminVerifyAccount, "/v1/admin/verify_account", Get, Options, "AdminFilter");
|
||||
|
||||
//User Managment
|
||||
METHOD_ADD(api::AddUser, "/v1/user/register", Post, Options); //expects ["name"](string) ["pass"](string)
|
||||
METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "AdminFilter"); //expects ["name"](string) ["balance"](32 bits) ["pass"](string)
|
||||
METHOD_ADD(api::AddUser, "/v1/user/register", Post, Options, "AcceptFilter"); //expects ["name"](string) ["pass"](string)
|
||||
METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "AcceptFilter", "AdminFilter"); //expects ["name"](string) ["balance"](32 bits) ["pass"](string)
|
||||
METHOD_ADD(api::DelUser, "/v1/delete", Delete, Options, "UserFilter");
|
||||
METHOD_ADD(api::AdminDelUser, "/v1/admin/delete", Delete, Options, "AdminFilter"); //expects ["name"](string)
|
||||
METHOD_ADD(api::AdminDelUser, "/v1/admin/delete", Delete, Options, "AcceptFilter", "AdminFilter"); //expects ["name"](string)
|
||||
#endif
|
||||
METHOD_ADD(api::ApiVersion, "/version");
|
||||
|
||||
|
|
|
|||
6
main.cpp
6
main.cpp
|
|
@ -100,7 +100,11 @@ int main(int argc, char **argv)
|
|||
auto API = std::make_shared<api>(bank);
|
||||
auto user_filter = std::make_shared<UserFilter>(bank);
|
||||
auto admin_filter = std::make_shared<AdminFilter>(bank);
|
||||
|
||||
auto accept_filter = std::make_shared<AcceptFilter>();
|
||||
app().registerPostHandlingAdvice(
|
||||
[](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) {
|
||||
resp->addHeader("Access-Control-Allow-Origin", "*"); //CORS
|
||||
});
|
||||
app()
|
||||
.loadConfigFile(config_location)
|
||||
.registerFilter(user_filter)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#include "bank_api.h"
|
||||
|
||||
#define CACHE_FOREVER resp->setExpiredTime(0)
|
||||
|
||||
#define CORS resp->addHeader("Access-Control-Allow-Origin", "*")
|
||||
#define GEN_BODY \
|
||||
const auto temp_req = req->getJsonObject(); \
|
||||
const auto body = temp_req ? *temp_req : Json::Value();
|
||||
|
|
@ -99,7 +97,6 @@ void api::Help(req_args) const
|
|||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody(""); //will be filled in with docs
|
||||
CORS;
|
||||
CACHE_FOREVER;
|
||||
callback(resp);
|
||||
}
|
||||
|
|
@ -107,7 +104,6 @@ void api::Ping(req_args) const
|
|||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("pong");
|
||||
CORS;
|
||||
CACHE_FOREVER;
|
||||
callback(resp);
|
||||
}
|
||||
|
|
@ -121,7 +117,6 @@ void api::Contains(req_args, const std::string &name) const
|
|||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(bank.Contains(name)));
|
||||
resp->setStatusCode(k200OK);
|
||||
CORS;
|
||||
callback(resp);
|
||||
}
|
||||
void api::AdminVerifyAccount(req_args) const
|
||||
|
|
@ -132,7 +127,6 @@ void api::ApiVersion(req_args) const
|
|||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(API_VERSION);
|
||||
resp->setStatusCode(k200OK);
|
||||
CORS;
|
||||
CACHE_FOREVER;
|
||||
callback(resp);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue