Wt: Wt::Auth::RegistrationModel Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
Wt::Auth::RegistrationModel Class Reference

Model for implementing a registration view. More...

`#include <Wt/Auth/RegistrationModel.h>`

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

## Public Member Functions
| RegistrationModel (const AuthService &baseAuth, AbstractUserDatabase &users, Login &login)
| Constructor.
virtual void | reset () override
| Resets the model.
Login & | login ()
| Returns the login object.
void | setMinLoginNameLength (int chars)
| Configures a minimum length for a login name.
int | minLoginNameLength () const
| Returns the minimum length for a login name.
void | setEmailPolicy (EmailPolicy policy)
| Configures whether an email address needs to be entered.
EmailPolicy | emailPolicy () const
| Returns the email policy.
virtual bool | registerIdentified (const Identity &identity)
| Register a user authenticated by an identity provider.
User | existingUser () const
| Returns the existing user that needs to be confirmed.
virtual IdentityConfirmationMethod | confirmIsExistingUser () const
| Returns the method to be used to confirm to be an existing user.
virtual void | existingUserConfirmed ()
| Confirms that the user is indeed an existing user.
virtual WString | validateLoginName (const WString &userName) const
| Validates the login name.
virtual void | checkUserExists (const WString &userName)
| Verifies that a user with that name does not yet exist.
virtual User | doRegister ()
| Performs the registration process.
virtual bool | isVisible (Field field) const override
| Returns whether a field is visible.
virtual bool | isReadOnly (Field field) const override
| Returns whether a field is read only.
virtual bool | validateField (Field field) override
| Validates a field.
virtual bool | isConfirmUserButtonVisible () const
| Returns whether an existing user needs to be confirmed.
virtual bool | isFederatedLoginVisible () const
| Returns whether federated login options can be shown.
Public Member Functions inherited from Wt::Auth::FormBaseModel
| FormBaseModel (const AuthService &baseAuth, AbstractUserDatabase &users)
| Constructor.
const AuthService * | baseAuth () const
| Returns the authentication base service.
AbstractUserDatabase & | users ()
| Returns the user database.
const AbstractUserDatabase & | users () const
| Returns the user database.
virtual void | addPasswordAuth (const AbstractPasswordService *auth)
| Adds a password authentication service.
const AbstractPasswordService * | passwordAuth () const
| Returns the password authentication service.
virtual void | addOAuth (const OAuthService *auth)
| Adds an OAuth authentication service provider.
virtual 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.
virtual void | addSaml (const Saml::Service *auth)
| Adds a SAML authentication service provider.
virtual void | addSaml (const std::vector< const Saml::Service * > &auth)
| Adds a list of SAML authentication service providers.
std::vector< const Saml::Service * > | saml () const
| Returns the list of SAML authentication service providers.
virtual WString | label (Field field) const override
| Returns a field label.
virtual bool | loginUser (Login &login, User &user, LoginState state=LoginState::Strong)
| Logs the user in.
Public Member Functions inherited from Wt::WFormModel
| WFormModel ()
| Constructor.
void | addField (Field field, const WString &info=WString::Empty)
| Adds a field.
void | removeField (Field field)
| Removes a field.
std::vector< Field > | fields () const
| Returns the fields.
virtual bool | validate ()
| Validates the current input.
bool | valid () const
| Returns the current overall validation state.
void | setVisible (Field field, bool visible)
| Sets whether a field is visible.
void | setReadOnly (Field field, bool readOnly)
| Sets whether a field is read-only.
virtual void | setValue (Field field, const cpp17::any &value)
| Sets the field value.
virtual const cpp17::any & | value (Field field) const
| Returns the field value.
virtual WString | valueText (Field field) const
| Returns the field value text.
virtual void | setValidator (Field field, const std::shared_ptr< WValidator > &validator)
| Sets a validator.
virtual std::shared_ptr< WValidator > | validator (Field field) const
| Returns a validator.
virtual void | setValidated (Field field, bool validated)
| Sets whether a field has been validated.
virtual bool | isValidated (Field field) const
| Returns whether the field has been validated yet.
const WValidator::Result & | validation (Field field) const
| Returns the result of a validation.
virtual void | setValidation (Field field, const WValidator::Result &result)
| Sets the validation result for a field.
Public Member Functions inherited from Wt::WObject
void | addChild (std::unique_ptr< WObject > child)
| Add a child WObject whose lifetime is determined by this WObject.
template<typename Child >
Child * | addChild (std::unique_ptr< Child > child)
| Add a child WObject, returning a raw pointer.
std::unique_ptr< WObject > | removeChild (WObject *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
template<typename Child >
std::unique_ptr< Child > | removeChild (Child *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
virtual const std::string | id () const
| Returns the (unique) identifier for this object.
virtual void | setObjectName (const std::string &name)
| Sets an object name.
virtual std::string | objectName () const
| Returns the object name.
void | resetLearnedSlots ()
| Resets learned stateless slot implementations.
template<class T >
void | resetLearnedSlot (void(T::*method)())
| Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)())
| Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)())
| Declares a slot to be stateless and learn client-side behaviour in advance.
void | isNotStateless ()
| Marks the current function as not stateless.
template<class T >
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode)
| Provides a JavaScript implementation for a method.
Public Member Functions inherited from Wt::Core::observable
| observable () noexcept
| Default constructor.
virtual | ~observable ()
| Destructor.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...)) noexcept
| Protects a method call against object destruction.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...) const) const noexcept
| Protects a const method call against object destruction.
template<typename Function >
auto | bindSafe (const Function &function) noexcept
| Protects a function against object destruction.

