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)
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} + "\"")

View file

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

View file

@ -67,13 +67,14 @@ 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` |
| 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 |
| 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:

View file

@ -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: |

View file

@ -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,6 +257,9 @@ void api::PruneUsers(req_args)
void api::AddUser(req_args)
{
if constexpr (ADD_USER_OPEN)
{
SIMD_JSON_GEN;
BankResponse res;
if (doc.error())
@ -280,6 +283,14 @@ void api::AddUser(req_args)
}
RESPONSE_PARSE(std::move(res));
}
else
{
auto resp = HttpResponse::newCustomHttpResponse(BankResponse{k404NotFound, "\"AddUser is Disabled\""});
CORS;
CACHE_FOREVER;
callback(resp);
}
}
void api::AdminAddUser(req_args)
{
SIMD_JSON_GEN;