Wt: Wt::Auth::AuthWidget Class Reference

Wt 3.3.0

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

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions
Wt::Auth::AuthWidget Class Reference
Authentication module (Wt::Auth)

An authentication widget. More...

`#include <Wt/Auth/AuthWidget>`

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

List of all members.

## Public Member Functions
| AuthWidget (const AuthService &baseAuth, AbstractUserDatabase &users, Login &login, WContainerWidget *parent=0)
| Constructor.
| AuthWidget (Login &login, WContainerWidget *parent=0)
| Constructor.
void | setModel (AuthModel *model)
| Sets a model.
AuthModel * | model () const
| Returns the model.
Login & | login ()
| Returns the login object.
void | setInternalBasePath (const std::string &path)
| Sets an internal path for authentication services.
std::string | internalBasePath () const
| Returns the internal path.
void | setRegistrationEnabled (bool enabled)
| Configures registration capabilities.
void | registerNewUser ()
| Starts a new registration process.
virtual void | registerNewUser (const Identity &oauth)
| Starts a new registration process.
virtual void | processEnvironment ()
| Processes the (initial) environment.
virtual void | letUpdatePassword (const User &user, bool promptPassword)
| Lets the user update his password.
virtual void | handleLostPassword ()
| Lets the user "recover" a lost password.
virtual WWidget * | createLostPasswordView ()
| Creates a lost password view.
virtual WWidget * | createRegistrationView (const Identity &id)
| Creates a registration view.
virtual WWidget * | createUpdatePasswordView (const User &user, bool promptPassword)
| Creates a view to update a user's password.
virtual WDialog * | createPasswordPromptDialog (Login &login)
| Creates a password prompt dialog.
## Protected Member Functions
virtual void | create ()
| Creates the user-interface.
virtual void | createLoginView ()
| Creates the login view.
virtual void | createLoggedInView ()
| Creates the view shown when the user is logged in.
virtual void | createPasswordLoginView ()
| Creates a password login view.
virtual void | createOAuthLoginView ()
| Creates a widget to login using OAuth.
virtual WDialog * | showDialog (const WString &title, WWidget *contents)
| Shows a dialog.
virtual RegistrationModel * | createRegistrationModel ()
| Creates a registration model.
virtual WFormWidget * | createFormWidget (AuthModel::Field field)
| Creates a form widget.
virtual void | render (WFlags< RenderFlag > flags)
| Renders the widget.

## Detailed Description

An authentication widget.

The authentication widget is a widget that provides a login or logout function (depending on whether the user is currently logged in). You can use it for either or both purposes.

Login or logout events are signalled to a Login object on which this widget acts.

The widget also processes environmental information related to authentication:

- email tokens, which are indicated in an internal path. The widget uses dialogs (by default) to interact with the user to act on the token.
- authentication tokens, which are stored in browser cookies, to implement remember-me functionality.

The processEnvironment() method initiates this process, and should typically be called only at application startup time.

The authentication widget is implemented as a View for an AuthModel, which can be set using setModel(). The login logic (at this moment only for password-based authentication) is handled by this model.

It is very likely that the off-the shelf authentication widget does not satisfy entirely to your taste or functional requirements. The widget uses three methods to allow customization:

- as a WTemplateFormView, you may change the layout and styling of to your liking.
- the authentication logic is delegated to an AuthModel and can can be specialized or can be used with a custom view altogether.
- the views are created using virtual methods, which may be specialized to create a customized view or to apply changes to the default view.

## Constructor & Destructor Documentation

Wt::Auth::AuthWidget::AuthWidget | ( | const AuthService & | baseAuth,
|  | AbstractUserDatabase & | users,
|  | Login & | login,
|  | WContainerWidget * | parent = `0`
| ) |  |

Constructor.

Creates a new authentication widget. This creates an AuthModel using the given authentication service `baseAuth` and user database `users`.

The result of authentication changes is propagated to the rest of the application using a `login` object.

Authentication services need to be configured in the model().

Wt::Auth::AuthWidget::AuthWidget | ( | Login & | login,
|  | WContainerWidget * | parent = `0`
| ) |  |

Constructor.

Creates a new authentication widget.

The result of authentication changes is propagated to the rest of the application using a `login` object.

You need to call setModel() to configure a model for this view.

## Member Function Documentation

void Wt::Auth::AuthWidget::create | ( |  | ) | `[protected, virtual]`

Creates the user-interface.

This method is called just before an initial rendering, and creates the initial view.

The default implementation calls createLoginView() or createLoggedInView() depending on whether a user is currently logged in.

WFormWidget * Wt::Auth::AuthWidget::createFormWidget | ( | AuthModel::Field | field | ) | `[protected, virtual]`

Creates a form widget.

This method is called by updateViewField() when it needs to create a form widget for a field, and none was specified using setFormWidget().

Reimplemented from Wt::WTemplateFormView.

void Wt::Auth::AuthWidget::createLoggedInView | ( |  | ) | `[protected, virtual]`

Creates the view shown when the user is logged in.

The default implementation renders the `"Wt.Auth.template.logged-in"` template.

void Wt::Auth::AuthWidget::createLoginView | ( |  | ) | `[protected, virtual]`

Creates the login view.

This creates a view that allows the user to login, and is shown when no user is current logged in.

The default implementation renders the `"Wt.Auth.template.login"` template, and binds fields using createPasswordLoginView() and createOAuthLoginView().

WWidget * Wt::Auth::AuthWidget::createLostPasswordView | ( |  | ) | `[virtual]`

Creates a lost password view.

When email verification has been enabled, the user may indicate that he has lost his password -- then proof of controlling the same email address that had associated with his account is sufficient to allow him to enter a new password.

This creates the widget used to let the user enter his email address. The default implementation creates a new LostPasswordWidget.

See also:
  handleLostPassword()

void Wt::Auth::AuthWidget::createOAuthLoginView | ( |  | ) | `[protected, virtual]`

Creates a widget to login using OAuth.

The default implementation adds an icon for each OAuth service provider available.

There's alot to say about making a usable login mechanism for OAuth (and federated login services in general), see https://sites.google.com/site/oauthgoog/UXFedLogin.

See also:
  createLoginView()

void Wt::Auth::AuthWidget::createPasswordLoginView | ( |  | ) | `[protected, virtual]`

Creates a password login view.

This is used by the default implementation of createLoginView() to prompt for the information needed for logging in using a username and password. The default implementation implements a view guided by the model().

See also:
  createLoginView()

WDialog * Wt::Auth::AuthWidget::createPasswordPromptDialog | ( | Login & | login | ) | `[virtual]`

Creates a password prompt dialog.

This creates a dialog which prompts the user for his password. The user is taken from the `login` object, which also signals an eventual success using its Login::changed() signal.

The default implementation instantiates a PasswordPromptDialog.

RegistrationModel * Wt::Auth::AuthWidget::createRegistrationModel | ( |  | ) | `[protected, virtual]`

Creates a registration model.

This method creates a registration model.

See also:
  registerNewUser()

WWidget * Wt::Auth::AuthWidget::createRegistrationView | ( | const Identity & | id | ) | `[virtual]`

Creates a registration view.

This creates a registration view, optionally using information already obtained from a third party identification service (such as an OAuth provider).

The default implementation creates a new RegistrationWidget with a model created using createRegistrationModel().

See also:
  registerNewUser()

WWidget * Wt::Auth::AuthWidget::createUpdatePasswordView | ( | const User & | user,
|  | bool | promptPassword
| ) |  | `[virtual]`

Creates a view to update a user's password.

If `promptPassword` is `true`, the user has to enter his current password in addition to a new password.

This creates the widget used to let the user chose a new password. The default implementation instantiates an UpdatePasswordWidget.

See also:
  letUpdatePassword()

void Wt::Auth::AuthWidget::handleLostPassword | ( |  | ) | `[virtual]`

Lets the user "recover" a lost password.

This creates a view to let the user enter his email address, used to send an email containing instructions to enter a new password.

The default implementation creates a new view using createLostPasswordView() and shows it in a dialog using showDialog().

std::string Wt::Auth::AuthWidget::internalBasePath | ( |  | ) | const

Returns the internal path.

See also:
  setInternalBasePath()

void Wt::Auth::AuthWidget::letUpdatePassword | ( | const User & | user,
|  | bool | promptPassword
| ) |  | `[virtual]`

Lets the user update his password.

This creates a view to let the user enter his new password.

The default implementation creates a new view using createUpdatePasswordView() and shows it in a dialog using showDialog().

Login& Wt::Auth::AuthWidget::login | ( |  | ) |

Returns the login object.

This login object is used to keep track of the user currently authenticated.

AuthModel* Wt::Auth::AuthWidget::model | ( |  | ) | const

Returns the model.

The model is used only for the login function.

See also:
  setModel()

void Wt::Auth::AuthWidget::processEnvironment | ( |  | ) | `[virtual]`

Processes the (initial) environment.

This method process environmental information that may be relevant to authentication:

- email tokens, which are indicated through an internal path. The widget uses dialogs (by default) to interact with the user to act on the token.

- authentication tokens, which are stored in browser cookies, to implement remember-me functionality. When logging in using an authentication token, the login is considered "weak" (since a user may have inadvertently forgotten to logout from a public computer). You should let the user authenticate using another, primary method before doing sensitive operations. The createPasswordPromptDialog() method may be useful for this.

See also:
  letUpdatePassword()

void Wt::Auth::AuthWidget::registerNewUser | ( |  | ) |

Starts a new registration process.

This calls `registerNewUser(0)`.

void Wt::Auth::AuthWidget::registerNewUser | ( | const Identity & | oauth | ) | `[virtual]`

Starts a new registration process.

This starts a new registration process, and may be called in response to a user action, an internal path change, or an OAuthService login procedure which identified a new user. In the latter case, the OAuth-provided information is passed as parameter `oauth`.

The default implementation creates a view using createRegistrationView(), and shows it in a dialog using showDialog().

void Wt::Auth::AuthWidget::render | ( | WFlags< RenderFlag > | flags | ) | `[protected, virtual]`

Renders the widget.

This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

Reimplemented from Wt::WWebWidget.

void Wt::Auth::AuthWidget::setInternalBasePath | ( | const std::string & | path | ) |

Sets an internal path for authentication services.

Only the registration function is made available through an internal path (so that one can redirect a user to the registration page). Other internal paths involved in authentication are configured in the service classes:

- AuthService::setEmailRedirectInternalPath(): email tokens
- OAuthService::redirectInternalPath(): an internal path used during the oauth process.

void Wt::Auth::AuthWidget::setModel | ( | AuthModel * | model | ) |

Sets a model.

This sets a model to be used for authentication.

void Wt::Auth::AuthWidget::setRegistrationEnabled | ( | bool | enabled | ) |

Configures registration capabilities.

Although the AuthWidget itself does not implement a registration view, it may offer a button/link to do so, and calls registerNewUser() when a user wishes to register.

Even if registration is not enabled, the result of an OAuthService login process may be that a new user is identified. Then the createRegistrationView() is also used to present this new user with a registration view, passing the information obtained through OAuth.

WDialog * Wt::Auth::AuthWidget::showDialog | ( | const WString & | title,
|  | WWidget * | contents
| ) |  | `[protected, virtual]`

Shows a dialog.

This shows a dialog. The default method creates a standard WDialog, with the given `title` and `contents` as central widget.

When the central widget is deleted, it deletes the dialog.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator