MythTV  master
mythsession.h
Go to the documentation of this file.
1 #ifndef MYTHSESSION_H
2 #define MYTHSESSION_H
3 
4 #include "mythbaseexp.h"
5 
6 #include <cstdint>
7 
8 #include <QString>
9 #include <QDateTime>
10 #include <QMap>
11 
12 enum DigestUserActions : std::uint8_t {
16 };
17 
19 {
20  public :
21  MythUserSession() = default;
22  ~MythUserSession() { m_sessionToken.fill('0'); m_sessionToken.clear(); }
23  MythUserSession(const MythUserSession &) = default;
24  MythUserSession(MythUserSession&& other) = default;
25  MythUserSession &operator=(const MythUserSession &) = default;
26  MythUserSession& operator=(MythUserSession&& other) = default;
27 
39  bool IsValid(void) const;
40 
41  QString GetUserName(void) const { return m_name; }
42  uint GetUserId(void) const { return m_userId; }
43 
44  QString GetSessionToken(void) const { return m_sessionToken; }
45  QString GetSessionClient(void) const { return m_sessionClient; }
46 
47  QDateTime GetSessionCreated() const { return m_sessionCreated; }
48  QDateTime GetSessionLastActive() const { return m_sessionLastActive; }
49  QDateTime GetSessionExpires() const { return m_sessionExpires; }
50 
59  bool CheckPermission( const QString &context, uint permission);
60 
61  protected:
69  bool Save(void);
70 
74  bool Update(void);
75 
76  uint m_userId {0};
77  QString m_name;
78 
79  QString m_sessionToken;
80  QDateTime m_sessionCreated;
81  QDateTime m_sessionLastActive; // For informational purposes
82  QDateTime m_sessionExpires;
83  QString m_sessionClient;
84 
85  QMap<QString, uint> m_permissionsList; // Context, flags
86 
87  friend class MythSessionManager;
88 };
89 
105 {
106  public :
108 
114  static bool IsValidUser(const QString &username);
115 
120  bool IsValidSession(const QString &sessionToken);
121 
128  MythUserSession GetSession(const QString &sessionToken);
129 
136  static QString GetPasswordDigest(const QString &username);
137 
146  MythUserSession LoginUser(const QString &username,
147  const QByteArray &digest,
148  const QString &client = "");
149 
158  MythUserSession LoginUser(const QString &username,
159  const QString &password,
160  const QString &client = "");
161 
167  static QByteArray CreateDigest(const QString &username,
168  const QString &password);
169 
178  static bool ManageDigestUser(DigestUserActions action,
179  const QString &username,
180  const QString &password,
181  const QString &newPassword,
182  const QString &adminPassword);
183 
184  private:
188  void LoadSessions(void);
189 
193  void UpdateSession(const QString &sessionToken);
194 
202  MythUserSession GetSession(const QString &username, const QString &client);
203 
207  MythUserSession CreateUserSession(uint userId, const QString &username,
208  const QString &client);
209 
213  void DestroyUserSession(const QString &sessionToken);
214 
215  static bool AddDigestUser(const QString &username,
216  const QString &password,
217  const QString &adminPassword);
218 
219  static bool RemoveDigestUser(const QString &username,
220  const QString &password);
221 
222  static bool ChangeDigestUserPassword(const QString &username,
223  const QString &oldPassword,
224  const QString &newPassword);
225 
226  QMap<QString, MythUserSession> m_sessionList;
227 };
228 
229 #endif // MYTHSESSION_H
MythUserSession::~MythUserSession
~MythUserSession()
Definition: mythsession.h:22
MythSessionManager::m_sessionList
QMap< QString, MythUserSession > m_sessionList
Definition: mythsession.h:226
mythbaseexp.h
MythUserSession::m_name
QString m_name
Definition: mythsession.h:77
MythUserSession
Definition: mythsession.h:18
MythUserSession::m_sessionLastActive
QDateTime m_sessionLastActive
Definition: mythsession.h:81
MythUserSession::m_sessionToken
QString m_sessionToken
Definition: mythsession.h:79
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
DigestUserActions
DigestUserActions
Definition: mythsession.h:12
MythUserSession::GetUserId
uint GetUserId(void) const
Definition: mythsession.h:42
MythUserSession::m_sessionExpires
QDateTime m_sessionExpires
Definition: mythsession.h:82
MythUserSession::GetSessionToken
QString GetSessionToken(void) const
Definition: mythsession.h:44
MythUserSession::m_permissionsList
QMap< QString, uint > m_permissionsList
Definition: mythsession.h:85
MythUserSession::GetSessionLastActive
QDateTime GetSessionLastActive() const
Definition: mythsession.h:48
MythUserSession::GetSessionExpires
QDateTime GetSessionExpires() const
Definition: mythsession.h:49
DIGEST_USER_ADD
@ DIGEST_USER_ADD
Definition: mythsession.h:13
MythUserSession::GetSessionCreated
QDateTime GetSessionCreated() const
Definition: mythsession.h:47
MythUserSession::m_sessionCreated
QDateTime m_sessionCreated
Definition: mythsession.h:80
DIGEST_USER_CHANGE_PW
@ DIGEST_USER_CHANGE_PW
Definition: mythsession.h:15
MythUserSession::m_sessionClient
QString m_sessionClient
Definition: mythsession.h:83
build_compdb.action
action
Definition: build_compdb.py:9
MythUserSession::GetSessionClient
QString GetSessionClient(void) const
Definition: mythsession.h:45
MythUserSession::GetUserName
QString GetUserName(void) const
Definition: mythsession.h:41
DIGEST_USER_REMOVE
@ DIGEST_USER_REMOVE
Definition: mythsession.h:14
uint
unsigned int uint
Definition: freesurround.h:24
MythSessionManager
Definition: mythsession.h:104