TreeFrogFramework  1.18
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 className () const
 
QString name () const
 
QString activeAction () const
 
const THttpRequesthttpRequest () const
 
const THttpResponsehttpResponse () const
 
QString getRenderingData (const QString &templateName, const QVariantMap &vars=QVariantMap())
 
const TSessionsession () const
 
virtual bool sessionEnabled () const
 
virtual bool csrfProtectionEnabled () const
 
virtual QStringList exceptionActionsOfCsrfProtection () const
 
virtual bool transactionEnabled () const
 
QByteArray authenticityToken () const
 
QString flash (const QString &name) const
 
QHostAddress clientAddress () const
 
virtual bool isUserLoggedIn () const
 
virtual QString identityKeyOfLoginUser () const
 
- Public Member Functions inherited from TAbstractController
 TAbstractController ()
 
virtual ~TAbstractController ()
 
- 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, qint64 arg) const
 
QUrl url (const QString &controller, const QString &action, quint64 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, qint64 arg) const
 
QUrl urla (const QString &action, quint64 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 ()
 

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 setFlash (const QString &name, const QVariant &value)
 
void setFlashValidationErrors (const TFormValidator &validator, const QString &prefix=QString("err_"))
 
TSessionsession ()
 
void setSession (const TSession &session)
 
bool addCookie (const TCookie &cookie)
 
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)
 
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 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)
 
int socketId () const
 
void sendTextToWebSocket (int sid, const QString &text)
 
void sendBinaryToWebSocket (int sid, const QByteArray &binary)
 
void closeWebSokcet (int sid, int closeCode=Tf::NormalClosure)
 
virtual bool userLogin (const TAbstractUser *user)
 
virtual void userLogout ()
 
virtual void setAccessRules ()
 
THttpRequesthttpRequest ()
 
THttpResponsehttpResponse ()
 
- Protected Member Functions inherited from TAbstractController
QVariant variant (const QString &name) const
 
void exportVariant (const QString &name, const QVariant &value, bool overwrite=true)
 
void exportValidationErrors (const TFormValidator &validator, const QString &prefix=QString("err_"))
 
bool hasVariant (const QString &name) const
 
void exportVariants (const QVariantMap &map)
 
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
 

Friends

class TActionContext
 
class TSessionCookieStore
 
class TDirectView
 

Additional Inherited Members

- Protected Attributes inherited from TAccessValidator
bool allowDefault
 
QList< AccessRuleaccessRules
 

Detailed Description

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

Constructor & Destructor Documentation

TActionController::TActionController ( )

Constructor.

TActionController::~TActionController ( )
inlinevirtual

Destructor.

Member Function Documentation

QString TActionController::activeAction ( ) const
inlinevirtual

Returns the active action name.

Implements TAbstractController.

bool TActionController::addCookie ( const TCookie cookie)
protected

Adds the cookie to the internal list of cookies.

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 
)
protected

Adds the cookie to the internal list of cookies.

QByteArray TActionController::authenticityToken ( ) const

Returns the authenticity token.

const QStringList & TActionController::availableControllers ( )
static

Returns the list of all available controllers.

QString TActionController::className ( ) const
inline

Returns the class name.

QHostAddress TActionController::clientAddress ( ) const

Returns the client address of the current session.

void TActionController::closeWebSokcet ( int  sid,
int  closeCode = Tf::NormalClosure 
)
protected
QByteArray TActionController::contentType ( ) const
inlineprotected

Returns the content type for a response message.

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()
const QStringList & TActionController::disabledControllers ( )
static
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()
QString TActionController::flash ( const QString &  name) const
inline

Returns the flash message for name.

See also
setFlash()
QString TActionController::getRenderingData ( const QString &  templateName,
const QVariantMap &  vars = QVariantMap() 
)

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

const THttpRequest & TActionController::httpRequest ( ) const

Returns the HTTP request being executed.

THttpRequest & TActionController::httpRequest ( )
protected

Returns the HTTP request being executed.

const THttpResponse & TActionController::httpResponse ( ) const
inline

Returns a HTTP response to be sent.

THttpResponse & TActionController::httpResponse ( )
inlineprotected

Returns a HTTP response to be sent.

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()
bool TActionController::isUserLoggedIn ( ) const
virtual

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

This is a virtual function.

See also
userLogin()
QString TActionController::layout ( ) const
inlineprotected

Returns the name of the layout template.

See also
setLayout()
bool TActionController::layoutEnabled ( ) const
inlineprotected

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

See also
setLayoutEnabled()
QString TActionController::loginUserNameKey ( )
static
QString TActionController::name ( ) const
virtual

Returns the controller name.

Implements TAbstractController.

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.

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.

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

Redirects to the URL url.

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

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

bool TActionController::renderErrorResponse ( int  statusCode)
protected

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

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

Renders the JSON document document as HTTP response.

This is available on Qt 5.

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

Renders the JSON object object as HTTP response.

This is available on Qt 5.

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

Renders the JSON array array as HTTP response.

This is available on Qt 5.

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

Renders the map as a JSON object.

This is available on Qt 5.

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

Renders the list as a JSON array.

This is available on Qt 5.

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

Renders the list as a JSON array.

This is available on Qt 5.

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

Renders the template given by templateName with the layout layout.

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

Renders the text text with the layout layout.

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

Renders the XML document document.

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

Renders the map as XML document.

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

Renders the list of variants list as XML document.

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

Renders the list of strings list as XML document.

void TActionController::rollbackTransaction ( )
inlineprotected

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

void TActionController::sendBinaryToWebSocket ( int  sid,
const QByteArray &  binary 
)
protected
bool TActionController::sendData ( const QByteArray &  data,
const QByteArray &  contentType,
const QString &  name = QString() 
)
protected

Sends the data data as HTTP response.

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

Sends the file filePath as HTTP response.

void TActionController::sendTextToWebSocket ( int  sid,
const QString &  text 
)
protected
const TSession & TActionController::session ( ) const
inline

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

See also
setSession(), sessionEnabled()
TSession & TActionController::session ( )
inlineprotected

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

See also
setSession(), 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()
void TActionController::setAccessRules ( )
inlineprotectedvirtual

Sets rules of access to this controller.

See also
validateAccess(), TAccessValidator
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.

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

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

void TActionController::setCsrfProtectionInto ( TSession session)
static

Sets CSRF protection informaion into session.

Internal use.

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

Sets the flash message of name to value.

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

Sets the validation errors to flash variant.

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

Sets the layout template to layout.

See also
layout()
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()
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()
void TActionController::setSession ( const TSession session)
protected

Sets the HTTP session to session.

void TActionController::setStatusCode ( int  code)
inlineprotected

Sets the status code to code.

See also
statusCode()
int TActionController::socketId ( ) const
inlineprotected
int TActionController::statusCode ( ) const
inlineprotected

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

See also
setStatusCode()
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.

bool TActionController::userLogin ( const TAbstractUser user)
protectedvirtual

Logs the user user in to the system.

This is a virtual function.

See also
userLogout()
void TActionController::userLogout ( )
protectedvirtual

Logs out of the system.

This is a virtual function.

See also
userLogin()
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

friend class TActionContext
friend
friend class TDirectView
friend
friend class TSessionCookieStore
friend

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