1
0

userdaosqlite: query enabled + implemented save

Este cometimento está contido em:
Albert S. 2019-05-03 15:56:52 +02:00
ascendente b29194f0d9
cometimento 81816dd28c

Ver ficheiro

@ -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);
}
}