VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
userStore.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <map>
9 #include <mutex>
10 #include <string>
11 #include <vector>
12 
39 {
40 public:
42  static DtUserStore& getInstance();
43 
47  void initialize(const std::string& usersFilePath);
48 
50  bool userExists(const std::string& username) const;
51 
56  std::vector<std::string> getUserPermissions(const std::string& username) const;
57 
60  std::string getPasswordHash(const std::string& username) const;
61 
63  std::vector<std::string> usernames() const;
64 
68  bool addUser(const std::string& username,
69  const std::vector<std::string>& permissions,
70  const std::string& passwordHash);
71 
78  bool addUserWithPreset(const std::string& username,
79  const std::string& preset,
80  const std::vector<std::string>& extraPerms,
81  const std::string& passwordHash);
82 
85  std::string getUserPreset(const std::string& username) const;
86 
88  std::map<std::string, std::vector<std::string>> getPresets() const;
89 
92  bool removeUser(const std::string& username);
93 
97  bool setPasswordHash(const std::string& username, const std::string& passwordHash);
98 
102  bool setPermissions(const std::string& username,
103  const std::vector<std::string>& permissions);
104 
109  bool setPreset(const std::string& username, const std::string& preset);
110 
111 private:
112  DtUserStore();
113 
115  struct DtUserEntry
116  {
117  std::string preset;
118  std::vector<std::string> permissions;
119  std::string passwordHash;
120  };
121 
124  bool persistToFile() const;
125 
126  std::map<std::string, DtUserEntry> myUsers;
127  std::map<std::string, std::vector<std::string>> myPresets;
128  std::string myUsersFilePath;
129  mutable std::mutex myMutex;
130 };
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&#39;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&#39;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&#39;s extra permissions are not modified.
std::string myUsersFilePath
Definition: userStore.h:128

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)