TreeFrogFramework  2.8
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
TActionController Class Reference

#include <tactioncontroller.h>

Inheritance diagram for TActionController:
Inheritance graph
[legend]
Collaboration diagram for TActionController:
Collaboration graph
[legend]

Public Member Functions

 TActionController ()
 
virtual ~TActionController ()
 
QString name () const override
 
QString activeAction () const override
 
QStringList arguments () const override
 
const THttpRequestrequest () const override
 
const THttpRequesthttpRequest () const override
 
const THttpResponseresponse () const
 
const THttpResponsehttpResponse () const
 
const TSessionsession () const override
 
QString getRenderingData (const QString &templateName, const QVariantMap &vars=QVariantMap()) override
 
virtual bool sessionEnabled () const
 
virtual bool csrfProtectionEnabled () const
 
virtual QStringList exceptionActionsOfCsrfProtection () const
 
virtual bool transactionEnabled () const
 
QByteArray authenticityToken () const override
 
QString flash (const QString &name) const
 
QHostAddress clientAddress () const
 
virtual bool isUserLoggedIn () const override
 
virtual QString identityKeyOfLoginUser () const
 
void setFlash (const QString &name, const QVariant &value) override
 
void reset () override
 
- Public Member Functions inherited from TAbstractController
 TAbstractController ()
 
virtual ~TAbstractController ()
 
virtual QString className () const
 
void exportVariant (const QString &name, const QVariant &value, bool overwrite=true)
 
const TActionContext * context () const
 
TActionContext * context ()
 
void setContext (TActionContext *context)
 
- Public Member Functions inherited from TActionHelper
virtual ~TActionHelper ()
 
QUrl url (const QString &controller=QString(), const QString &action=QString(), const QStringList &args=QStringList(), const QVariantMap &query=QVariantMap()) const
 
QUrl url (const QString &controller, const QString &action, const QStringList &args, const QString &query) const
 
QUrl url (const QString &controller, const QString &action, int arg) const
 
QUrl url (const QString &controller, const QString &action, uint arg) const
 
QUrl url (const QString &controller, const QString &action, int64_t arg) const
 
QUrl url (const QString &controller, const QString &action, uint64_t arg) const
 
QUrl url (const QString &controller, const QString &action, const QString &arg) const
 
QUrl url (const QString &controller, const QString &action, const QVariant &arg) const
 
QUrl url (const QString &controller, const QString &action, const QVariantMap &query) const
 
QUrl urla (const QString &action=QString(), const QStringList &args=QStringList(), const QVariantMap &query=QVariantMap()) const
 
QUrl urla (const QString &action, const QStringList &args, const QString &query) const
 
QUrl urla (const QString &action, int arg) const
 
QUrl urla (const QString &action, uint arg) const
 
QUrl urla (const QString &action, int64_t arg) const
 
QUrl urla (const QString &action, uint64_t arg) const
 
QUrl urla (const QString &action, const QString &arg) const
 
QUrl urla (const QString &action, const QVariant &arg) const
 
QUrl urla (const QString &action, const QVariantMap &query) const
 
QUrl urlq (const QVariantMap &query) const
 
QUrl urlq (const QString &query) const
 

Static Public Member Functions

static void setCsrfProtectionInto (TSession &session)
 
static const QStringList & availableControllers ()
 
static const QStringList & disabledControllers ()
 
static QString loginUserNameKey ()
 
- Static Public Member Functions inherited from TAbstractController
static QThread * currentThread ()
 

Protected Member Functions

virtual bool preFilter ()
 
virtual void postFilter ()
 
void setLayoutEnabled (bool enable)
 
void setLayoutDisabled (bool disable)
 
bool layoutEnabled () const
 
void setLayout (const QString &layout)
 
QString layout () const
 
void setStatusCode (int code)
 
int statusCode () const
 
void setFlashValidationErrors (const TFormValidator &validator, const QString &prefix=QString("err_"))
 
