🎨 simplified DelUser()

This commit is contained in:
EntireTwix 2021-06-27 19:38:06 -07:00
parent 541b912efe
commit 1ea1618228

View file

@ -202,36 +202,28 @@ int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt) n
if (users.erase_if(name, [this, &bal, &name, &state, &attempt](User &u) { if (users.erase_if(name, [this, &bal, &name, &state, &attempt](User &u) {
bal = u.balance; bal = u.balance;
#else #else
if (users.erase_if(name, [this, &name, &state, &attempt](User &u) { if (!users.erase_if(name, [this, &name, &state, &attempt](User &u) {
#endif #endif
return state = (XXH3_64bits(attempt.data(), attempt.size()) == u.password); return state = (XXH3_64bits(attempt.data(), attempt.size()) == u.password);
})) }))
{ {
if constexpr (RETURN_ON_DEL) return ErrorResponse::UserNotFound;
{ }
if (state) //if the password matches
{
#if RETURN_ON_DEL #if RETURN_ON_DEL
users.modify_if(return_account, [&bal](User &u) { if (state) //if the password matches
u.balance += bal; {
}); users.modify_if(return_account, [&bal](User &u) {
#endif u.balance += bal;
return true; });
} return true;
else
{
return ErrorResponse::WrongPassword;
}
}
else
{
return (state) ? true : ErrorResponse::WrongPassword;
}
} }
else else
{ {
return ErrorResponse::UserNotFound; return ErrorResponse::WrongPassword;
} }
#else
return (state) ? true : ErrorResponse::WrongPassword;
#endif
} }
int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attempt) noexcept int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attempt) noexcept
{ {