Repository navigation
Expand file tree
/
Copy pathuser_store.cpp
More file actions
69 lines (52 loc) · 2.04 KB
/
Copy pathuser_store.cpp
File metadata and controls
69 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* UserStore — user and settings management delegated through StorageBackend.
*/
#include "user_store.h"
#include "sqlite/backend.h"
#include "config.h"
#include <filesystem>
#include <stdexcept>
#include <string>
namespace ragger {
using sqlite::Backend;
namespace fs = std::filesystem;
struct UserStore::Impl {
std::unique_ptr<sqlite::Backend> backend;
explicit Impl(const std::string& path) {
std::string resolved = expand_path(path);
fs::create_directories(fs::path(resolved).parent_path());
backend = std::make_unique<sqlite::Backend>(resolved);
}
};
UserStore::UserStore(const std::string& db_path)
: pImpl(std::make_unique<Impl>(db_path)) {}
UserStore::~UserStore() = default;
std::optional<UserInfo> UserStore::get_user_by_username(const std::string& username) {
return pImpl->backend->get_user_by_username(username);
}
std::optional<std::string> UserStore::get_user_password(const std::string& username) {
return pImpl->backend->get_user_password(username);
}
void UserStore::update_user_token(const std::string& username, const std::string& new_hash) {
pImpl->backend->update_user_token(username, new_hash);
}
int UserStore::create_user(const std::string& username, const std::string& token_hash) {
return pImpl->backend->create_user(username, token_hash);
}
bool UserStore::delete_user(const std::string& username) {
return pImpl->backend->delete_user(username);
}
void UserStore::set_user_password(const std::string& username,
const std::string& password_hash) {
pImpl->backend->set_user_password(username, password_hash);
}
std::optional<UserInfo> UserStore::get_user_by_token_hash(const std::string& token_hash) {
return pImpl->backend->get_user_by_token_hash(token_hash);
}
std::optional<std::string> UserStore::get_setting(const std::string& key) {
return pImpl->backend->get_setting(key);
}
void UserStore::set_setting(const std::string& key, const std::string& value) {
pImpl->backend->set_setting(key, value);
}
} // namespace ragger