userdaosqlite: query enabled + implemented save
This commit is contained in:
父節點
b29194f0d9
當前提交
81816dd28c
@ -41,10 +41,10 @@ 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);
|
||||
@ -64,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);
|
||||
@ -89,5 +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