2 #include <QHostAddress>
4 #include <TAbstractController>
5 #include <TAccessValidator>
6 #include <TActionHelper>
8 #include <THttpRequest>
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 #if QT_VERSION >= 0x050c00
87 bool renderCbor(
const QVariant &variant, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
88 bool renderCbor(
const QVariantMap &map, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
89 bool renderCbor(
const QVariantHash &hash, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
90 bool renderCbor(
const QCborValue &value, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
91 bool renderCbor(
const QCborMap &map, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
92 bool renderCbor(
const QCborArray &array, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
94 bool renderErrorResponse(
int statusCode);
95 void redirect(
const QUrl &url,
int statusCode =
Tf::Found);
96 bool sendFile(
const QString &filePath,
const QByteArray &contentType,
const QString &name = QString(),
bool autoRemove =
false);
97 bool sendData(
const QByteArray &data,
const QByteArray &contentType,
const QString &name = QString());
99 void setAutoRemove(
const QString &filePath);
102 void sendTextToWebSocket(
int socket,
const QString &text);
103 void sendBinaryToWebSocket(
int socket,
const QByteArray &binary);
105 void publish(
const QString &topic,
const QString &text);
106 void publish(
const QString &topic,
const QByteArray &binary);
107 void flushResponse();
110 virtual void userLogout();
118 enum WebSocketTaskType {
126 enum class RenderState {
132 void setActionName(
const QString &name);
133 void setArguments(
const QStringList &arguments) { _args =
arguments; }
136 void exportAllFlashVariants();
138 bool rollbackRequested()
const {
return _rollback; }
139 static QString layoutClassName(
const QString &layout);
140 static QString partialViewClassName(
const QString &partial);
142 mutable QString _ctrlName;
146 RenderState _rendered {RenderState::NotRendered};
147 bool _layoutEnable {
true};
150 QVariantMap _flashVars;
153 bool _rollback {
false};
154 QStringList _autoRemoveFiles;
155 QList<QPair<int, QVariant>> _taskList;
157 friend class TActionContext;
158 friend class TSessionCookieStore;
174 inline void TActionController::setActionName(
const QString &name)
181 _layoutEnable = enable;
186 _layoutEnable = !disable;
191 return _layoutEnable;
206 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:99
virtual void setFlash(const QString &name, const QVariant &value)
Definition: tabstractcontroller.cpp:93
virtual bool addCookie(const TCookie &cookie)
Definition: tabstractcontroller.cpp:129
virtual const THttpRequest & request() const
Definition: tabstractcontroller.cpp:111
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:152
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
void rollbackTransaction()
This function is called to rollback a transaction on the database.
Definition: tactioncontroller.h:98
virtual void setAccessRules()
Sets rules of access to this controller.
Definition: tactioncontroller.h:111
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:115
void setStatusCode(int code)
Sets the status code to code.
Definition: tactioncontroller.h:199
QString activeAction() const override
Returns the active action name.
Definition: tactioncontroller.h:164
bool layoutEnabled() const
Returns true if the layout mechanism is enabled; otherwise returns false.
Definition: tactioncontroller.h:189
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
const THttpResponse & response() const
Definition: tactioncontroller.h:31
QString name() const override
Returns the controller name.
Definition: tactioncontroller.cpp:66
QStringList arguments() const override
Definition: tactioncontroller.h:169
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
THttpRequest & httpRequest()
Definition: tactioncontroller.h:114
QString flash(const QString &name) const
Returns the flash message for name.
Definition: tactioncontroller.h:204
void setContentType(const QByteArray &type)
Sets the content type specified by type for a response message.
Definition: tactioncontroller.h:214
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:184
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
const THttpRequest & httpRequest() const override
Definition: tactioncontroller.h:30
void setLayoutEnabled(bool enable)
Enables the layout mechanism if enable is true, otherwise disables it.
Definition: tactioncontroller.h:179
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:194
QByteArray contentType() const
Returns the content type for a response message.
Definition: tactioncontroller.h:209
virtual bool csrfProtectionEnabled() const
Must be overridden by subclasses to disable CSRF protection.
Definition: tactioncontroller.h:36
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