TSessionsession () override
 
void setSession (const TSession &session)
 
bool addCookie (const TCookie &cookie) override
 
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
 
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
 
QByteArray contentType () const
 
void setContentType (const QByteArray &type)
 
bool render (const QString &action=QString(), const QString &layout=QString())
 
bool renderTemplate (const QString &templateName, const QString &layout=QString())
 
bool renderText (const QString &text, bool layoutEnable=false, const QString &layout=QString())
 
bool renderXml (const QDomDocument &document)
 
bool renderXml (const QVariantMap &map)
 
bool renderXml (const QVariantList &list)
 
bool renderXml (const QStringList &list)
 
bool renderJson (const QJsonDocument &document)
 
bool renderJson (const QJsonObject &object)
 
bool renderJson (const QJsonArray &array)
 
bool renderJson (const QVariantMap &map)
 
bool renderJson (const QVariantList &list)
 
bool renderJson (const QStringList &list)
 
bool renderAndCache (const QByteArray &key, int seconds, const QString &action=QString(), const QString &layout=QString())
 
bool renderOnCache (const QByteArray &key)
 
void removeCache (const QByteArray &key)
 
bool renderCbor (const QVariant &variant, QCborValue::EncodingOptions opt=QCborValue::NoTransformation)
 
bool renderCbor (const QVariantMap &map, QCborValue::EncodingOptions opt=QCborValue::NoTransformation)
 
bool renderCbor (const QVariantHash &hash, QCborValue::EncodingOptions opt=QCborValue::NoTransformation)
 
bool renderCbor (const QCborValue &value, QCborValue::EncodingOptions opt=QCborValue::NoTransformation)
 
bool renderCbor (const QCborMap &map, QCborValue::EncodingOptions opt=QCborValue::NoTransformation)
 
bool renderCbor (const QCborArray &array, QCborValue::EncodingOptions opt=QCborValue::NoTransformation)
 
bool renderErrorResponse (int statusCode)
 
void redirect (const QUrl &url, int statusCode=Tf::Found)
 
bool sendFile (const QString &filePath, const QByteArray &contentType, const QString &name=QString(), bool autoRemove=false)
 
bool sendData (const QByteArray &data, const QByteArray &contentType, const QString &name=QString())
 
void rollbackTransaction ()
 
void setAutoRemove (const QString &filePath)
 
bool validateAccess (const TAbstractUser *user)
 
void sendTextToWebSocket (int socket, const QString &text)
 
void sendBinaryToWebSocket (int socket, const QByteArray &binary)
 
void closeWebSokcet (int socket, int closeCode=Tf::NormalClosure)
 
void publish (const QString &topic, const QString &text)
 
void publish (const QString &topic, const QByteArray &binary)
 
void flushResponse ()
 
virtual bool userLogin (const TAbstractUser *user)
 
virtual void userLogout ()
 
virtual void setAccessRules ()
 
THttpRequestrequest ()
 
THttpRequesthttpRequest ()
 
THttpResponsehttpResponse ()
 
- Protected Member Functions inherited from TAbstractController
QVariant variant (const QString &name) const
 
void exportVariants (const QVariantMap &map)
 
void exportValidationErrors (const TFormValidator &validator, const QString &prefix=QString("err_"))
 
bool hasVariant (const QString &name) const
 
const QVariantMap & allVariants () const
 
QString viewClassName (const QString &action=QString()) const
 
QString viewClassName (const QString &contoller, const QString &action) const
 
- Protected Member Functions inherited from TAccessValidator
void addRules (int type, const QString &key, const QStringList &actions, bool allow)
 
 TAccessValidator ()
 
virtual ~TAccessValidator ()
 
void setAllowDefault (bool allow=true)
 
void setDenyDefault (bool deny=true)
 
void setAllowGroup (const QString &groupKey, const QString &action)
 
void setAllowGroup (const QString &groupKey, const QStringList &actions)
 
void setDenyGroup (const QString &groupKey, const QString &action)
 
void setDenyGroup (const QString &groupKey, const QStringList &actions)
 
void setAllowUser (const QString &identityKey, const QString &action)
 
void setAllowUser (const QString &identityKey, const QStringList &actions)
 
void setDenyUser (const QString &identityKey, const QString &action)
 
void setDenyUser (const QString &identityKey, const QStringList &actions)
 
void setAllowUnauthenticatedUser (const QString &action)
 
void setAllowUnauthenticatedUser (const QStringList &actions)
 
void setDenyUnauthenticatedUser (const QString &action)
 
void setDenyUnauthenticatedUser (const QStringList &actions)
 
void clear ()
 
virtual bool validate (const TAbstractUser *user, const TActionController *controller) const
 

Friends

class TActionContext
 
class TSessionCookieStore
 

Additional Inherited Members

- Protected Attributes inherited from TAccessValidator
bool allowDefault {true}
 
QList< AccessRuleaccessRules
 

Detailed Description

The TActionController class is the base class of all action controllers.

Constructor & Destructor Documentation

◆ TActionController()

TActionController::TActionController ( )

Constructor.

◆ ~TActionController()

TActionController::~TActionController ( )
virtual

Destructor.

Member Function Documentation

◆ activeAction()

QString TActionController::activeAction ( ) const
inlineoverridevirtual

Returns the active action name.

Implements TAbstractController.

◆ addCookie() [1/3]

bool TActionController::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" 
)
overrideprotectedvirtual

Adds the cookie to the internal list of cookies.

Reimplemented from TAbstractController.

◆ addCookie() [2/3]

bool TActionController::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" 
)
overrideprotectedvirtual

Reimplemented from TAbstractController.

◆ addCookie() [3/3]

bool TActionController::addCookie ( const TCookie cookie)
overrideprotectedvirtual

Adds the cookie to the internal list of cookies.

Reimplemented from TAbstractController.

◆ arguments()

QStringList TActionController::arguments ( ) const
inlineoverridevirtual

Reimplemented from TAbstractController.

◆ authenticityToken()

QByteArray TActionController::authenticityToken ( ) const
overridevirtual

Returns the authenticity token.

Reimplemented from TAbstractController.

◆ availableControllers()

const QStringList & TActionController::availableControllers ( )
static

Returns the list of all available controllers.

◆ clientAddress()

QHostAddress TActionController::clientAddress ( ) const

Returns the client address of the current session.

◆ closeWebSokcet()

void TActionController::closeWebSokcet ( int  socket,
int  closeCode = Tf::NormalClosure 
)
protected

◆ contentType()

QByteArray TActionController::contentType ( ) const
inlineprotected

Returns the content type for a response message.

◆ csrfProtectionEnabled()

bool TActionController::csrfProtectionEnabled ( ) const
inlinevirtual

Must be overridden by subclasses to disable CSRF protection.

The function must return false to disable the protection. This function returns true.

See also
exceptionActionsOfCsrfProtection()

◆ disabledControllers()

const QStringList & TActionController::disabledControllers ( )
static

◆ exceptionActionsOfCsrfProtection()

QStringList TActionController::exceptionActionsOfCsrfProtection ( ) const
inlinevirtual

Must be overridden by subclasses to return a string list of actions excluded from CSRF protection when the protection is enabled.

See also
csrfProtectionEnabled()

◆ flash()

QString TActionController::flash ( const QString &  name) const
inline

Returns the flash message for name.

See also
setFlash()

◆ flushResponse()

void TActionController::flushResponse ( )
protected

Sends a response immediately, and then allows time-consuming processing to continue in the controller.

◆ getRenderingData()

QString TActionController::getRenderingData ( const QString &  templateName,
const QVariantMap &  vars = QVariantMap() 
)
overridevirtual

Returns the rendering data of the partial template given by templateName.

Reimplemented from TAbstractController.

◆ httpRequest() [1/2]

THttpRequest& TActionController::httpRequest ( )
inlineprotected

◆ httpRequest() [2/2]

const THttpRequest& TActionController::httpRequest ( ) const
inlineoverridevirtual

Reimplemented from TAbstractController.

◆ httpResponse() [1/2]

THttpResponse & TActionController::httpResponse ( )
inlineprotected

Returns a HTTP response to be sent.

◆ httpResponse() [2/2]

const THttpResponse & TActionController::httpResponse ( ) const
inline

Returns a HTTP response to be sent.

◆ identityKeyOfLoginUser()

QString TActionController::identityKeyOfLoginUser ( ) const
virtual

Returns the identity key of the user, i.e., TAbstractUser object, logged in.

This is a virtual function.

See also
userLogin()

◆ isUserLoggedIn()

bool TActionController::isUserLoggedIn ( ) const
overridevirtual

Returns true if a user is logged in to the system; otherwise returns false.

This is a virtual function.

See also
userLogin()

Reimplemented from TAbstractController.

◆ layout()

QString TActionController::layout ( ) const
inlineprotected

Returns the name of the layout template.

See also
setLayout()

◆ layoutEnabled()

bool TActionController::layoutEnabled ( ) const
inlineprotected

Returns true if the layout mechanism is enabled; otherwise returns false.

See also
setLayoutEnabled()

◆ loginUserNameKey()

QString TActionController::loginUserNameKey ( )
static

◆ name()

QString TActionController::name ( ) const
overridevirtual

Returns the controller name.

Implements TAbstractController.

◆ postFilter()

void TActionController::postFilter ( )
inlineprotectedvirtual

This function is called after actions on the controller are performed.

Can be overridden by subclasses (controllers) in order to post-processing of actions on the controller.

◆ preFilter()

bool TActionController::preFilter ( )
inlineprotectedvirtual

This function is called before actions on the controller are performed, therefore can be overridden by subclasses (controllers) to filter a HTTP request.

If the function returns false, a action on the controller is not executed.

◆ publish() [1/2]

void TActionController::publish ( const QString &  topic,
const QByteArray &  binary 
)
protected

◆ publish() [2/2]

void TActionController::publish ( const QString &  topic,
const QString &  text 
)
protected

◆ redirect()

void TActionController::redirect ( const QUrl &  url,
int  statusCode = Tf::Found 
)
protected

Redirects to the URL url.

◆ removeCache()

void TActionController::removeCache ( const QByteArray &  key)
protected

Removes the template with the key from the cache.

See also
renderAndCache()
renderOnCache()

◆ render()

bool TActionController::render ( const QString &  action = QString(),
const QString &  layout = QString() 
)
protected

Renders the template of the action action with the layout layout.

◆ renderAndCache()

bool TActionController::renderAndCache ( const QByteArray &  key,
int  seconds,
const QString &  action = QString(),
const QString &  layout = QString() 
)
protected

Renders the template of the action with the layout and caches it with the key for seconds.

To use this function, enable cache module in application.ini.

See also
render()
renderOnCache()
removeCache()

◆ renderCbor() [1/6]

bool TActionController::renderCbor ( const QCborArray &  array,
QCborValue::EncodingOptions  opt = QCborValue::NoTransformation 
)
protected

Renders a CBOR array as HTTP response.

◆ renderCbor() [2/6]

bool TActionController::renderCbor ( const QCborMap &  map,
QCborValue::EncodingOptions  opt = QCborValue::NoTransformation 
)
protected

Renders a CBOR map as HTTP response.

◆ renderCbor() [3/6]

bool TActionController::renderCbor ( const QCborValue &  value,
QCborValue::EncodingOptions  opt = QCborValue::NoTransformation 
)
protected

Renders a CBOR value as HTTP response.

◆ renderCbor() [4/6]

bool TActionController::renderCbor ( const QVariant &  variant,
QCborValue::EncodingOptions  opt = QCborValue::NoTransformation 
)
protected

Renders a CBOR object variant as HTTP response.

◆ renderCbor() [5/6]

bool TActionController::renderCbor ( const QVariantHash &  hash,
QCborValue::EncodingOptions  opt = QCborValue::NoTransformation 
)
protected

Renders a CBOR object hash as HTTP response.

◆ renderCbor() [6/6]

bool TActionController::renderCbor ( const QVariantMap &  map,
QCborValue::EncodingOptions  opt = QCborValue::NoTransformation 
)
protected

Renders a CBOR object map as HTTP response.

◆ renderErrorResponse()

bool TActionController::renderErrorResponse ( int  statusCode)
protected

Renders a static error page with the status code, which page is [statusCode].html in the public directory.

◆ renderJson() [1/6]

bool TActionController::renderJson ( const QJsonArray &  array)
protected

Renders the JSON array array as HTTP response.

◆ renderJson() [2/6]

bool TActionController::renderJson ( const QJsonDocument &  document)
protected

Renders the JSON document document as HTTP response.

◆ renderJson() [3/6]

bool TActionController::renderJson ( const QJsonObject &  object)
protected

Renders the JSON object object as HTTP response.

◆ renderJson() [4/6]

bool TActionController::renderJson ( const QStringList &  list)
protected

Renders the list as a JSON array.

◆ renderJson() [5/6]

bool TActionController::renderJson ( const QVariantList &  list)
protected

Renders the list as a JSON array.

◆ renderJson() [6/6]

bool TActionController::renderJson ( const QVariantMap &  map)
protected

Renders the map as a JSON object.

◆ renderOnCache()

bool TActionController::renderOnCache ( const QByteArray &  key)
protected

Renders the template cached with the key.

If no item with the key found, returns false. To use this function, enable cache module in application.ini.

See also
renderAndCache()

◆ renderTemplate()

bool TActionController::renderTemplate ( const QString &  templateName,
const QString &  layout = QString() 
)
protected

Renders the template given by templateName with the layout layout.

◆ renderText()

bool TActionController::renderText ( const QString &  text,
bool  layoutEnable = false,
const QString &  layout = QString() 
)
protected

Renders the text text with the layout layout.

◆ renderXml() [1/4]

bool TActionController::renderXml ( const QDomDocument &  document)
protected

Renders the XML document document.

◆ renderXml() [2/4]

bool TActionController::renderXml ( const QStringList &  list)
protected

Renders the list of strings list as XML document.

◆ renderXml() [3/4]

bool TActionController::renderXml ( const QVariantList &  list)
protected

Renders the list of variants list as XML document.

◆ renderXml() [4/4]

bool TActionController::renderXml ( const QVariantMap &  map)
protected

Renders the map as XML document.

◆ request() [1/2]

THttpRequest & TActionController::request ( )
protected

Returns the HTTP request being executed.

◆ request() [2/2]

const THttpRequest & TActionController::request ( ) const
overridevirtual

Returns the HTTP request being executed.

Reimplemented from TAbstractController.

◆ reset()

void TActionController::reset ( )
overridevirtual

Reimplemented from TAbstractController.

◆ response()

const THttpResponse& TActionController::response ( ) const
inline

◆ rollbackTransaction()

void TActionController::rollbackTransaction ( )
inlineprotected

This function is called to rollback a transaction on the database.

◆ sendBinaryToWebSocket()

void TActionController::sendBinaryToWebSocket ( int  socket,
const QByteArray &  binary 
)
protected

◆ sendData()

bool TActionController::sendData ( const QByteArray &  data,
const QByteArray &  contentType,
const QString &  name = QString() 
)
protected

Sends the data data as HTTP response.

◆ sendFile()

bool TActionController::sendFile ( const QString &  filePath,
const QByteArray &  contentType,
const QString &  name = QString(),
bool  autoRemove = false 
)
protected

Sends the file filePath as HTTP response.

◆ sendTextToWebSocket()

void TActionController::sendTextToWebSocket ( int  socket,
const QString &  text 
)
protected

◆ session() [1/2]

const TSession & TActionController::session ( ) const
inlineoverridevirtual

Returns the current HTTP session, allows associating information with individual visitors.

See also
setSession(), sessionEnabled()

Reimplemented from TAbstractController.

◆ session() [2/2]

TSession & TActionController::session ( )
inlineoverrideprotectedvirtual

Returns the current HTTP session, allows associating information with individual visitors.

See also
setSession(), sessionEnabled()

Reimplemented from TAbstractController.

◆ sessionEnabled()

bool TActionController::sessionEnabled ( ) const
inlinevirtual

Must be overridden by subclasses to enable a HTTP session.

The function must return false to disable a session. This function returns true.

See also
session()

◆ setAccessRules()

void TActionController::setAccessRules ( )
inlineprotectedvirtual

Sets rules of access to this controller.

See also
validateAccess(), TAccessValidator

◆ setAutoRemove()

void TActionController::setAutoRemove ( const QString &  filePath)
protected

Sets the automatically removing file.

The file filePath is removed when the context is extinguished, after replied the HTTP response.

◆ setContentType()

void TActionController::setContentType ( const QByteArray &  type)
inlineprotected

Sets the content type specified by type for a response message.

◆ setCsrfProtectionInto()

void TActionController::setCsrfProtectionInto ( TSession session)
static

Sets CSRF protection informaion into session.

Internal use.

◆ setFlash()

void TActionController::setFlash ( const QString &  name,
const QVariant &  value 
)
overridevirtual

Sets the flash message of name to value.

See also
flash()

Reimplemented from TAbstractController.

◆ setFlashValidationErrors()

void TActionController::setFlashValidationErrors ( const TFormValidator validator,
const QString &  prefix = QString("err_") 
)
protected

Sets the validation errors to flash variant.

◆ setLayout()

void TActionController::setLayout ( const QString &  layout)
protected

Sets the layout template to layout.

See also
layout()

◆ setLayoutDisabled()

void TActionController::setLayoutDisabled ( bool  disable)
inlineprotected

Disables the layout mechanism if disable is true, otherwise enables it.

By default the layout mechanism is enabled, and a HTML response is generated with using the current layout.

See also
layoutEnabled()

◆ setLayoutEnabled()

void TActionController::setLayoutEnabled ( bool  enable)
inlineprotected

Enables the layout mechanism if enable is true, otherwise disables it.

By default the layout mechanism is enabled, and a HTML response is generated with using the current layout.

See also
layoutEnabled()

◆ setSession()

void TActionController::setSession ( const TSession session)
protected

Sets the HTTP session to session.

◆ setStatusCode()

void TActionController::setStatusCode ( int  code)
inlineprotected

Sets the status code to code.

See also
statusCode()

◆ statusCode()

int TActionController::statusCode ( ) const
inlineprotected

Returns the status code of the HTTP response to be sent.

See also
setStatusCode()

◆ transactionEnabled()

bool TActionController::transactionEnabled ( ) const
inlinevirtual

Must be overridden by subclasses to disable transaction mechanism.

The function must return false to disable the mechanism. This function returns true.

◆ userLogin()

bool TActionController::userLogin ( const TAbstractUser user)
protectedvirtual

Logs the user user in to the system.

This is a virtual function.

See also
userLogout()

◆ userLogout()

void TActionController::userLogout ( )
protectedvirtual

Logs out of the system.

This is a virtual function.

See also
userLogin()

◆ validateAccess()

bool TActionController::validateAccess ( const TAbstractUser user)
protected

Validates the access of the user user.

Returns true if the user access is allowed by rule; otherwise returns false.

See also
setAccessRules(), TAccessValidator::validate()

Friends And Related Function Documentation

◆ TActionContext

friend class TActionContext
friend

◆ TSessionCookieStore

friend class TSessionCookieStore
friend

The documentation for this class was generated from the following files: