4#include <TAbstractController>
5#include <TAccessValidator>
6#include <TActionHelper>
9#include <THttpResponse>
10#include <TActionContext>
26 QString
name()
const override;
34 QString
getRenderingData(
const QString &templateName,
const QVariantMap &vars = QVariantMap())
override;
40 QString flash(
const QString &name)
const;
41 QHostAddress clientAddress()
const;
43 virtual QString identityKeyOfLoginUser()
const;
44 void setFlash(
const QString &name,
const QVariant &value)
override;
45 void reset()
override;
47 static void setCsrfProtectionInto(
TSession &session);
48 static const QStringList &availableControllers();
49 static const QStringList &disabledControllers();
50 static QString loginUserNameKey();
55 void setLayoutEnabled(
bool enable);
56 void setLayoutDisabled(
bool disable);
57 bool layoutEnabled()
const;
58 void setLayout(
const QString &layout);
59 QString layout()
const;
60 void setStatusCode(
int code);
62 void setFlashValidationErrors(
const TFormValidator &validator,
const QString &prefix = QString(
"err_"));
64 void setSession(
const TSession &session);
66 bool addCookie(
const QByteArray &name,
const QByteArray &value,
const QDateTime &expire = QDateTime(),
const QString &path = QString(),
const QString &domain = QString(),
bool secure =
false,
bool httpOnly =
false,
const QByteArray &sameSite =
"Lax")
override;
67 bool addCookie(
const QByteArray &name,
const QByteArray &value, int64_t maxAge,
const QString &path = QString(),
const QString &domain = QString(),
bool secure =
false,
bool httpOnly =
false,
const QByteArray &sameSite =
"Lax")
override;
68 QByteArray contentType()
const;
69 void setContentType(
const QByteArray &type);
70 bool render(
const QString &action = QString(),
const QString &layout = QString());
71 bool renderTemplate(
const QString &templateName,
const QString &layout = QString());
72 bool renderText(
const QString &text,
bool layoutEnable =
false,
const QString &layout = QString());
73 bool renderXml(
const QDomDocument &document);
74 bool renderXml(
const QVariantMap &map);
75 bool renderXml(
const QVariantList &list);
76 bool renderXml(
const QStringList &list);
77 bool renderJson(
const QJsonDocument &document);
78 bool renderJson(
const QJsonObject &
object);
79 bool renderJson(
const QJsonArray &array);
80 bool renderJson(
const QVariantMap &map);
81 bool renderJson(
const QVariantList &list);
82 bool renderJson(
const QStringList &list);
83 bool renderAndCache(
const QByteArray &key,
int seconds,
const QString &action = QString(),
const QString &layout = QString());
84 bool renderOnCache(
const QByteArray &key);
85 void removeCache(
const QByteArray &key);
86 bool renderCbor(
const QVariant &variant, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
87 bool renderCbor(
const QVariantMap &map, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
88 bool renderCbor(
const QVariantHash &hash, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
89 bool renderCbor(
const QCborValue &value, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
90 bool renderCbor(
const QCborMap &map, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
91 bool renderCbor(
const QCborArray &array, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
92 bool renderErrorResponse(
int statusCode);
93 void redirect(
const QUrl &url,
int statusCode =
Tf::Found);
94 bool sendFile(
const QString &filePath,
const QByteArray &contentType,
const QString &name = QString(),
bool autoRemove =
false);
95 bool sendData(
const QByteArray &data,
const QByteArray &contentType,
const QString &name = QString());
97 void setAutoRemove(
const QString &filePath);
100 void sendTextToWebSocket(
int socket,
const QString &text);
101 void sendBinaryToWebSocket(
int socket,
const QByteArray &binary);
103 void publish(
const QString &topic,
const QString &text);
104 void publish(
const QString &topic,
const QByteArray &binary);
105 void flushResponse();
108 virtual void userLogout();
116 enum WebSocketTaskType {
124 enum class RenderState {
130 void setActionName(
const QString &name);
131 void setArguments(
const QStringList &arguments) { _args =
arguments; }
134 void exportAllFlashVariants();
136 bool rollbackRequested()
const {
return _rollback; }
137 static QString layoutClassName(
const QString &layout);
138 static QString partialViewClassName(
const QString &partial);
140 mutable QString _ctrlName;
144 RenderState _rendered {RenderState::NotRendered};
145 bool _layoutEnable {
true};
148 QVariantMap _flashVars;
151 bool _rollback {
false};
152 QStringList _autoRemoveFiles;
153 QList<QPair<int, QVariant>> _taskList;
155 friend class TActionContext;
156 friend class TSessionCookieStore;
172inline void TActionController::setActionName(
const QString &name)
179 _layoutEnable = enable;
184 _layoutEnable = !disable;
189 return _layoutEnable;
204 return _flashVars.value(
name).toString();
The TAbstractController class is the abstract base class of controllers, providing functionality comm...
Definition tabstractcontroller.h:13
virtual QStringList arguments() const
Definition tabstractcontroller.h:20
virtual QString getRenderingData(const QString &templateName, const QVariantMap &vars=QVariantMap())
Definition tabstractcontroller.cpp:95
virtual void setFlash(const QString &name, const QVariant &value)
Definition tabstractcontroller.cpp:89
virtual bool addCookie(const TCookie &cookie)
Definition tabstractcontroller.cpp:125
virtual const THttpRequest & request() const
Definition tabstractcontroller.cpp:107
virtual QByteArray authenticityToken() const
Definition tabstractcontroller.h:25
virtual QString name() const =0
This function is reimplemented in subclasses to return a controller name.
virtual void reset()
Definition tabstractcontroller.h:39
virtual bool isUserLoggedIn() const
Returns true if a user is logged in to the system; otherwise returns false.
Definition tabstractcontroller.cpp:148
virtual QString activeAction() const =0
This function is reimplemented in subclasses to return a active action name.
The TAbstractUser class is the abstract base class of users, providing functionality common to users.
Definition tabstractuser.h:6
The TAccessValidator class provides validation of user access.
Definition taccessvalidator.h:11
The TActionController class is the base class of all action controllers.
Definition tactioncontroller.h:21
const THttpResponse & response() const
Definition tactioncontroller.h:31
void rollbackTransaction()
This function is called to rollback a transaction on the database.
Definition tactioncontroller.h:96
const THttpRequest & httpRequest() const override
Definition tactioncontroller.h:30
virtual void setAccessRules()
Sets rules of access to this controller.
Definition tactioncontroller.h:109
virtual void postFilter()
This function is called after actions on the controller are performed.
Definition tactioncontroller.h:54
THttpResponse & httpResponse()
Returns a HTTP response to be sent.
Definition tactioncontroller.h:113
void setStatusCode(int code)
Sets the status code to code.
Definition tactioncontroller.h:197
QString activeAction() const override
Returns the active action name.
Definition tactioncontroller.h:162
bool layoutEnabled() const
Returns true if the layout mechanism is enabled; otherwise returns false.
Definition tactioncontroller.h:187
const TSession & session() const override
Returns the current HTTP session, allows associating information with individual visitors.
Definition tactioncontroller.h:33
TSession & session() override
Returns the current HTTP session, allows associating information with individual visitors.
Definition tactioncontroller.h:63
QString name() const override
Returns the controller name.
Definition tactioncontroller.cpp:64
QStringList arguments() const override
Definition tactioncontroller.h:167
const THttpResponse & httpResponse() const
Returns a HTTP response to be sent.
Definition tactioncontroller.h:32
virtual bool transactionEnabled() const
Must be overridden by subclasses to disable transaction mechanism.
Definition tactioncontroller.h:38
QString flash(const QString &name) const
Returns the flash message for name.
Definition tactioncontroller.h:202
void setContentType(const QByteArray &type)
Sets the content type specified by type for a response message.
Definition tactioncontroller.h:212
virtual bool preFilter()
This function is called before actions on the controller are performed, therefore can be overridden b...
Definition tactioncontroller.h:53
void setLayoutDisabled(bool disable)
Disables the layout mechanism if disable is true, otherwise enables it.
Definition tactioncontroller.h:182
int statusCode() const
Returns the status code of the HTTP response to be sent.
Definition tactioncontroller.h:61
virtual bool sessionEnabled() const
Must be overridden by subclasses to enable a HTTP session.
Definition tactioncontroller.h:35
void setLayoutEnabled(bool enable)
Enables the layout mechanism if enable is true, otherwise disables it.
Definition tactioncontroller.h:177
virtual QStringList exceptionActionsOfCsrfProtection() const
Must be overridden by subclasses to return a string list of actions excluded from CSRF protection whe...
Definition tactioncontroller.h:37
QString layout() const
Returns the name of the layout template.
Definition tactioncontroller.h:192
QByteArray contentType() const
Returns the content type for a response message.
Definition tactioncontroller.h:207
virtual bool csrfProtectionEnabled() const
Must be overridden by subclasses to disable CSRF protection.
Definition tactioncontroller.h:36
THttpRequest & httpRequest()
Definition tactioncontroller.h:112
The TActionHelper class is the base class of all helpers.
Definition tactionhelper.h:12
virtual const TAbstractController * controller() const =0
The TActionView class is the abstract base class of views, providing functionality common to view.
Definition tactionview.h:14
The TCache class stores items so that can be served faster.
Definition tcache.h:7
The TCookieJar class holds network cookies.
Definition tcookiejar.h:12
The TCookie class holds one network cookie.
Definition tcookie.h:7
The THttpRequest class contains request information for HTTP.
Definition thttprequest.h:34
The THttpResponse class contains response information for HTTP.
Definition thttpresponse.h:10
THttpResponseHeader & header()
Return the HTTP header.
Definition thttpresponse.h:16
The TSession class holds information associated with individual visitors.
Definition tsession.h:7
@ OK
Definition tfnamespace.h:39
@ Found
Definition tfnamespace.h:49
@ NormalClosure
Definition tfnamespace.h:213
#define T_CORE_EXPORT
Definition tdeclexport.h:28
#define T_DISABLE_COPY(Class)
Definition tdeclexport.h:37
#define T_DISABLE_MOVE(Class)
Definition tdeclexport.h:41