mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 08:32:13 +11:00
🐛🐎 noexcept and fixed DelUser
This commit is contained in:
parent
7c0b4f48bd
commit
b90552d0d4
1 changed files with 29 additions and 30 deletions
|
|
@ -1,21 +1,24 @@
|
||||||
#include "bank_api.h"
|
#include "bank_api.h"
|
||||||
|
|
||||||
|
#define CACHE_FOREVER resp->setExpiredTime(0)
|
||||||
|
|
||||||
|
#define CORS resp->addHeader("Access-Control-Allow-Origin", "*")
|
||||||
#define GEN_BODY \
|
#define GEN_BODY \
|
||||||
const auto temp_req = req->getJsonObject(); \
|
const auto temp_req = req->getJsonObject(); \
|
||||||
const auto body = temp_req ? *temp_req : Json::Value();
|
const auto body = temp_req ? *temp_req : Json::Value();
|
||||||
|
|
||||||
#define RESPONSE_PARSE(R) \
|
#define RESPONSE_PARSE(R) \
|
||||||
const auto r = R; \
|
const auto r(R); \
|
||||||
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(std::move(r.second))); \
|
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(std::move(r.second))); \
|
||||||
resp->setStatusCode(r.first); \
|
resp->setStatusCode(r.first); \
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*"); \
|
CORS; \
|
||||||
callback(resp);
|
callback(resp);
|
||||||
|
|
||||||
#define RESPOND_TRUE \
|
#define RESPOND_TRUE \
|
||||||
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(true)); \
|
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(true)); \
|
||||||
resp->setStatusCode(k200OK); \
|
resp->setStatusCode(k200OK); \
|
||||||
resp->setExpiredTime(0); \
|
CACHE_FOREVER; \
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*"); \
|
CORS; \
|
||||||
callback(resp);
|
callback(resp);
|
||||||
|
|
||||||
#define NAME_PARAM req->getBody().data()
|
#define NAME_PARAM req->getBody().data()
|
||||||
|
|
@ -41,18 +44,16 @@ constexpr Json::Value JsonCast(T &&val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api::api(Bank &b) : bank(b)
|
api::api(Bank &b) noexcept : bank(b) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#if API_VERSION >= 1
|
#if API_VERSION >= 1
|
||||||
|
|
||||||
//Usage
|
//Usage
|
||||||
void api::GetBal(req_args, const std::string &name) const
|
void api::GetBal(req_args, const std::string &name) const noexcept
|
||||||
{
|
{
|
||||||
RESPONSE_PARSE(bank.GetBal(name));
|
RESPONSE_PARSE(bank.GetBal(name));
|
||||||
}
|
}
|
||||||
void api::GetLog(req_args)
|
void api::GetLog(req_args) noexcept
|
||||||
{
|
{
|
||||||
if constexpr (MAX_LOG_SIZE > 0)
|
if constexpr (MAX_LOG_SIZE > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -62,8 +63,8 @@ void api::GetLog(req_args)
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpJsonResponse("Logs are Disabled");
|
auto resp = HttpResponse::newHttpJsonResponse("Logs are Disabled");
|
||||||
resp->setStatusCode(k404NotFound);
|
resp->setStatusCode(k404NotFound);
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
CORS;
|
||||||
resp->setExpiredTime(0); //cached forever
|
CACHE_FOREVER;
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -72,17 +73,14 @@ void api::SendFunds(req_args) const
|
||||||
GEN_BODY
|
GEN_BODY
|
||||||
RESPONSE_PARSE(bank.SendFunds(NAME_PARAM, body["to"].asCString(), body["amount"].asUInt()));
|
RESPONSE_PARSE(bank.SendFunds(NAME_PARAM, body["to"].asCString(), body["amount"].asUInt()));
|
||||||
}
|
}
|
||||||
void api::VerifyPassword(req_args) const
|
void api::VerifyPassword(req_args) const noexcept { RESPOND_TRUE }
|
||||||
{
|
|
||||||
RESPOND_TRUE //as we know the user exists and is verified
|
|
||||||
}
|
|
||||||
|
|
||||||
//Meta Usage
|
//Meta Usage
|
||||||
void api::ChangePassword(req_args) const
|
void api::ChangePassword(req_args) const
|
||||||
{
|
{
|
||||||
GEN_BODY
|
GEN_BODY
|
||||||
bank.ChangePassword(NAME_PARAM, std::move(body["new_pass"].asCString()));
|
bank.ChangePassword(NAME_PARAM, std::move(body["new_pass"].asCString()));
|
||||||
RESPOND_TRUE //as we know the user exists and is verified
|
RESPOND_TRUE
|
||||||
}
|
}
|
||||||
void api::AdminChangePassword(req_args) const
|
void api::AdminChangePassword(req_args) const
|
||||||
{
|
{
|
||||||
|
|
@ -97,45 +95,45 @@ void api::SetBal(req_args) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//System Usage
|
//System Usage
|
||||||
void api::Help(req_args) const
|
void api::Help(req_args) const noexcept
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpResponse();
|
auto resp = HttpResponse::newHttpResponse();
|
||||||
resp->setBody(""); //will be filled in with docs
|
resp->setBody(""); //will be filled in with docs
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
CORS;
|
||||||
resp->setExpiredTime(0);
|
CACHE_FOREVER;
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
void api::Ping(req_args) const
|
void api::Ping(req_args) const noexcept
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpResponse();
|
auto resp = HttpResponse::newHttpResponse();
|
||||||
resp->setBody("pong");
|
resp->setBody("pong");
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
CORS;
|
||||||
resp->setExpiredTime(0);
|
CACHE_FOREVER;
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
void api::Close(req_args) const
|
void api::Close(req_args) const noexcept
|
||||||
{
|
{
|
||||||
bank.Save();
|
bank.Save();
|
||||||
app().quit();
|
app().quit();
|
||||||
RESPOND_TRUE //filter handles admin creds
|
RESPOND_TRUE //filter handles admin creds
|
||||||
}
|
}
|
||||||
void api::Contains(req_args, const std::string &name) const
|
void api::Contains(req_args, const std::string &name) const noexcept
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(bank.Contains(name)));
|
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(bank.Contains(name)));
|
||||||
resp->setStatusCode(k200OK);
|
resp->setStatusCode(k200OK);
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
CORS;
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
void api::AdminVerifyAccount(req_args)
|
void api::AdminVerifyAccount(req_args) const noexcept
|
||||||
{
|
{
|
||||||
RESPOND_TRUE //filter handles admin creds
|
RESPOND_TRUE //filter handles admin creds
|
||||||
}
|
}
|
||||||
void api::ApiVersion(req_args) const
|
void api::ApiVersion(req_args) const noexcept
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpJsonResponse(API_VERSION);
|
auto resp = HttpResponse::newHttpJsonResponse(API_VERSION);
|
||||||
resp->setStatusCode(k200OK);
|
resp->setStatusCode(k200OK);
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
CORS;
|
||||||
resp->setExpiredTime(0); //cached forever
|
CACHE_FOREVER;
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,7 +149,8 @@ void api::AdminAddUser(req_args) const
|
||||||
}
|
}
|
||||||
void api::DelUser(req_args) const
|
void api::DelUser(req_args) const
|
||||||
{
|
{
|
||||||
RESPONSE_PARSE(bank.DelUser(NAME_PARAM))
|
GEN_BODY
|
||||||
|
RESPONSE_PARSE(bank.DelUser(body["name"].asCString()))
|
||||||
}
|
}
|
||||||
void api::AdminDelUser(req_args) const
|
void api::AdminDelUser(req_args) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue