Wt: Wt::Auth::Dbo::UserDatabase< DboType > Class Template Reference

Wt 3.3.0

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

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::Auth::Dbo::UserDatabase< DboType > Class Template Reference
Authentication module (Wt::Auth)

A default implementation for a authentication data in Wt::Dbo. More...

`#include <Wt/Auth/Dbo/UserDatabase>`

Inheritance diagram for Wt::Auth::Dbo::UserDatabase< DboType >:
[legend]

List of all members.

## Public Member Functions
| UserDatabase (Wt::Dbo::Session &session)
| Constructor.
virtual Transaction * | startTransaction ()
| Creates a new database transaction.
Wt::Dbo::ptr< DboType > | find (const User &user) const
| Returns the Dbo user type corresponding to an Auth::User.
User | find (const Wt::Dbo::ptr< DboType > user) const
| Returns the Auth::User corresponding to a Dbo user.
virtual User | findWithId (const std::string &id) const
| Finds a user with a given id.
virtual User | findWithIdentity (const std::string &provider, const WString &identity) const
| Finds a user with a given identity.
virtual WString | identity (const User &user, const std::string &provider) const
| Returns a user identity.
virtual User | registerNew ()
| Registers a new user.
virtual void | deleteUser (const User &user)
| Delete a user.
virtual User::Status | status (const User &user) const
| Returns the status for a user.
virtual void | setPassword (const User &user, const PasswordHash &password)
| Sets a new user password.
virtual PasswordHash | password (const User &user) const
| Returns a user password.
virtual void | addIdentity (const User &user, const std::string &provider, const WString &identity)
| Sets an identifier for the user.
virtual bool | setEmail (const User &user, const std::string &address)
| Sets a user's email address.
virtual std::string | email (const User &user) const
| Returns a user's email address.
virtual void | setUnverifiedEmail (const User &user, const std::string &address)
| Sets a user's unverified email address.
virtual std::string | unverifiedEmail (const User &user) const
| Returns a user's unverified email address.
virtual User | findWithEmail (const std::string &address) const
| Finds a user with a given email address.
virtual void | setEmailToken (const User &user, const Token &token, User::EmailTokenRole role)
| Sets a new email token for a user.
virtual Token | emailToken (const User &user) const
| Returns an email token.
virtual User::EmailTokenRole | emailTokenRole (const User &user) const
| Returns the role of the current email token.
virtual User | findWithEmailToken (const std::string &hash) const
| Finds a user with a given email token.
virtual void | addAuthToken (const User &user, const Token &token)
| Adds an authentication token to a user.
virtual void | removeAuthToken (const User &user, const std::string &hash)
| Deletes an authentication token.
virtual User | findWithAuthToken (const std::string &hash) const
| Finds a user with an authentication token.
virtual void | setFailedLoginAttempts (const User &user, int count)
| Sets the number of consecutive authentication failures.
virtual int | failedLoginAttempts (const User &user) const
| Returns the number of consecutive authentication failures.
virtual void | setLastLoginAttempt (const User &user, const WDateTime &t)
| Sets the time of the last login attempt.
virtual WDateTime | lastLoginAttempt (const User &user) const
| Returns the time of the last login.

## Detailed Description

### template<class DboType>
class Wt::Auth::Dbo::UserDatabase< DboType >

A default implementation for a authentication data in Wt::Dbo.

This is a template class, and needs as parameter the Dbo type which models holds the authentication information. A suitable implementation, which stores authentication information outside the "user" class, is provided by AuthInfo.

See also:
  UserDatabase

## Member Function Documentation

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::addAuthToken | ( | const User & | user,
|  | const Token & | token
| ) |  | `[virtual]`

Adds an authentication token to a user.

Unless you want a user to only have remember-me support from a single computer at a time, you should support multiple authentication tokens per user.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::addIdentity | ( | const User & | user,
|  | const std::string & | provider,
|  | const WString & | id
| ) |  | `[virtual]`

Sets an identifier for the user.

This associates an identifier with the user.

You are free to support only one identity per user, e.g. if you only use password-based authentication. But you may also want to support more than one if you allow the user to login using multiple methods (e.g. name/password, OAuth from one or more providers, LDAP, ...).

Implements Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::deleteUser | ( | const User & | user | ) | `[virtual]`

Delete a user.

This deletes a user from the database.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual std::string Wt::Auth::Dbo::UserDatabase< DboType >::email | ( | const User & | user | ) | const`[virtual]`

Returns a user's email address.

This may be an unverified or verified email address, depending on whether email address verification is enabled in the model classes.

This is an optional method, and currently not used by any of the included models or views.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual Token Wt::Auth::Dbo::UserDatabase< DboType >::emailToken | ( | const User & | user | ) | const`[virtual]`

Returns an email token.

This is only used when email verification is enabled and for lost password functionality. It should return the email token previously set with setEmailToken()

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User::EmailTokenRole Wt::Auth::Dbo::UserDatabase< DboType >::emailTokenRole | ( | const User & | user | ) | const`[virtual]`

Returns the role of the current email token.

This is only used when email verification is enabled or for lost password functionality. It should return the role previously set with setEailToken().

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual int Wt::Auth::Dbo::UserDatabase< DboType >::failedLoginAttempts | ( | const User & | user | ) | const`[virtual]`

Returns the number of consecutive authentication failures.

setFailedLoginAttempts()

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User Wt::Auth::Dbo::UserDatabase< DboType >::findWithAuthToken | ( | const std::string & | hash | ) | const`[virtual]`

Finds a user with an authentication token.

Returns a user with an authentication token.

This should find the user associated with a particular token hash, or return an invalid user if no user with that token hash exists.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User Wt::Auth::Dbo::UserDatabase< DboType >::findWithEmail | ( | const std::string & | address | ) | const`[virtual]`

Finds a user with a given email address.

This is used to verify that a email addresses are unique, and to implement lost password functionality.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User Wt::Auth::Dbo::UserDatabase< DboType >::findWithEmailToken | ( | const std::string & | hash | ) | const`[virtual]`

Finds a user with a given email token.

This is only used when email verification is enabled or for lost password functionality.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User Wt::Auth::Dbo::UserDatabase< DboType >::findWithId | ( | const std::string & | id | ) | const`[virtual]`

Finds a user with a given id.

The id uniquely identifies a user.

This should find the user with the given `id`, or return an invalid user if no user with that id exists.

Implements Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User Wt::Auth::Dbo::UserDatabase< DboType >::findWithIdentity | ( | const std::string & | provider,
|  | const WString & | identity
| ) |  | const`[virtual]`

Finds a user with a given identity.

The `identity` uniquely identifies the user by the `provider`.

This should find the user with the given `identity`, or return an invalid user if no user with that identity exists.

Implements Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual WString Wt::Auth::Dbo::UserDatabase< DboType >::identity | ( | const User & | user,
|  | const std::string & | provider
| ) |  | const`[virtual]`

Returns a user identity.

Returns a user identity for the given provider, or an empty string if the user has no identitfy set for this provider.

See also:
  addIdentity()

Implements Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual WDateTime Wt::Auth::Dbo::UserDatabase< DboType >::lastLoginAttempt | ( | const User & | user | ) | const`[virtual]`

Returns the time of the last login.

See also:
  setLastLoginAttempt()

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual PasswordHash Wt::Auth::Dbo::UserDatabase< DboType >::password | ( | const User & | user | ) | const`[virtual]`

Returns a user password.

This returns the stored password for a user, or a default constructed password hash if the user does not yet have password credentials.

This is used only by PasswordService.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User Wt::Auth::Dbo::UserDatabase< DboType >::registerNew | ( |  | ) | `[virtual]`

Registers a new user.

This adds a new user.

This method is only used by view classes involved with registration (RegistrationWidget).

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::removeAuthToken | ( | const User & | user,
|  | const std::string & | hash
| ) |  | `[virtual]`

Deletes an authentication token.

Deletes an authentication token previously added with addAuthToken()

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual bool Wt::Auth::Dbo::UserDatabase< DboType >::setEmail | ( | const User & | user,
|  | const std::string & | address
| ) |  | `[virtual]`

Sets a user's email address.

This is used only when email verification is enabled, or as a result of a 3rd party Identity Provider based registration process, if the provider also provides email address information with the identiy.

Returns whether the user's email address could be set. This may fail when there is already a user registered that email address.

See also:
  findWithEmail()

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::setEmailToken | ( | const User & | user,
|  | const Token & | token,
|  | User::EmailTokenRole | role
| ) |  | `[virtual]`

Sets a new email token for a user.

This is only used when email verification is enabled or for lost password functionality.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::setFailedLoginAttempts | ( | const User & | user,
|  | int | count
| ) |  | `[virtual]`

Sets the number of consecutive authentication failures.

This sets the number of consecutive authentication failures since the last valid login.

This is used by the throttling logic to determine how much time a user needs to wait before he can do a new login attempt.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::setLastLoginAttempt | ( | const User & | user,
|  | const WDateTime & | t
| ) |  | `[virtual]`

Sets the time of the last login attempt.

This sets the time at which the user attempted to login.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::setPassword | ( | const User & | user,
|  | const PasswordHash & | password
| ) |  | `[virtual]`

Sets a new user password.

This updates the password for a user.

This is used only by PasswordService.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual void Wt::Auth::Dbo::UserDatabase< DboType >::setUnverifiedEmail | ( | const User & | user,
|  | const std::string & | address
| ) |  | `[virtual]`

Sets a user's unverified email address.

This is only used when email verification is enabled. It holds the currently unverified email address, while a mail is being sent for the user to confirm this email address.

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual Transaction* Wt::Auth::Dbo::UserDatabase< DboType >::startTransaction | ( |  | ) | `[virtual]`

Creates a new database transaction.

If the underlying database does not support transactions, you can return `0`.

Ownership of the transaction is transferred, and the transaction must be deleted after it has been committed or rolled back.

The default implementation returns `0` (no transaction support).

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual User::Status Wt::Auth::Dbo::UserDatabase< DboType >::status | ( | const User & | user | ) | const`[virtual]`

Returns the status for a user.

If there is support for suspending accounts, then this method may be implemented to return whether a user account is disabled.

The default implementation always returns User::Normal.

See also:
  Login::loginState()

Reimplemented from Wt::Auth::AbstractUserDatabase.

template<class DboType >

virtual std::string Wt::Auth::Dbo::UserDatabase< DboType >::unverifiedEmail | ( | const User & | user | ) | const`[virtual]`

Returns a user's unverified email address.

This is an optional method, and currently not used by any of the included models or views.

Reimplemented from Wt::Auth::AbstractUserDatabase.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator