userdaosqlite: query enabled + implemented save
This commit is contained in:
parent
2f7a87ce6d
commit
7c435d61d4
@ -40,10 +40,11 @@ std::optional<User> UserDaoSqlite::find(std::string username)
|
||||
try
|
||||
{
|
||||
User user;
|
||||
auto stmt = *db << "SELECT username, password, salt, permissions FROM user WHERE username = ?" << username;
|
||||
auto stmt = *db << "SELECT username, password, salt, permissions, enabled FROM user WHERE username = ?"
|
||||
<< username;
|
||||
|
||||
int perms = 0;
|
||||
stmt >> std::tie(user.login, user.password, user.salt, perms);
|
||||
stmt >> std::tie(user.login, user.password, user.salt, perms, user.enabled);
|
||||
user.permissions = Permissions{perms};
|
||||
|
||||
return std::move(user);
|
||||
@ -63,10 +64,10 @@ std::optional<User> UserDaoSqlite::find(int id)
|
||||
try
|
||||
{
|
||||
User user;
|
||||
auto stmt = *db << "SELECT username, password, salt, permissions FROM user WHERE id = ?" << id;
|
||||
auto stmt = *db << "SELECT username, password, salt, permissions, enabled FROM user WHERE id = ?" << id;
|
||||
|
||||
int perms = 0;
|
||||
stmt >> std::tie(user.login, user.password, user.salt, perms);
|
||||
stmt >> std::tie(user.login, user.password, user.salt, perms, user.enabled);
|
||||
user.permissions = Permissions{perms};
|
||||
|
||||
return std::move(user);
|
||||
@ -88,4 +89,15 @@ void UserDaoSqlite::deleteUser(std::string username)
|
||||
|
||||
void UserDaoSqlite::save(const User &u)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto q = *db << "INSERT OR REPLACE INTO user(id, username, password, salt, permissions, enabled) "
|
||||
"VALUES((SELECT id FROM user WHERE username = ?), ?,?,?,?,?)";
|
||||
q << u.login << u.login << u.password << u.salt << u.permissions.getPermissions() << u.enabled;
|
||||
q.execute();
|
||||
}
|
||||
catch(sqlite::sqlite_exception &e)
|
||||
{
|
||||
throwFrom(e);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user