userdaosqlite: query enabled + implemented save
This commit is contained in:
parent
b29194f0d9
commit
81816dd28c
@ -41,10 +41,10 @@ std::optional<User> UserDaoSqlite::find(std::string username)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
User user;
|
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;
|
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 };
|
user.permissions = Permissions { perms };
|
||||||
|
|
||||||
return std::move(user);
|
return std::move(user);
|
||||||
@ -64,10 +64,10 @@ std::optional<User> UserDaoSqlite::find(int id)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
User user;
|
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;
|
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 };
|
user.permissions = Permissions { perms };
|
||||||
|
|
||||||
return std::move(user);
|
return std::move(user);
|
||||||
@ -89,5 +89,15 @@ void UserDaoSqlite::deleteUser(std::string username)
|
|||||||
|
|
||||||
void UserDaoSqlite::save(const User &u)
|
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