Wt: Wt::Auth::AuthModel Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Attributes
Wt::Auth::AuthModel Class Reference
Authentication module (Wt::Auth)

Model for implementing an authentication view. More...

`#include <Wt/Auth/AuthModel>`

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

List of all members.

## Public Member Functions
| AuthModel (const AuthService &baseAuth, AbstractUserDatabase &users, WObject *parent=0)
| Constructor.
virtual void | reset ()
| Resets the model.
virtual bool | isVisible (Field field) const
| Returns whether a field is visible.
virtual bool | validateField (Field field)
| Validates a field.
virtual bool | validate ()
| Validates the current input.
virtual void | configureThrottling (WInteractWidget *button)
| Initializes client-side login throttling.
virtual void | updateThrottling (WInteractWidget *button)
| Updates client-side login throttling.
virtual bool | login (Login &login)
| Logs the user in.
virtual EmailTokenResult | processEmailToken (const std::string &token)
| Processes an email token.
virtual User | processAuthToken ()
| Detects and processes an authentication token.
## Static Public Attributes
static const Field | PasswordField = "password"
| Password field.
static const Field | RememberMeField = "remember-me"
| Remember-me field.

## 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:

- LoginNameField: the login name (used as an identity for the Identity::LoginName provider)
- PasswordField: the password
- RememberMeField: whether the login should be remembered with an authentication cookie (if that is configured in the AuthService).

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

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

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

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.

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.

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

EmailTokenResult Wt::Auth::AuthModel::processEmailToken | ( | const std::string & | token | ) | `[virtual]`

Processes an email token.

This simply calls AuthService::processEmailToken().

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.

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.

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.

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.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator