Wt  3.7.1
Public Member Functions | Static Public Attributes | List of all members
Wt::Auth::AuthModel Class Reference

Model for implementing an authentication view. More...

#include <Wt/Auth/AuthModel>

Inheritance diagram for Wt::Auth::AuthModel:
Inheritance graph
[legend]

Public Member Functions

 AuthModel (const AuthService &baseAuth, AbstractUserDatabase &users, WObject *parent=0)
 Constructor. More...
 
virtual void reset ()
 Resets the model. More...
 
virtual bool isVisible (Field field) const
 Returns whether a field is visible. More...
 
virtual bool validateField (Field field)
 Validates a field. More...
 
virtual bool validate ()
 Validates the current input. More...
 
virtual void configureThrottling (WInteractWidget *button)
 Initializes client-side login throttling. More...
 
virtual void updateThrottling (WInteractWidget *button)
 Updates client-side login throttling. More...
 
virtual bool login (Login &login)
 Logs the user in. More...
 
virtual void logout (Login &login)
 Logs the user out. More...
 
virtual EmailTokenResult processEmailToken (const std::string &token)
 Processes an email token. More...
 
virtual void setRememberMeCookie (const User &user)
 Creates a token and stores it in a cookie. More...
 
virtual User processAuthToken ()
 Detects and processes an authentication token. More...
 
- Public Member Functions inherited from Wt::Auth::FormBaseModel
 FormBaseModel (const AuthService &baseAuth, AbstractUserDatabase &users, WObject *parent=0)
 Constructor.
 
const AuthServicebaseAuth () const
 Returns the authentication base service. More...
 
AbstractUserDatabaseusers ()
 Returns the user database.
 
virtual void addPasswordAuth (const AbstractPasswordService *auth)
 Adds a password authentication service. More...
 
const AbstractPasswordServicepasswordAuth () const
 Returns the password authentication service. More...
 
virtual void addOAuth (const OAuthService *auth)
 Adds an OAuth authentication service provider. More...
 
virtual void addOAuth (const std::vector< const OAuthService *> &auth)
 Adds a list of OAuth authentication service providers. More...
 
std::vector< const OAuthService * > oAuth () const
 Returns the list of OAuth authentication service providers. More...
 
virtual WString label (Field field) const
 Returns a field label. More...
 
virtual bool loginUser (Login &login, User &user, LoginState state=StrongLogin)
 Logs the user in. More...
 
- Public Member Functions inherited from Wt::WFormModel
 WFormModel (WObject *parent=0)
 Constructor. More...
 
void addField (Field field, const WString &info=WString::Empty)
 Adds a field. More...
 
void removeField (Field field)
 Removes a field. More...
 
std::vector< Fieldfields () const
 Returns the fields. More...
 
bool valid () const
 Returns the current overall validation state. More...
 
void setVisible (Field field, bool visible)
 Sets whether a field is visible. More...
 
void setReadOnly (Field field, bool readOnly)
 Sets whether a field is read-only. More...
 
virtual bool isReadOnly (Field field) const
 Returns whether a field is read only. More...
 
virtual void setValue (Field field, const boost::any &value)
 Sets the field value. More...
 
virtual const boost::any & value (Field field) const
 Returns the field value. More...
 
virtual WString valueText (Field field) const
 Returns the field value text. More...
 
virtual void setValidator (Field field, WValidator *validator)
 Sets a validator. More...
 
virtual WValidatorvalidator (Field field) const
 Returns a validator. More...
 
virtual void setValidated (Field field, bool validated)
 Sets whether a field has been validated. More...
 
virtual bool isValidated (Field field) const
 Returns whether the field has been validated yet. More...
 
const WValidator::Resultvalidation (Field field) const
 Returns the result of a validation. More...
 
virtual void setValidation (Field field, const WValidator::Result &result)
 Sets the validation result for a field. More...
 
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 Create a WObject with a given parent object. More...
 
virtual ~WObject ()
 Destructor. More...
 
virtual const std::string id () const
 Returns the (unique) identifier for this object. More...
 
virtual void setObjectName (const std::string &name)
 Sets an object name. More...
 
virtual std::string objectName () const
 Returns the object name. More...
 
void resetLearnedSlots ()
 Resets learned stateless slot implementations. More...
 
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation. More...
 
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation. More...
 
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance. More...
 
void isNotStateless ()
 Marks the current function as not stateless. More...
 
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method. More...
 
void addChild (WObject *child)
 Adds a child object. More...
 
virtual void removeChild (WObject *child)
 Removes a child object. More...
 
const std::vector< WObject * > & children () const
 Returns the children.
 
WObjectparent () const
 Returns the parent object.
 

Static Public Attributes

static const Field PasswordField = "password"
 Password field.
 
static const Field RememberMeField = "remember-me"
 Remember-me field.
 
- Static Public Attributes inherited from Wt::Auth::FormBaseModel
static const Field LoginNameField = "user-name"
 Login name field.
 

Additional Inherited Members

- Public Types inherited from Wt::WFormModel
typedef const char * Field
 A type to identify a field. More...
 
- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 Typedef for a WObject method without arguments.
 
- Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation. More...
 
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()
 Returns the sender of the current slot call. More...
 

Detailed Description

Model for implementing an authentication view.

This model implements the logic for authenticating a user (the "login" interface). It implements traditional username/password registration, and third party identification methods (although for the latter, it doesn't really do anything).

The model exposes three fields:

When the model validates correctly (validate() returns true), the entered credentials are correct. At that point you can use the login() utility function to login the identified user.

The model can also be used when the user is already known (e.g. to implement password confirmation before a critical operation). In that case you can set a value for the LoginNameField and make this field invisible or read-only.

The model also provides the client-side JavaScript logic to indicate password attempt throttling (configureThrottling() and updateThrottling()).

See also
AuthWidget

Constructor & Destructor Documentation

◆ AuthModel()

Wt::Auth::AuthModel::AuthModel ( const AuthService baseAuth,
AbstractUserDatabase users,
WObject parent = 0 
)

Constructor.

Creates a new authentication model, using a basic authentication service and user database.

Member Function Documentation

◆ configureThrottling()

void Wt::Auth::AuthModel::configureThrottling ( WInteractWidget button)
virtual

Initializes client-side login throttling.

If login attempt throttling is enabled, then this may also be indicated client-side using JavaScript by disabling the login button and showing a count-down indicator. This method initializes this JavaScript utlity function for a login button.

See also
updateThrottling()

◆ isVisible()

bool Wt::Auth::AuthModel::isVisible ( Field  field) const
virtual

Returns whether a field is visible.

In some cases not all fields of the model need to be shown. This may depend on values input for certain fields, and thus change dynamically. You may specialize this method to indicate that a certain field should be invisible.

The default implementation returns the value set by setVisible().

Reimplemented from Wt::WFormModel.

◆ login()

bool Wt::Auth::AuthModel::login ( Login login)
virtual

Logs the user in.

Logs in the user after a successful call to validate(). To avoid mishaps, you should call this method immediately after a call to validate().

Returns whether the user could be logged in.

◆ logout()

void Wt::Auth::AuthModel::logout ( Login login)
virtual

Logs the user out.

This also removes the remember-me cookie for the user.

◆ processAuthToken()

User Wt::Auth::AuthModel::processAuthToken ( )
virtual

Detects and processes an authentication token.

This returns a user that was identified with an authentication token found in the application environment, or an invalid User object if this feature is not configured, or no valid cookie was found.

See also
AuthService::processAuthToken()

◆ processEmailToken()

EmailTokenResult Wt::Auth::AuthModel::processEmailToken ( const std::string &  token)
virtual

Processes an email token.

This simply calls AuthService::processEmailToken().

◆ reset()

void Wt::Auth::AuthModel::reset ( )
virtual

Resets the model.

The default implementation clears the value of all fields, and resets the validation state to not validated.

Reimplemented from Wt::WFormModel.

◆ setRememberMeCookie()

void Wt::Auth::AuthModel::setRememberMeCookie ( const User user)
virtual

Creates a token and stores it in a cookie.

This enables automatic authentication in a next session.

◆ updateThrottling()

void Wt::Auth::AuthModel::updateThrottling ( WInteractWidget button)
virtual

Updates client-side login throttling.

This should be called after a call to attemptPasswordLogin(), if you want to reflect throttling using a client-side count-down indicator in the button.

You need to call configureThrottling() before you can do this.

◆ validate()

bool Wt::Auth::AuthModel::validate ( )
virtual

Validates the current input.

The default implementation calls validateField() for each field and returns true if all fields validated.

See also
validateField()

Reimplemented from Wt::WFormModel.

◆ validateField()

bool Wt::Auth::AuthModel::validateField ( Field  field)
virtual

Validates a field.

The default implementation uses the validator configured for the field to validate the field contents, or if no validator has been configured assumes that the field is valid.

You will typically customize this method for more complex validation cases.

See also
validate(), validationResult()

Reimplemented from Wt::WFormModel.


Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13