mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
:construction
This commit is contained in:
parent
8eadc3e6d9
commit
a4505b1408
4 changed files with 76 additions and 74 deletions
|
|
@ -49,19 +49,19 @@ public:
|
||||||
BankResponse SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount) noexcept;
|
BankResponse SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount) noexcept;
|
||||||
bool VerifyPassword(const std::string &name, const std::string &attempt) const noexcept; //internally used
|
bool VerifyPassword(const std::string &name, const std::string &attempt) const noexcept; //internally used
|
||||||
|
|
||||||
|
void ChangePassword(const std::string &name, std::string &&new_pass) noexcept;
|
||||||
|
|
||||||
int_fast8_t AddUser(const std::string &name, const std::string &init_pass) noexcept;
|
int_fast8_t AddUser(const std::string &name, const std::string &init_pass) noexcept;
|
||||||
int_fast8_t AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept;
|
int_fast8_t AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept;
|
||||||
|
|
||||||
int_fast8_t DelUser(const std::string &name, const std::string &attempt) noexcept;
|
int_fast8_t DelUser(const std::string &name, const std::string &attempt) noexcept;
|
||||||
int_fast8_t AdminDelUser(const std::string &name, const std::string &attempt) noexcept;
|
int_fast8_t AdminDelUser(const std::string &name, const std::string &attempt) noexcept;
|
||||||
|
|
||||||
bool Contains(const std::string &name) const noexcept; //done
|
bool Contains(const std::string &name) const noexcept;
|
||||||
int_fast8_t AdminVerifyPass(const std::string &attempt) noexcept;
|
int_fast8_t AdminVerifyPass(const std::string &attempt) noexcept;
|
||||||
|
|
||||||
int_fast8_t SetBal(const std::string &name, const std::string &attempt, uint32_t amount) noexcept;
|
int_fast8_t SetBal(const std::string &name, const std::string &attempt, uint32_t amount) noexcept;
|
||||||
|
|
||||||
int_fast8_t ChangePassword(const std::string &name, const std::string &attempt, std::string &&new_pass) noexcept;
|
|
||||||
|
|
||||||
void Save();
|
void Save();
|
||||||
void Load();
|
void Load();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,12 @@ namespace v1
|
||||||
|
|
||||||
public:
|
public:
|
||||||
api(Bank &b);
|
api(Bank &b);
|
||||||
void GetBal(req_args) const;
|
void GetBal(req_args, const std::string &name) const;
|
||||||
void GetLog(req_args, const std::string &name);
|
void GetLog(req_args, const std::string &name);
|
||||||
void SendFunds(req_args, const std::string name) const;
|
void SendFunds(req_args, const std::string &name) const;
|
||||||
void VerifyPassword(req_args) const;
|
void VerifyPassword(req_args, const std::string &name) const;
|
||||||
|
|
||||||
|
void ChangePassword(req_args, const std::string &name) const;
|
||||||
|
|
||||||
void Help(req_args) const;
|
void Help(req_args) const;
|
||||||
void Ping(req_args) const;
|
void Ping(req_args) const;
|
||||||
|
|
@ -26,7 +28,6 @@ namespace v1
|
||||||
void AdminAddUser(req_args, std::string &&name, uint32_t init_bal) const;
|
void AdminAddUser(req_args, std::string &&name, uint32_t init_bal) const;
|
||||||
void DelUser(req_args, const std::string &name) const;
|
void DelUser(req_args, const std::string &name) const;
|
||||||
void AdminDelUser(req_args, const std::string &name) const;
|
void AdminDelUser(req_args, const std::string &name) const;
|
||||||
void ChangePassword(req_args, const std::string &name) const;
|
|
||||||
void Contains(req_args, const std::string &name) const;
|
void Contains(req_args, const std::string &name) const;
|
||||||
void SetBal(req_args, const std::string &name, uint32_t amount) const;
|
void SetBal(req_args, const std::string &name, uint32_t amount) const;
|
||||||
void AdminVerifyPass(req_args);
|
void AdminVerifyPass(req_args);
|
||||||
|
|
@ -34,13 +35,13 @@ namespace v1
|
||||||
METHOD_LIST_BEGIN
|
METHOD_LIST_BEGIN
|
||||||
|
|
||||||
//Usage
|
//Usage
|
||||||
METHOD_ADD(api::GetBal, "/user/bal", Get, Options); //done
|
METHOD_ADD(api::GetBal, "/users/{name}/bal", Get, Options); //done
|
||||||
METHOD_ADD(api::GetLog, "/user/log", Get, Options, "UserFilter"); //snapshot not implemented
|
METHOD_ADD(api::GetLog, "/users/{name}/log", Get, Options, "UserFilter"); //snapshot not implemented
|
||||||
METHOD_ADD(api::SendFunds, "/user/transfer", Post, Options, "UserFilter"); //responses incomplete
|
METHOD_ADD(api::SendFunds, "/users/{name}/transfer", Post, Options, "UserFilter"); //responses incomplete
|
||||||
METHOD_ADD(api::VerifyPassword, "/{name}/pass/verify", Get, Options); //done
|
METHOD_ADD(api::VerifyPassword, "/users/{name}/verify_password", Get, Options); //done
|
||||||
|
|
||||||
//Meta Usage
|
//Meta Usage
|
||||||
METHOD_ADD(api::ChangePassword, "/{name}/pass/change", Patch, Options);
|
METHOD_ADD(api::ChangePassword, "/users/{name}/change_password", Patch, Options); //done
|
||||||
METHOD_ADD(api::SetBal, "/admin/{name}/bal?amount={amount}", Patch, Options);
|
METHOD_ADD(api::SetBal, "/admin/{name}/bal?amount={amount}", Patch, Options);
|
||||||
|
|
||||||
//System Usage
|
//System Usage
|
||||||
|
|
|
||||||
28
src/bank.cpp
28
src/bank.cpp
|
|
@ -81,7 +81,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam
|
||||||
//if A can afford it and A's password matches attempt
|
//if A can afford it and A's password matches attempt
|
||||||
if (a.balance < amount)
|
if (a.balance < amount)
|
||||||
{
|
{
|
||||||
state = {ErrorResponse::InsufficientFunds, "Sender has insufficient funds"};
|
state = {k200OK, "Sender has insufficient funds"};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -107,7 +107,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam
|
||||||
//if A can afford it and A's password matches attempt
|
//if A can afford it and A's password matches attempt
|
||||||
if (a.balance < amount)
|
if (a.balance < amount)
|
||||||
{
|
{
|
||||||
state = {ErrorResponse::InsufficientFunds, "Sender has insufficient funds"};
|
state = {k200OK, "Sender has insufficient funds"};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -134,6 +134,13 @@ bool Bank::VerifyPassword(const std::string &name, const std::string &attempt) c
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bank::ChangePassword(const std::string &name, std::string &&new_pass) noexcept
|
||||||
|
{
|
||||||
|
users.modify_if(name, [&new_pass](User &u) {
|
||||||
|
u.password = XXH3_64bits(new_pass.data(), new_pass.size());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
int_fast8_t Bank::AddUser(const std::string &name, const std::string &init_pass) noexcept
|
int_fast8_t Bank::AddUser(const std::string &name, const std::string &init_pass) noexcept
|
||||||
{
|
{
|
||||||
if (name.size() > max_name_size)
|
if (name.size() > max_name_size)
|
||||||
|
|
@ -265,23 +272,6 @@ int_fast8_t Bank::SetBal(const std::string &name, const std::string &attempt, ui
|
||||||
: ErrorResponse::UserNotFound;
|
: ErrorResponse::UserNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
int_fast8_t Bank::ChangePassword(const std::string &name, const std::string &attempt, std::string &&new_pass) noexcept
|
|
||||||
{
|
|
||||||
int_fast8_t res = ErrorResponse::UserNotFound;
|
|
||||||
users.modify_if(name, [&res, &attempt, &new_pass](User &u) {
|
|
||||||
if (u.password != XXH3_64bits(attempt.data(), attempt.size()))
|
|
||||||
{
|
|
||||||
res = ErrorResponse::WrongPassword;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
res = true;
|
|
||||||
u.password = XXH3_64bits(new_pass.data(), new_pass.size());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bank::Save()
|
void Bank::Save()
|
||||||
{
|
{
|
||||||
if (GetChangeState())
|
if (GetChangeState())
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue