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 <QString>
7 #include <QDateTime>
8 #include <QMap>
9 
14 };
15 
17 {
18  public :
19  MythUserSession() = default;
20  ~MythUserSession() { m_sessionToken.fill('0'); m_sessionToken.clear(); }
21  MythUserSession(const MythUserSession &) = default;
22  MythUserSession(MythUserSession&& other) = default;
23  MythUserSession &operator=(const MythUserSession &) = default;
24  MythUserSession& operator=(MythUserSession&& other) = default;
25 
37  bool IsValid(void) const;
38 
39  QString GetUserName(void) const { return m_name; }
40  uint GetUserId(void) const { return m_userId; }
41 
42  QString GetSessionToken(void) const { return m_sessionToken; }
43  QString GetSessionClient(void) const { return m_sessionClient; }
44 
45  QDateTime GetSessionCreated() const { return m_sessionCreated; }
46  QDateTime GetSessionLastActive() const { return m_sessionLastActive; }
47  QDateTime GetSessionExpires() const { return m_sessionExpires; }
48 
57  bool CheckPermission( const QString &context, uint permission);
58 
59  protected:
67  bool Save(void);
68 
72  bool Update(void);
73 
74  uint m_userId {0};
75  QString m_name;
76 
77  QString m_sessionToken;
78  QDateTime m_sessionCreated;
79  QDateTime m_sessionLastActive; // For informational purposes
80  QDateTime m_sessionExpires;
81  QString m_sessionClient;
82 
83  QMap<QString, uint> m_permissionsList; // Context, flags
84 
85  friend class MythSessionManager;
86 };
87 
103 {
104  public :
106 
112  static bool IsValidUser(const QString &username);
113 
118  bool IsValidSession(const QString &sessionToken);
119 
126  MythUserSession GetSession(const QString &sessionToken);
127 
134  static QString GetPasswordDigest(const QString &username);
135 
144  MythUserSession LoginUser(const QString &username,
145  const QByteArray &digest,
146  const QString &client = "");
147 
156  MythUserSession LoginUser(const QString &username,
157  const QString &password,
158  const QString &client = "");
159 
165  static QByteArray CreateDigest(const QString &username,
166  const QString &password);
167 
176  static bool ManageDigestUser(DigestUserActions action,
177  const QString &username,
178  const QString &password,
179  const QString &newPassword,
180  const QString &adminPassword);
181 
182  private:
186  void LoadSessions(void);
187 
191  void UpdateSession(const QString &sessionToken);
192 
200  MythUserSession GetSession(const QString &username, const QString &client);
201 
205  MythUserSession CreateUserSession(uint userId, const QString &username,
206  const QString &client);
207 
211  void DestroyUserSession(const QString &sessionToken);
212 
213  static bool AddDigestUser(const QString &username,
214  const QString &password,
215  const QString &adminPassword);
216 
217  static bool RemoveDigestUser(const QString &username,
218  const QString &password);
219 
220  static bool ChangeDigestUserPassword(const QString &username,
221  const QString &oldPassword,
222  const QString &newPassword);
223 
224  QMap<QString, MythUserSession> m_sessionList;
225 };
226 
227 #endif // MYTHSESSION_H
MythUserSession::~MythUserSession
~MythUserSession()
Definition: mythsession.h:20
DIGEST_USER_CHANGE_PW
@ DIGEST_USER_CHANGE_PW
Definition: mythsession.h:13
MythSessionManager::m_sessionList
QMap< QString, MythUserSession > m_sessionList
Definition: mythsession.h:224
mythbaseexp.h
MythUserSession::m_name
QString m_name
Definition: mythsession.h:75
MythUserSession
Definition: mythsession.h:16
MythUserSession::m_sessionLastActive
QDateTime m_sessionLastActive
Definition: mythsession.h:79
MythUserSession::m_sessionToken
QString m_sessionToken
Definition: mythsession.h:77
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythUserSession::GetUserId
uint GetUserId(void) const
Definition: mythsession.h:40
MythUserSession::m_sessionExpires
QDateTime m_sessionExpires
Definition: mythsession.h:80
DigestUserActions
DigestUserActions
Definition: mythsession.h:10
MythUserSession::GetSessionToken
QString GetSessionToken(void) const
Definition: mythsession.h:42
MythUserSession::m_permissionsList
QMap< QString, uint > m_permissionsList
Definition: mythsession.h:83
uint
unsigned int uint
Definition: compat.h:81
DIGEST_USER_REMOVE
@ DIGEST_USER_REMOVE
Definition: mythsession.h:12
MythUserSession::GetSessionLastActive
QDateTime GetSessionLastActive() const
Definition: mythsession.h:46
MythUserSession::GetSessionExpires
QDateTime GetSessionExpires() const
Definition: mythsession.h:47
MythUserSession::GetSessionCreated
QDateTime GetSessionCreated() const
Definition: mythsession.h:45
MythUserSession::m_sessionCreated
QDateTime m_sessionCreated
Definition: mythsession.h:78
MythUserSession::m_sessionClient
QString m_sessionClient
Definition: mythsession.h:81
build_compdb.action
action
Definition: build_compdb.py:9
DIGEST_USER_ADD
@ DIGEST_USER_ADD
Definition: mythsession.h:11
MythUserSession::GetSessionClient
QString GetSessionClient(void) const
Definition: mythsession.h:43
MythUserSession::GetUserName
QString GetUserName(void) const
Definition: mythsession.h:39
MythSessionManager
Definition: mythsession.h:102