Merge pull request #36 from EntireTwix/AddUserToggle

AddUser toggle
This commit is contained in:
William Katz 2021-12-02 12:39:57 -08:00 committed by GitHub
commit d71d74678e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 26 deletions

View file

@ -67,6 +67,12 @@ else()
set(MULTI_THREADED_VAL true) set(MULTI_THREADED_VAL true)
endif() 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) if(DEFINED RETURN_ON_DEL_NAME)
set(RETURN_ON_DEL_VAL true) set(RETURN_ON_DEL_VAL true)
set(RETURN_ON_DEL_NAME_VAL "\"" + ${RETURN_ON_DEL_NAME} + "\"") set(RETURN_ON_DEL_NAME_VAL "\"" + ${RETURN_ON_DEL_NAME} + "\"")

View file

@ -38,3 +38,5 @@ etc
#define API_VERSION 1 #define API_VERSION 1
#define MULTI_THREADED @MULTI_THREADED_VAL@ #define MULTI_THREADED @MULTI_THREADED_VAL@
#define ADD_USER_OPEN @ADD_USER_OPEN_VAL@

View file

@ -66,14 +66,15 @@ cp ../config/config.json config.json
### CMake Flags ### CMake Flags
there are multiple flags responsible configuring CCash: there are multiple flags responsible configuring CCash:
| name | default | description | pros | cons | | name | default | description | pros | cons |
| :--------------------- | :--------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------- | | :--------------------- | :-----------: | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------- |
| USER_SAVE_LOC | "users.dat" | where the users are saved | `N/A` | `N/A` | | 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` | | 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 | | 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 | | 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 | | 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 | | 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: EXAMPLE:

View file

@ -102,7 +102,7 @@ Valid
### User Management endpoints ### User Management endpoints
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U | | 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: | | 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: | | 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: | | 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 ### User Management endpoint errors
| name | 400 | 401 | 404 | 406 | 409 | | 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: | | 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: | | 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: | | AdminDelUser | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: |

View file

@ -205,7 +205,7 @@ void api::AdminVerifyAccount(req_args)
} }
void api::ApiProperties(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) if constexpr (RETURN_ON_DEL)
{ {
info += ",\"return_on_del\":\"" + std::string(return_account) + "\"}"; info += ",\"return_on_del\":\"" + std::string(return_account) + "\"}";
@ -257,28 +257,39 @@ void api::PruneUsers(req_args)
void api::AddUser(req_args) void api::AddUser(req_args)
{ {
SIMD_JSON_GEN; if constexpr (ADD_USER_OPEN)
BankResponse res;
if (doc.error())
{ {
res = BankResponse{k400BadRequest, "\"Invalid JSON\""};
} SIMD_JSON_GEN;
else BankResponse res;
{ if (doc.error())
auto name = doc["name"].get_string();
auto pass = doc["pass"].get_string();
if (name.error() || pass.error())
{ {
res = BankResponse{k400BadRequest, "\"Missing JSON arg(s)\""}; res = BankResponse{k400BadRequest, "\"Invalid JSON\""};
} }
else else
{ {
StrFromSV_Wrapper name_val(name.value()); auto name = doc["name"].get_string();
StrFromSV_Wrapper pass_val(pass.value()); auto pass = doc["pass"].get_string();
res = Bank::AddUser(name_val.str, 0, pass_val.str); 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) void api::AdminAddUser(req_args)
{ {