Wt: Wt::Auth::AuthModel Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
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.h>`

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

## Public Member Functions
| AuthModel (const AuthService &baseAuth, AbstractUserDatabase &users)
| Constructor.
virtual void | reset () override
| Resets the model.
virtual bool | isVisible (Field field) const override
| Returns whether a field is visible.
virtual bool | validateField (Field field) override
| Validates a field.
virtual bool | validate () override
| 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 void | logout (Login &login)
| Logs the user out.
virtual EmailTokenResult | processEmailToken (const std::string &token)
| Processes an email token.
virtual void | setRememberMeCookie (const User &user)
| Creates a token and stores it in a cookie.
virtual User | processAuthToken ()
| Detects and processes an authentication token.
bool | showResendEmailVerification () const
| Returns whether to allow resending the email verification.
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.
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 bool | isReadOnly (Field field) const
| Returns 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 | PasswordField
| Password field.
static const Field | RememberMeField
| Remember-me field.
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 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

## ◆ AuthModel()

Wt::Auth::AuthModel::AuthModel | ( | const AuthService & | baseAuth,
|  | AbstractUserDatabase & | users )

Constructor.

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

## Member Function Documentation

## ◆ configureThrottling()

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

virtual bool Wt::Auth::AuthModel::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.

## ◆ login()

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

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

Logs the user out.

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

## ◆ processAuthToken()

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

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

Processes an email token.

This simply calls AuthService::processEmailToken().

## ◆ reset()

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

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

virtual 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.

## ◆ showResendEmailVerification()

bool Wt::Auth::AuthModel::showResendEmailVerification | ( |  | ) | const

Returns whether to allow resending the email verification.

Returns true when email verification is required and the user was not yet verified. In this case, a user would be stuck if the verification email was lost.

## ◆ updateThrottling()

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

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

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

virtual bool Wt::Auth::AuthModel::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.