cutelyst 4.3.0
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
19namespace Cutelyst {
20
21class Context;
35class CUTELYST_PLUGIN_SESSION_EXPORT SessionStore : public QObject
36{
37 Q_OBJECT
38public:
42 explicit SessionStore(QObject *parent = nullptr);
43
49 const QByteArray &sid,
50 const QString &key,
51 const QVariant &defaultValue = QVariant()) = 0;
52
56 virtual bool storeSessionData(Context *c,
57 const QByteArray &sid,
58 const QString &key,
59 const QVariant &value) = 0;
60
64 virtual bool deleteSessionData(Context *c, const QByteArray &sid, const QString &key) = 0;
65
69 virtual bool deleteExpiredSessions(Context *c, quint64 expires) = 0;
70};
71
72class SessionPrivate;
160class CUTELYST_PLUGIN_SESSION_EXPORT Session : public Plugin
161{
162 Q_OBJECT
163 Q_DECLARE_PRIVATE(Session)
164public:
168 Session(Application *parent);
169
178 Session(Application *parent, const QVariantMap &defaultConfig);
179
183 virtual ~Session();
184
188 virtual bool setup(Application *app) final;
189
194 void setStorage(std::unique_ptr<SessionStore> store);
195
199 SessionStore *storage() const;
200
205 static QByteArray id(Context *c);
206
212 static quint64 expires(Context *c);
213
219 static void changeExpires(Context *c, quint64 expires);
220
227 static void deleteSession(Context *c, const QString &reason = QString());
228
235 static QString deleteReason(Context *c);
236
241 static QVariant
242 value(Context *c, const QString &key, const QVariant &defaultValue = QVariant());
243
248 static void setValue(Context *c, const QString &key, const QVariant &value);
249
253 static void deleteValue(Context *c, const QString &key);
254
258 static void deleteValues(Context *c, const QStringList &keys);
259
263 static bool isValid(Context *c);
264
265protected:
266 SessionPrivate *d_ptr;
267
268private:
269 Q_PRIVATE_SLOT(d_func(), void _q_saveSession(Context *))
270};
271
272} // namespace Cutelyst
273
274#endif // CSESSION_H
The Cutelyst application.
Definition application.h:66
The Cutelyst Context.
Definition context.h:42
Base class for Cutelyst Plugins.
Definition plugin.h:25
Abstract class to create a session store.
Definition session.h:36
virtual bool deleteSessionData(Context *c, const QByteArray &sid, const QString &key)=0
virtual bool deleteExpiredSessions(Context *c, quint64 expires)=0
virtual QVariant getSessionData(Context *c, const QByteArray &sid, const QString &key, const QVariant &defaultValue=QVariant())=0
virtual bool storeSessionData(Context *c, const QByteArray &sid, const QString &key, const QVariant &value)=0
Plugin providing methods for session management.
Definition session.h:161
The Cutelyst namespace holds all public Cutelyst API.