mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-16 16:12:14 +11:00
🎨 simplified
This commit is contained in:
parent
e157586557
commit
029a10f1bc
3 changed files with 4 additions and 29 deletions
|
|
@ -65,8 +65,7 @@ public:
|
|||
bool Contains(const std::string &name) const noexcept;
|
||||
bool AdminVerifyAccount(std::string_view name) noexcept;
|
||||
|
||||
BankResponse AddUser(std::string &&name, std::string &&init_pass) noexcept;
|
||||
BankResponse AdminAddUser(std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept;
|
||||
BankResponse AddUser(std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept;
|
||||
BankResponse DelUser(const std::string &name) noexcept;
|
||||
|
||||
void Save();
|
||||
|
|
|
|||
26
src/bank.cpp
26
src/bank.cpp
|
|
@ -158,31 +158,7 @@ bool Bank::AdminVerifyAccount(std::string_view name) noexcept
|
|||
return (name == admin_account);
|
||||
}
|
||||
|
||||
BankResponse Bank::AddUser(std::string &&name, std::string &&init_pass) noexcept
|
||||
{
|
||||
if (!ValidUsrname(name))
|
||||
{
|
||||
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
||||
}
|
||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||
if (users.try_emplace_l(
|
||||
std::move(name), [](User &) {}, std::move(init_pass)))
|
||||
{
|
||||
#if CONSERVATIVE_DISK_SAVE
|
||||
#if MULTI_THREADED
|
||||
save_flag.SetChangesOn();
|
||||
#else
|
||||
save_flag = true;
|
||||
#endif
|
||||
#endif
|
||||
return {k200OK, "User added!"};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {k409Conflict, "User already exists"};
|
||||
}
|
||||
}
|
||||
BankResponse Bank::AdminAddUser(std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept
|
||||
BankResponse Bank::AddUser(std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept
|
||||
{
|
||||
if (!ValidUsrname(name))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -140,12 +140,12 @@ void api::ApiVersion(req_args) const
|
|||
void api::AddUser(req_args) const
|
||||
{
|
||||
GEN_BODY
|
||||
RESPONSE_PARSE(bank.AddUser(body["name"].asCString(), body["pass"].asCString()))
|
||||
RESPONSE_PARSE(bank.AddUser(body["name"].asCString(), 0, body["pass"].asCString()))
|
||||
}
|
||||
void api::AdminAddUser(req_args) const
|
||||
{
|
||||
GEN_BODY
|
||||
RESPONSE_PARSE(bank.AdminAddUser(body["name"].asCString(), body["balance"].asUInt(), body["pass"].asCString()))
|
||||
RESPONSE_PARSE(bank.AddUser(body["name"].asCString(), body["balance"].asUInt(), body["pass"].asCString()))
|
||||
}
|
||||
void api::DelUser(req_args) const
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue