mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 08:32:13 +11:00
🎨 simplified DelUser()
This commit is contained in:
parent
541b912efe
commit
1ea1618228
1 changed files with 13 additions and 21 deletions
34
src/bank.cpp
34
src/bank.cpp
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue