mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-16 08:12:12 +11:00
commit
d71d74678e
5 changed files with 46 additions and 26 deletions
|
|
@ -67,6 +67,12 @@ else()
|
|||
set(MULTI_THREADED_VAL true)
|
||||
endif()
|
||||
|
||||
if(DEFINED ADD_USER_OPEN)
|
||||
set(ADD_USER_OPEN_VAL ${ADD_USER_OPEN})
|
||||
else()
|
||||
set(ADD_USER_OPEN_VAL true)
|
||||
endif()
|
||||
|
||||
if(DEFINED RETURN_ON_DEL_NAME)
|
||||
set(RETURN_ON_DEL_VAL true)
|
||||
set(RETURN_ON_DEL_NAME_VAL "\"" + ${RETURN_ON_DEL_NAME} + "\"")
|
||||
|
|
|
|||
|
|
@ -37,4 +37,6 @@ etc
|
|||
*/
|
||||
#define API_VERSION 1
|
||||
|
||||
#define MULTI_THREADED @MULTI_THREADED_VAL@
|
||||
#define MULTI_THREADED @MULTI_THREADED_VAL@
|
||||
|
||||
#define ADD_USER_OPEN @ADD_USER_OPEN_VAL@
|
||||
|
|
@ -66,14 +66,15 @@ cp ../config/config.json config.json
|
|||
|
||||
### CMake Flags
|
||||
there are multiple flags responsible configuring CCash:
|
||||
| name | default | description | pros | cons |
|
||||
| :--------------------- | :--------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------- |
|
||||
| USER_SAVE_LOC | "users.dat" | where the users are saved | `N/A` | `N/A` |
|
||||
| name | default | description | pros | cons |
|
||||
| :--------------------- | :-----------: | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------- |
|
||||
| USER_SAVE_LOC | "users.dat" | where the users are saved | `N/A` | `N/A` |
|
||||
| DROGON_CONFIG_LOC | "config.json" | where the config is located | `N/A` | `N/A` |
|
||||
| MAX_LOG_SIZE | 100 | max number of logs per user, last `n` transactions. If both this and pre log are toggled to 0 logs will not be compiled. | large history | higher memory usage |
|
||||
| CONSERVATIVE_DISK_SAVE | `true` | when `true` only saves when changes are made | low # of disk operations | some atomic overhead |
|
||||
| MULTI_THREADED | `true` | when `true` the program is compiled to utilize `n` threads which corresponds to how many Cores your CPU has, plus 1 for saving | speed | memory lock overhead is wasteful on single core machines |
|
||||
| RETURN_ON_DEL_NAME | `N/A` | when defined, return on delete will be toggled and any accounts deleted will send their funds to the defined account, this prevent currency destruction | prevents destruction of currency | deleting accounts is made slower |
|
||||
| MAX_LOG_SIZE | 100 | max number of logs per user, last `n` transactions. If both this and pre log are toggled to 0 logs will not be compiled. | large history | higher memory usage |
|
||||
| CONSERVATIVE_DISK_SAVE | `true` | when `true` only saves when changes are made | low # of disk operations | some atomic overhead |
|
||||
| MULTI_THREADED | `true` | when `true` the program is compiled to utilize `n` threads which corresponds to how many Cores your CPU has, plus 1 for saving | speed | memory lock overhead is wasteful on single core machines |
|
||||
| RETURN_ON_DEL_NAME | `N/A` | when defined, return on delete will be toggled and any accounts deleted will send their funds to the defined account, this prevent currency destruction | prevents destruction of currency | deleting accounts is made slower |
|
||||
| ADD_USER_OPEN | `true` | anybody can make a new account, if set to false only admins can add accounts via `AdminAddUser()` | `N/A` | spamming new users |
|
||||
|
||||
|
||||
EXAMPLE:
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ Valid
|
|||
### User Management endpoints
|
||||
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
|
||||
| :----------- | --------------------------------------- | --------------------------------------------- | -------------------------- | :---------: | :------------: | :---------: | :----------: | :----------------: | :----------------------: | :----------------------: | :----------------------: |
|
||||
| AddUser | adding a user with a balance of 0 | {"name":string,"pass":string} | api/v1/user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
| AddUser | adding a user with a balance of 0 | {"name":string,"pass":string} | api/v1/user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
| AdminAddUser | adding a user with an arbitrary balance | {"name":string,"amount":uint32,"pass":string} | api/v1/admin/user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| DelSelf | deletes a user | `N/A` | api/v1/user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: |
|
||||
| AdminDelUser | deletes a given user `{name}` | {"name":string} | api/v1/admin/user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
|
|
@ -110,7 +110,7 @@ Valid
|
|||
### User Management endpoint errors
|
||||
| name | 400 | 401 | 404 | 406 | 409 |
|
||||
| :----------- | :----------------------: | :----------------------: | :----------------------: | :----------------: | :----------------------: |
|
||||
| AddUser | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| AddUser | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| AdminAddUser | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| DelSelf | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| AdminDelUser | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ void api::AdminVerifyAccount(req_args)
|
|||
}
|
||||
void api::ApiProperties(req_args)
|
||||
{
|
||||
std::string info = "{\"version\":" + std::to_string(API_VERSION) + ",\"max_log\":" + std::to_string(MAX_LOG_SIZE);
|
||||
std::string info = "{\"version\":" + std::to_string(API_VERSION) + ",\"max_log\":" + std::to_string(MAX_LOG_SIZE) + ",\"add_user_open\":" + std::to_string(ADD_USER_OPEN);
|
||||
if constexpr (RETURN_ON_DEL)
|
||||
{
|
||||
info += ",\"return_on_del\":\"" + std::string(return_account) + "\"}";
|
||||
|
|
@ -257,28 +257,39 @@ void api::PruneUsers(req_args)
|
|||
|
||||
void api::AddUser(req_args)
|
||||
{
|
||||
SIMD_JSON_GEN;
|
||||
BankResponse res;
|
||||
if (doc.error())
|
||||
if constexpr (ADD_USER_OPEN)
|
||||
{
|
||||
res = BankResponse{k400BadRequest, "\"Invalid JSON\""};
|
||||
}
|
||||
else
|
||||
{
|
||||
auto name = doc["name"].get_string();
|
||||
auto pass = doc["pass"].get_string();
|
||||
if (name.error() || pass.error())
|
||||
|
||||
SIMD_JSON_GEN;
|
||||
BankResponse res;
|
||||
if (doc.error())
|
||||
{
|
||||
res = BankResponse{k400BadRequest, "\"Missing JSON arg(s)\""};
|
||||
res = BankResponse{k400BadRequest, "\"Invalid JSON\""};
|
||||
}
|
||||
else
|
||||
{
|
||||
StrFromSV_Wrapper name_val(name.value());
|
||||
StrFromSV_Wrapper pass_val(pass.value());
|
||||
res = Bank::AddUser(name_val.str, 0, pass_val.str);
|
||||
auto name = doc["name"].get_string();
|
||||
auto pass = doc["pass"].get_string();
|
||||
if (name.error() || pass.error())
|
||||
{
|
||||
res = BankResponse{k400BadRequest, "\"Missing JSON arg(s)\""};
|
||||
}
|
||||
else
|
||||
{
|
||||
StrFromSV_Wrapper name_val(name.value());
|
||||
StrFromSV_Wrapper pass_val(pass.value());
|
||||
res = Bank::AddUser(name_val.str, 0, pass_val.str);
|
||||
}
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newCustomHttpResponse(BankResponse{k404NotFound, "\"AddUser is Disabled\""});
|
||||
CORS;
|
||||
CACHE_FOREVER;
|
||||
callback(resp);
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
void api::AdminAddUser(req_args)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue