cutelyst  3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
session.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CSESSION_H
6 #define CSESSION_H
7 
8 #include <Cutelyst/cutelyst_global.h>
9 #include <Cutelyst/plugin.h>
10 
11 #include <QVariant>
12 
13 namespace Cutelyst {
14 
15 class Context;
16 class CUTELYST_PLUGIN_SESSION_EXPORT SessionStore : public QObject
17 {
18  Q_OBJECT
19 public:
23  explicit SessionStore(QObject *parent = nullptr);
24 
29  virtual QVariant getSessionData(Context *c,
30  const QString &sid,
31  const QString &key,
32  const QVariant &defaultValue = QVariant()) = 0;
33 
37  virtual bool storeSessionData(Context *c,
38  const QString &sid,
39  const QString &key,
40  const QVariant &value) = 0;
41 
45  virtual bool deleteSessionData(Context *c, const QString &sid, const QString &key) = 0;
46 
50  virtual bool deleteExpiredSessions(Context *c, quint64 expires) = 0;
51 };
52 
53 class SessionPrivate;
111 class CUTELYST_PLUGIN_SESSION_EXPORT Session : public Plugin
112 {
113  Q_OBJECT
114  Q_DECLARE_PRIVATE(Session)
115 public:
119  Session(Application *parent);
120  virtual ~Session();
121 
125  virtual bool setup(Application *app) final;
126 
130  void setStorage(SessionStore *store);
131 
135  SessionStore *storage() const;
136 
141  static QString id(Context *c);
142 
148  static quint64 expires(Context *c);
149 
155  static void changeExpires(Context *c, quint64 expires);
156 
163  static void deleteSession(Context *c, const QString &reason = QString());
164 
171  static QString deleteReason(Context *c);
172 
176  static QVariant
177  value(Context *c, const QString &key, const QVariant &defaultValue = QVariant());
178 
183  static void setValue(Context *c, const QString &key, const QVariant &value);
184 
188  static void deleteValue(Context *c, const QString &key);
189 
193  static void deleteValues(Context *c, const QStringList &keys);
194 
198  static bool isValid(Context *c);
199 
200 protected:
201  SessionPrivate *d_ptr;
202 
203 private:
204  Q_PRIVATE_SLOT(d_func(), void _q_saveSession(Context *))
205 };
206 
207 } // namespace Cutelyst
208 
209 #endif // CSESSION_H
The Cutelyst Context.
Definition: context.h:38
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
The Cutelyst Application.
Definition: application.h:42