## Static Public Attributes
static const Field | ChoosePasswordField
| Choose Password field.
static const Field | RepeatPasswordField
| Repeat password field.
static const Field | EmailField
| Email field (if login name is not email)
Static Public Attributes inherited from Wt::Auth::FormBaseModel
static const Field | LoginNameField
| Login name field.

## Additional Inherited Members
Public Types inherited from Wt::WFormModel
typedef const char * | Field
| A type to identify a field.
Public Types inherited from Wt::WObject
typedef void(WObject::*) | Method()
| Typedef for a WObject method without arguments.
Static Public Member Functions inherited from Wt::WObject
Protected Member Functions inherited from Wt::Auth::FormBaseModel
Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * | getStateless (Method method)
| On-demand stateless slot implementation.

## Detailed Description

Model for implementing a registration view.

This model implements the logic for the registration of a new user. It can deal with traditional username/password registration, or registration of pre-identified users using federated login.

The model exposes four fields:

- LoginNameField: the login name (used as an identity for the Identity::LoginName provider) – this can be an email if the AuthService is configured to use email addresses as identity
- ChoosePasswordField: the password
- RepeatPasswordField: the password (repeated)
- EmailField: if an email address is to be asked (and is not used as identity).

The largest complexity is in the handling of third party identity providers, which is initiated with a call to registerIdentified().

When a user is re-identified with the same identity, then the model may require that the (original) user confirms this new identity. The model indicates that this button should be made visible with isConfirmUserButtonVisible(), the action to take is determined by confirmIsExistingUser(), and existingUserConfirmed() ends this process by merging the new identity into the existing user.

See also
  RegistrationWidget

## Constructor & Destructor Documentation

## ◆ RegistrationModel()

Wt::Auth::RegistrationModel::RegistrationModel | ( | const AuthService & | baseAuth,
|  | AbstractUserDatabase & | users,
|  | Login & | login )

Constructor.

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

The `login` object is used to indicate that an existing user was re-identified, and thus the registration process may be aborted.

## Member Function Documentation

## ◆ checkUserExists()

virtual void Wt::Auth::RegistrationModel::checkUserExists | ( | const WString & | userName | ) |
| virtual

Verifies that a user with that name does not yet exist.

If a user with that name already exists, it may in fact be the same user that is trying to register again (perhaps using a different identification method). If possible, we allow the user to confirm his identity.

## ◆ confirmIsExistingUser()

virtual IdentityConfirmationMethod Wt::Auth::RegistrationModel::confirmIsExistingUser | ( |  | ) | const
| virtual

Returns the method to be used to confirm to be an existing user.

When the ConfirmExisting field is visible, this returns an appropriate method to use to let the user confirm that he is indeed the identified existing user.

The outcome of this method (if it is an online method, like a password prompt), if successful, should be indicated using existingUserConfirmed().

See also
  existingUserConfirmed()

## ◆ emailPolicy()

EmailPolicy Wt::Auth::RegistrationModel::emailPolicy | ( |  | ) | const

Returns the email policy.

See also
  setEmailPolicy()

## ◆ existingUser()

User Wt::Auth::RegistrationModel::existingUser | ( |  | ) | const

Returns the existing user that needs to be confirmed.

When a user wishes to register with an identity that corresponds to an existing user, he may be allowd to confirm that he is in fact this existing user.

See also
  confirmIsExistingUser()

## ◆ existingUserConfirmed()

virtual void Wt::Auth::RegistrationModel::existingUserConfirmed | ( |  | ) |
| virtual

Confirms that the user is indeed an existing user.

The new identity is added to this existing user (if applicable), and the user is logged in.

## ◆ isConfirmUserButtonVisible()

virtual bool Wt::Auth::RegistrationModel::isConfirmUserButtonVisible | ( |  | ) | const
| virtual

Returns whether an existing user needs to be confirmed.

This returns whether the user is being identified as an existing user and he can confirm that he is in fact the same user.

## ◆ isFederatedLoginVisible()

virtual bool Wt::Auth::RegistrationModel::isFederatedLoginVisible | ( |  | ) | const
| virtual

Returns whether federated login options can be shown.

This returns whether fields for federated login (such as OAuth) should be shown. These are typically buttons corresponding to identity providers.

The result of a federated authentication procedure should be indicated to registerIdentified().

## ◆ isReadOnly()

virtual bool Wt::Auth::RegistrationModel::isReadOnly | ( | Field | field | ) | const
| overridevirtual

Returns whether a field is read only.

The default implementation returns the value set by setReadOnly()

Reimplemented from Wt::WFormModel.

## ◆ isVisible()

virtual bool Wt::Auth::RegistrationModel::isVisible | ( | Field | field | ) | const
| overridevirtual

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.

## ◆ minLoginNameLength()

int Wt::Auth::RegistrationModel::minLoginNameLength | ( |  | ) | const

Returns the minimum length for a login name.

See also
  setMinLoginNameLength()

## ◆ registerIdentified()

virtual bool Wt::Auth::RegistrationModel::registerIdentified | ( | const Identity & | identity | ) |
| virtual

Register a user authenticated by an identity provider.

Using a 3rd party authentication service such as OAuth, a user may be identified which is not yet registered with the web application.

Then, you may still need to allow the user to complete registration, but because the user already is identified and authenticated, this simplifies the registration form, since fields related to authentication can be dropped.

Returns `true` if the given identity was already registered, and has been logged in.

## ◆ reset()

virtual void Wt::Auth::RegistrationModel::reset | ( |  | ) |
| overridevirtual

Resets the model.

This resets the model to initial values, clearing any entered information (login name, password, pre-identified identity).

Reimplemented from Wt::WFormModel.

## ◆ setEmailPolicy()

void Wt::Auth::RegistrationModel::setEmailPolicy | ( | EmailPolicy | policy | ) |

Configures whether an email address needs to be entered.

You may specify whether you want the user to enter an email address.

This has no effect when the IdentityPolicy is IdentityPolicy::EmailAddress.

The default policy is:

- EmailOptional when email address verification is enabled
- EmailDisabled otherwise

## ◆ setMinLoginNameLength()

void Wt::Auth::RegistrationModel::setMinLoginNameLength | ( | int | chars | ) |

Configures a minimum length for a login name.

The default value is 4.

## ◆ validateField()

virtual bool Wt::Auth::RegistrationModel::validateField | ( | Field | field | ) |
| overridevirtual

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.

## ◆ validateLoginName()

virtual WString Wt::Auth::RegistrationModel::validateLoginName | ( | const WString & | userName | ) | const
| virtual

Validates the login name.

This verifies that the login name is adequate (see also setMinLoginNameLength()).