Wt
3.2.0
|
An authentication widget. More...
#include <Wt/Auth/AuthWidget>
Public Member Functions | |
AuthWidget (const AuthService &baseAuth, AbstractUserDatabase &users, Login &login, WContainerWidget *parent=0) | |
Constructor. | |
void | setInternalBasePath (const std::string &path) |
Sets an internal path for authentication services. | |
std::string | internalBasePath () const |
Returns the internal path. | |
Login & | login () |
Returns the login object. | |
const AuthService * | baseAuth () const |
Returns the authentication base service. | |
void | addPasswordAuth (const AbstractPasswordService *auth) |
Adds a password authentication service. | |
const AbstractPasswordService * | passwordAuth () const |
Returns the password authentication service. | |
void | addOAuth (const OAuthService *auth) |
Adds an OAuth authentication service provider. | |
void | addOAuth (const std::vector< const OAuthService * > &auth) |
Adds a list of OAuth authentication service providers. | |
std::vector< const OAuthService * > | oAuth () const |
Returns the list of OAuth authentication service providers. | |
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 () |
Process the (initial) environment. | |
virtual void | letUpdatePassword (const User &user, bool promptPassword) |
Lets the user update his password. | |
virtual void | handleLostPassword () |
Lets the user update his password. | |
virtual void | createLoginView () |
Creates the login view. | |
virtual void | createLoggedInView () |
Creates the view shown when the user is logged in. | |
virtual void | createPasswordLogin () |
Creates a password login view. | |
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 void | createOAuthLogin () |
Creates a widget to login using OAuth. | |
virtual WDialog * | createPasswordPromptDialog (Login &login) |
Creates a password prompt dialog. | |
Protected Member Functions | |
virtual void | create () |
Creates the user-interface. | |
virtual WDialog * | showDialog (const WString &title, WWidget *contents) |
Shows a dialog. |
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:
The processEnvironment() method initiates this process, and should typically be called only at application startup time.
The authentication widget can be configured for password-based authentication (addPasswordAuth()) and/or OAuth-based authentication (addOAuth()).
It is very likely that the off-the shelf authentication widget not entirely to your taste or functional requirements. The widget uses two methods to allow customization:
Wt::Auth::AuthWidget::AuthWidget | ( | const AuthService & | baseAuth, |
AbstractUserDatabase & | users, | ||
Login & | login, | ||
WContainerWidget * | parent = 0 |
||
) |
Constructor.
Creates a new authentication widget which uses the authentication service in baseAuth
, and the user database users
.
The result of authentication changes is propagated to the rest of the application using a login
object.
Authentication methods should be configured using addPasswordAuth() and addOAuth().
void Wt::Auth::AuthWidget::addOAuth | ( | const OAuthService * | auth | ) |
Adds an OAuth authentication service provider.
This enables OAuth-based authentication. More than one OAuth authentication service can be configured: one for each supported third-party OAuth identity provider.
void Wt::Auth::AuthWidget::addOAuth | ( | const std::vector< const OAuthService * > & | auth | ) |
Adds a list of OAuth authentication service providers.
void Wt::Auth::AuthWidget::addPasswordAuth | ( | const AbstractPasswordService * | auth | ) |
Adds a password authentication service.
This enables password-based authentication capabilities in the widget:
Only one password authentication service can be configured.
const AuthService* Wt::Auth::AuthWidget::baseAuth | ( | ) | const |
Returns the authentication base service.
This returns the service passed through the constructor.
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.
void Wt::Auth::AuthWidget::createLoggedInView | ( | ) | [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 | ( | ) | [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 combines the result of createPasswordLogin() and/or createOAuthLogin() in a container widget.
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.
void Wt::Auth::AuthWidget::createOAuthLogin | ( | ) | [virtual] |
Creates a widget to login using OAuth.
The default implementation renders the "Wt.Auth.template.oauth-login"
template, and 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 FIXME link to google.
void Wt::Auth::AuthWidget::createPasswordLogin | ( | ) | [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 renders the "Wt.Auth.template.passwords-login"
template.
Creates a password prompt dialog.
This creates a dialog which prompts the user for his password. The user is taken from login
object, which also signals an eventual success using its Login::changed() signal.
The default implementation creates a new PasswordPromptDialog.
Creates a registration view.
This creates a registration view, optionally using information already obtained through OAuth.
The default implementation creates a new RegistrationWidget, and adds the same authentication mechanisms as used for logging in in this widget.
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 creates a new UpdatePasswordWidget.
void Wt::Auth::AuthWidget::handleLostPassword | ( | ) | [virtual] |
Lets the user update his 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.
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 returns the login object on which this authentication widget acts.
std::vector<const OAuthService *> Wt::Auth::AuthWidget::oAuth | ( | ) | const |
Returns the list of OAuth authentication service providers.
const AbstractPasswordService* Wt::Auth::AuthWidget::passwordAuth | ( | ) | const |
Returns the password authentication service.
void Wt::Auth::AuthWidget::processEnvironment | ( | ) | [virtual] |
Process the (initial) environment.
This method process environmental information that may be relevant to authentication:
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::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:
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.