cutelyst
4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Plugin providing methods for session management. More...
#include <Cutelyst/Plugins/Session/Session>
Public Member Functions | |
Session (Application *parent) | |
Session (Application *parent, const QVariantMap &defaultConfig) | |
virtual | ~Session () |
void | setStorage (std::unique_ptr< SessionStore > store) |
virtual bool | setup (Application *app) final |
SessionStore * | storage () const |
Public Member Functions inherited from Cutelyst::Plugin | |
Plugin (Application *parent) | |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
QBindable< QString > | bindableObjectName () |
bool | blockSignals (bool block) |
const QObjectList & | children () const const |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectInfo () const const |
void | dumpObjectTree () const const |
QList< QByteArray > | dynamicPropertyNames () const const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (Qt::FindChildOptions options) const const |
bool | inherits (const char *className) const const |
void | installEventFilter (QObject *filterObj) |
bool | isQuickItemType () const const |
bool | isWidgetType () const const |
bool | isWindowType () const const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
QVariant | property (const char *name) const const |
Q_CLASSINFO (Name, Value) | |
Q_EMIT Q_EMIT | |
Q_ENUM (...) | |
Q_ENUM_NS (...) | |
Q_ENUMS (...) | |
Q_FLAG (...) | |
Q_FLAG_NS (...) | |
Q_FLAGS (...) | |
Q_GADGET Q_GADGET | |
Q_GADGET_EXPORT (EXPORT_MACRO) | |
Q_INTERFACES (...) | |
Q_INVOKABLE Q_INVOKABLE | |
Q_MOC_INCLUDE Q_MOC_INCLUDE | |
Q_NAMESPACE Q_NAMESPACE | |
Q_NAMESPACE_EXPORT (EXPORT_MACRO) | |
Q_OBJECT Q_OBJECT | |
Q_PROPERTY (...) | |
Q_REVISION Q_REVISION | |
Q_SET_OBJECT_NAME (Object) | |
Q_SIGNAL Q_SIGNAL | |
Q_SIGNALS Q_SIGNALS | |
Q_SLOT Q_SLOT | |
Q_SLOTS Q_SLOTS | |
T | qobject_cast (const QObject *object) |
T | qobject_cast (QObject *object) |
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setObjectName (QAnyStringView name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | setProperty (const char *name, QVariant &&value) |
bool | signalsBlocked () const const |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType) |
QThread * | thread () const const |
Static Public Member Functions | |
static void | changeExpires (Context *c, quint64 expires) |
static QString | deleteReason (Context *c) |
static void | deleteSession (Context *c, const QString &reason=QString()) |
static void | deleteValue (Context *c, const QString &key) |
static void | deleteValues (Context *c, const QStringList &keys) |
static quint64 | expires (Context *c) |
static QByteArray | id (Context *c) |
static bool | isValid (Context *c) |
static void | setValue (Context *c, const QString &key, const QVariant &value) |
static QVariant | value (Context *c, const QString &key, const QVariant &defaultValue=QVariant()) |
Static Public Member Functions inherited from QObject | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
Additional Inherited Members | |
Public Attributes inherited from QObject | |
typedef | QObjectList |
Protected Member Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
bool | isSignalConnected (const QMetaMethod &signal) const const |
int | receivers (const char *signal) const const |
QObject * | sender () const const |
int | senderSignalIndex () const const |
virtual void | timerEvent (QTimerEvent *event) |
Properties inherited from QObject | |
objectName | |
The Session plugin manages user sessions and uses a SessionStore to store the session data. Cutelyst already ships with session stores to store sessions in the filesystem and on memcached servers. You can create your own session store by creating a new subclass of SessionStore and set it to this plugin using setStorage().
By default, if no session store has been manually set, a SessionStoreFile will be used.
There are some options you can set in your application configuration file in the Cutelyst_Session_Plugin
section. You can set your own default values using the defaultConfig parameter of the overloaded constructor.
Type: integer or string
Default: 2 hours
The expiration duration of the session. The value will be parsed by Utils::durationFromString() (since Cutelyst 4.0.0, before that, it took simple seconds), so you can use one of the supported human readable time spans.
Type: bool
Default: false
If true
, the plugin will check if the IP address of the requesting user matches the address stored in the session data. In case of a mismatch, the session will be deleted.
Type: bool
Default: false
If true
, the plugin will check if the user agent of the requesting user matches the user agent stored in the session data. In case of a mismatch, the session will be deleted.
Type: bool
Default: true
If true
, the session cookie will have the httpOnly flag set so that the cookie is not accessible to JavaScript’s Document.cookie API.
Type: bool
Default: false
If true
, the session cookie will have the secure flag set so that the cookie is only sent to the server with an encrypted request over the HTTPS protocol.
Type: string
Default: strict
Acceptable values: default,none,lax,strict
Defines the SameSite attribute of the session cookie. See MDN to learn more about SameSite cookies. Also have a look at QNetworkCookie::SameSite. This configuration key is available since Cutelyst 3.8.0.
Session::Session | ( | Cutelyst::Application * | parent | ) |
Constructs a new Session object with the given parent.
Definition at line 35 of file session.cpp.
Session::Session | ( | Cutelyst::Application * | parent, |
const QVariantMap & | defaultConfig | ||
) |
Constructs a new Session object with the given parent and defaultConfig.
Use the defaultConfig to set default values for the configuration entries from the configuration file.
Definition at line 41 of file session.cpp.
|
virtual |
Destroys the Session object.
Definition at line 48 of file session.cpp.
|
static |
Change the session expiration time for this session
Note that this only works to set the session longer than the config setting.
Definition at line 141 of file session.cpp.
References QDateTime::currentSecsSinceEpoch(), expires(), and id().
This method contains a string with the reason a session was deleted. Possible values include:
Definition at line 163 of file session.cpp.
References Cutelyst::Context::stash().
This method is used to invalidate a session. It takes an optional reason parameter which will be saved in deleteReason if provided.
Definition at line 154 of file session.cpp.
Removes the session key.
Definition at line 207 of file session.cpp.
References QVariant::isNull(), Cutelyst::Context::setStash(), Cutelyst::Context::stash(), and QVariant::toHash().
|
static |
Removes all session keys.
Definition at line 231 of file session.cpp.
References QVariant::isNull(), Cutelyst::Context::setStash(), Cutelyst::Context::stash(), and QVariant::toHash().
Referenced by Cutelyst::StatusMessage::load(), and Cutelyst::AuthenticationRealm::removePersistedUser().
|
static |
This method returns the time when the current session will expire, or 0 if there is no current session. If there is a session and it already expired, it will delete the session and return 0 as well.
Definition at line 121 of file session.cpp.
References Cutelyst::Context::stash().
Referenced by changeExpires().
|
static |
Returns the current session id or null if there is no current session
Definition at line 103 of file session.cpp.
References QVariant::isNull(), Cutelyst::Context::stash(), and QVariant::toByteArray().
Referenced by changeExpires().
|
static |
Returns true if the session is valid.
Definition at line 257 of file session.cpp.
void Session::setStorage | ( | std::unique_ptr< SessionStore > | store | ) |
Sets the session store. If no store has been set manually, a SessionStoreFile will be created.
Definition at line 89 of file session.cpp.
|
finalvirtual |
Sets up the plugin and loads the configuration.
Reimplemented from Cutelyst::Plugin.
Definition at line 53 of file session.cpp.
References Cutelyst::Application::afterDispatch(), QCoreApplication::applicationName, Qt::CaseInsensitive, QString::compare(), Cutelyst::Engine::config(), QObject::connect(), Cutelyst::Utils::durationFromString(), Cutelyst::Application::engine(), and Cutelyst::Application::postForked().
|
static |
Sets the value for session key to value. If the key already exists, the previous value is overwritten.
Definition at line 183 of file session.cpp.
References QVariant::isNull(), Cutelyst::Context::setStash(), Cutelyst::Context::stash(), QVariant::toHash(), and value().
Referenced by Cutelyst::StatusMessage::error(), Cutelyst::StatusMessage::errorQuery(), Cutelyst::AuthenticationRealm::persistUser(), Cutelyst::StatusMessage::status(), and Cutelyst::StatusMessage::statusQuery().
SessionStore * Session::storage | ( | ) | const |
Returns the session storage.
Definition at line 97 of file session.cpp.
|
static |
Returns the value for session key. If the session key doesn't exist, returns defaultValue.
Definition at line 168 of file session.cpp.
References QVariant::isNull(), Cutelyst::Context::stash(), and QVariant::toHash().
Referenced by Cutelyst::StatusMessage::load(), setValue(), and Cutelyst::AuthenticationRealm::userIsRestorable().