diff --git a/help.md b/help.md index a0b7202..8d34a56 100644 --- a/help.md +++ b/help.md @@ -39,7 +39,7 @@ # User Management | Name | Path | Method | A | Description | | :----------: | :------------------------------------- | :----: | :---: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| AddUser | /user/{name} | POST | false | registers a user with the name `{name}`, balance of 0 and a password of the password supplied in the body | +| AddUser | /user/{name} | POST | true | registers a user with the name `{name}`, balance of 0 and a password of the password supplied in the header | | AdminAddUser | /admin/user/{name}?init_bal={init_bal} | POST | true | if the password supplied in the header matches the admin password, then it registers a user with the name `{name}`, balance of `init_bal` and a password supplied by the body of the request | | DelUser | /user/{name} | DELETE | true | if the password supplied in the header matches the user `{name}`'s password, then the user is deleted | | AdminDelUser | /admin/user/{name} | DELETE | true | if the password supplied in the header matches the admin password, then the user is deleted | \ No newline at end of file diff --git a/include/bank.h b/include/bank.h index 9b6e3cc..1408233 100644 --- a/include/bank.h +++ b/include/bank.h @@ -33,24 +33,24 @@ private: public: std::string admin_pass; - int_fast8_t AddUser(const std::string &name, std::string &&init_pass); - int_fast8_t AdminAddUser(std::string_view attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass); + int_fast8_t AddUser(const std::string &name, const std::string &init_pass); + int_fast8_t AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass); - int_fast8_t DelUser(const std::string &name, std::string_view attempt); - int_fast8_t AdminDelUser(const std::string &name, std::string_view attempt); + int_fast8_t DelUser(const std::string &name, const std::string &attempt); + int_fast8_t AdminDelUser(const std::string &name, const std::string &attempt); - int_fast8_t SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount, std::string_view attempt); + int_fast8_t SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount, const std::string &attempt); bool Contains(const std::string &name) const; - bool AdminVerifyPass(std::string_view attempt); + bool AdminVerifyPass(const std::string &attempt); - int_fast8_t SetBal(const std::string &name, std::string_view attempt, uint32_t amount); + int_fast8_t SetBal(const std::string &name, const std::string &attempt, uint32_t amount); int_fast64_t GetBal(const std::string &name) const; - int_fast8_t VerifyPassword(const std::string &name, std::string_view attempt) const; - int_fast8_t ChangePassword(const std::string &name, std::string_view attempt, std::string &&new_pass); + int_fast8_t VerifyPassword(const std::string &name, const std::string &attempt) const; + int_fast8_t ChangePassword(const std::string &name, const std::string &attempt, std::string &&new_pass); - Json::Value GetLogs(const std::string &name, std::string_view attempt); + Json::Value GetLogs(const std::string &name, const std::string &attempt); void Save(); diff --git a/include/bank_f.h b/include/bank_f.h index aeb6d5f..99f8c52 100644 --- a/include/bank_f.h +++ b/include/bank_f.h @@ -14,7 +14,7 @@ public: BankF(Bank *b); void Help(req_args) const; void Close(req_args) const; - void AddUser(req_args, std::string &&name) const; + void AddUser(req_args, const std::string &name) const; void AdminAddUser(req_args, std::string &&name, uint32_t init_bal) const; void DelUser(req_args, const std::string &name) const; void AdminDelUser(req_args, const std::string &name) const; diff --git a/include/user.h b/include/user.h index 8e5ecad..26ec26f 100644 --- a/include/user.h +++ b/include/user.h @@ -11,8 +11,8 @@ struct User uint64_t password; Log log; - User(std::string &&init_pass); - User(uint32_t init_bal, std::string &&init_pass); + User(const std::string &init_pass); + User(uint32_t init_bal, const std::string &init_pass); User(uint32_t init_bal, uint64_t init_pass); User(uint32_t init_bal, uint64_t init_pass, const Json::Value &log_j); diff --git a/src/bank.cpp b/src/bank.cpp index 81785a8..59a402c 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -1,6 +1,6 @@ #include "bank.h" -int_fast8_t Bank::AddUser(const std::string &name, std::string &&init_pass) +int_fast8_t Bank::AddUser(const std::string &name, const std::string &init_pass) { if (name.size() > max_name_size) { @@ -9,7 +9,7 @@ int_fast8_t Bank::AddUser(const std::string &name, std::string &&init_pass) { std::shared_lock lock{size_l}; if (users.try_emplace_l( - name, [](User &) {}, std::move(init_pass))) + name, [](User &) {}, init_pass)) { return true; } @@ -19,7 +19,7 @@ int_fast8_t Bank::AddUser(const std::string &name, std::string &&init_pass) } } } -int_fast8_t Bank::AdminAddUser(std::string_view attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass) +int_fast8_t Bank::AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass) { if (name.size() > max_name_size) { @@ -42,7 +42,7 @@ int_fast8_t Bank::AdminAddUser(std::string_view attempt, std::string &&name, uin } } } -int_fast8_t Bank::DelUser(const std::string &name, std::string_view attempt) +int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt) { std::shared_lock lock{size_l}; bool state = false; @@ -62,7 +62,7 @@ int_fast8_t Bank::DelUser(const std::string &name, std::string_view attempt) } } } -int_fast8_t Bank::AdminDelUser(const std::string &name, std::string_view attempt) +int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attempt) { std::shared_lock lock{size_l}; bool state = false; @@ -83,7 +83,7 @@ int_fast8_t Bank::AdminDelUser(const std::string &name, std::string_view attempt } } -int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount, std::string_view attempt) +int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount, const std::string &attempt) { //cant send money to self, from self or amount is 0 if (a_name == b_name || !amount) @@ -159,12 +159,12 @@ bool Bank::Contains(const std::string &name) const { return users.contains(name); } -bool Bank::AdminVerifyPass(std::string_view attempt) +bool Bank::AdminVerifyPass(const std::string &attempt) { return (admin_pass == attempt); } -int_fast8_t Bank::SetBal(const std::string &name, std::string_view attempt, uint32_t amount) +int_fast8_t Bank::SetBal(const std::string &name, const std::string &attempt, uint32_t amount) { if (admin_pass != attempt) { @@ -190,7 +190,7 @@ int_fast64_t Bank::GetBal(const std::string &name) const return res; } -int_fast8_t Bank::VerifyPassword(const std::string &name, std::string_view attempt) const +int_fast8_t Bank::VerifyPassword(const std::string &name, const std::string &attempt) const { int_fast8_t res = ErrorResponse::UserNotFound; users.if_contains(name, [&res, &attempt](const User &u) { @@ -198,7 +198,7 @@ int_fast8_t Bank::VerifyPassword(const std::string &name, std::string_view attem }); return res; } -int_fast8_t Bank::ChangePassword(const std::string &name, std::string_view attempt, std::string &&new_pass) +int_fast8_t Bank::ChangePassword(const std::string &name, const std::string &attempt, std::string &&new_pass) { int_fast8_t res = ErrorResponse::UserNotFound; users.modify_if(name, [&res, &attempt, &new_pass](User &u) { @@ -214,7 +214,7 @@ int_fast8_t Bank::ChangePassword(const std::string &name, std::string_view attem return res; } -Json::Value Bank::GetLogs(const std::string &name, std::string_view attempt) +Json::Value Bank::GetLogs(const std::string &name, const std::string &attempt) { Json::Value res; if (!users.if_contains(name, [&res, &attempt](const User &u) { diff --git a/src/bank_f.cpp b/src/bank_f.cpp index a6b30ec..b3b0385 100644 --- a/src/bank_f.cpp +++ b/src/bank_f.cpp @@ -52,9 +52,9 @@ void BankF::Close(req_args) const } JSON(res); } -void BankF::AddUser(req_args, std::string &&name) const +void BankF::AddUser(req_args, const std::string &name) const { - JSON(bank.AddUser(std::move(name), std::string(req->getBody()))); + JSON(bank.AddUser(std::move(name), PASS_HEADER)); } void BankF::AdminAddUser(req_args, std::string &&name, uint32_t init_bal) const { diff --git a/src/user.cpp b/src/user.cpp index 1dfce5d..ade67c2 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -5,7 +5,7 @@ * * @param init_pass initial password */ -User::User(std::string &&init_pass) : password(XXH3_64bits(init_pass.data(), init_pass.size())) {} +User::User(const std::string &init_pass) : password(XXH3_64bits(init_pass.data(), init_pass.size())) {} /** * @brief User Constructor for admins @@ -13,7 +13,7 @@ User::User(std::string &&init_pass) : password(XXH3_64bits(init_pass.data(), ini * @param init_bal initial balance * @param init_pass initial password */ -User::User(uint32_t init_bal, std::string &&init_pass) : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())) {} +User::User(uint32_t init_bal, const std::string &init_pass) : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())) {} /** * @brief User Constructor for loading