47 void initialize(
const std::string& usersFilePath);
50 bool userExists(
const std::string& username)
const;
63 std::vector<std::string>
usernames()
const;
68 bool addUser(
const std::string& username,
69 const std::vector<std::string>& permissions,
70 const std::string& passwordHash);
79 const std::string& preset,
80 const std::vector<std::string>& extraPerms,
81 const std::string& passwordHash);
88 std::map<std::string, std::vector<std::string>>
getPresets()
const;
97 bool setPasswordHash(
const std::string& username,
const std::string& passwordHash);
103 const std::vector<std::string>& permissions);
109 bool setPreset(
const std::string& username,
const std::string& preset);
127 std::map<std::string, std::vector<std::string>>
myPresets;
std::vector< std::string > usernames() const
Returns a list of all known usernames.
bool removeUser(const std::string &username)
Removes the user with the given username.
std::mutex myMutex
Definition: userStore.h:129
bool addUser(const std::string &username, const std::vector< std::string > &permissions, const std::string &passwordHash)
Adds a new user with the given permissions and optional password hash.
bool persistToFile() const
Serializes myUsers and myPresets back to myUsersFilePath. Must be called while myMutex is held...
std::vector< std::string > getUserPermissions(const std::string &username) const
Returns the permission strings for the given user. The returned list is the union of the user's prese...
std::string getPasswordHash(const std::string &username) const
Returns the stored password hash for the given user. Returns an empty string if the user does not exi...
Per-user record.
Definition: userStore.h:115
std::map< std::string, std::vector< std::string > > myPresets
Definition: userStore.h:127
static DtUserStore & getInstance()
Returns the process-wide singleton instance.
bool userExists(const std::string &username) const
Returns true if a user with the given username exists in the store.
std::string passwordHash
Empty = no password required.
Definition: userStore.h:119
std::string preset
Named preset (empty = none).
Definition: userStore.h:117
bool setPermissions(const std::string &username, const std::vector< std::string > &permissions)
Replaces the full permission list for an existing user. Replaces only the user's extra permissions; t...
bool addUserWithPreset(const std::string &username, const std::string &preset, const std::vector< std::string > &extraPerms, const std::string &passwordHash)
Adds a new user whose permissions are derived from a named preset, with an optional list of additiona...
std::map< std::string, std::vector< std::string > > getPresets() const
Returns all defined presets as a map of preset-name → permission list.
std::string getUserPreset(const std::string &username) const
Returns the preset name assigned to the given user. Returns an empty string if the user does not exis...
DtUserStore — process-wide singleton for loading and querying the user database.
Definition: userStore.h:38
bool setPasswordHash(const std::string &username, const std::string &passwordHash)
Replaces the password hash for an existing user. Pass an empty string to remove the password requirem...
void initialize(const std::string &usersFilePath)
Load users from the given JSON file path. Creates a default file with admin/viewer users if the path ...
std::map< std::string, DtUserEntry > myUsers
Definition: userStore.h:126
std::vector< std::string > permissions
Extra permissions beyond the preset.
Definition: userStore.h:118
bool setPreset(const std::string &username, const std::string &preset)
Sets the preset for an existing user. Pass an empty string to remove the preset assignment. The user's extra permissions are not modified.
std::string myUsersFilePath
Definition: userStore.h:128