Wt: Wt::Auth::User Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Wt::Auth::User Class Reference

A user. More...

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

## Public Types
typedef AccountStatus | Status
| Typedef for enum Wt::Auth::AccountStatus.

## Public Member Functions
| User ()
| Default constructor.
| User (const std::string &id, const AbstractUserDatabase &database)
| Constructor.
AbstractUserDatabase * | database () const
| Returns the user database.
bool | operator== (const User &other) const
| Comparison operator.
bool | operator!= (const User &other) const
| Comparison operator.
bool | isValid () const
| Returns whether the user is valid.
const std::string & | id () const
| Returns the user id.
WString | identity (const std::string &provider) const
| Returns an identity.
void | addIdentity (const std::string &provider, const WString &identity)
| Adds an identity.
void | setIdentity (const std::string &provider, const WString &identity)
| Sets an identity.
void | removeIdentity (const std::string &provider)
| Removes an identity.
void | setPassword (const PasswordHash &password) const
| Sets a password.
PasswordHash | password () const
| Returns the password.
void | setEmail (const std::string &address) const
| Sets the email address.
std::string | email () const
| Returns the email address.
void | setUnverifiedEmail (const std::string &address) const
| Sets the unverified email address.
std::string | unverifiedEmail () const
| Returns the unverified email address.
AccountStatus | status () const
| Returns the account status.
void | setStatus (AccountStatus status)
| Sets the account status.
Token | emailToken () const
| Returns the email token.
EmailTokenRole | emailTokenRole () const
| Returns the email token role.
void | setEmailToken (const Token &token, EmailTokenRole role) const
| Sets an email token.
void | clearEmailToken () const
| Clears the email token.
void | addAuthToken (const Token &token) const
| Adds an authentication token.
void | removeAuthToken (const std::string &hash) const
| Removes an authentication token.
int | updateAuthToken (const std::string &hash, const std::string &newHash) const
| Updates an authentication token.
void | setAuthenticated (bool success) const
| Logs the result of an authentication attempt.
int | failedLoginAttempts () const
| Returns the number of consecutive unsuccessful login attempts.
WDateTime | lastLoginAttempt () const
| Returns the last login attempt.

## Detailed Description

A user.

This class represents a user. It is a value class that stores only the user id and a reference to an AbstractUserDatabase to access its properties.

An object can point to a valid user, or be invalid. Invalid users are typically used as return value for database queries which did not match with an existing user.

Not all methods are valid or applicable to your authentication system. See AbstractUserDatabase for a discussion.

See also
  AbstractUserDatabase

## Constructor & Destructor Documentation

## ◆ User() [1/2]

Wt::Auth::User::User | ( |  | ) |

Default constructor.

Creates an invalid user.

See also
  isValid()

## ◆ User() [2/2]

Wt::Auth::User::User | ( | const std::string & | id,
|  | const AbstractUserDatabase & | database )

Constructor.

Creates a user with id `id`, and whose information is stored in the `database`.

## Member Function Documentation

## ◆ addAuthToken()

void Wt::Auth::User::addAuthToken | ( | const Token & | token | ) | const

Adds an authentication token.

See also
  AbstractUserDatabase::addAuthToken()

## ◆ addIdentity()

void Wt::Auth::User::addIdentity | ( | const std::string & | provider,
|  | const WString & | identity )

Adds an identity.

Depending on whether the database supports multiple identities per provider, this may change (like setIdentity()), or add another identity to the user. For some identity providers (e.g. a 3rd party identity provider), it may be sensible to have more than one identity of the same provider for a single user (e.g. multiple email accounts managed by the same provider, that in fact identify the same user).

## ◆ clearEmailToken()

void Wt::Auth::User::clearEmailToken | ( |  | ) | const

Clears the email token.

See also
  setEmailToken()

## ◆ database()

AbstractUserDatabase * Wt::Auth::User::database | ( |  | ) | const

Returns the user database.

This returns the user database passed in the constructor, or 0 if the user is invalid, and was constructed using the default constructor.

## ◆ email()

std::string Wt::Auth::User::email | ( |  | ) | const

Returns the email address.

See also
  AbstractUserDatabase::email()

## ◆ emailToken()

Token Wt::Auth::User::emailToken | ( |  | ) | const

Returns the email token.

See also
  AbstractUserDatabase::emailToken()

## ◆ emailTokenRole()

EmailTokenRole Wt::Auth::User::emailTokenRole | ( |  | ) | const

Returns the email token role.

See also
  AbstractUserDatabase::emailTokenRole()

## ◆ failedLoginAttempts()

int Wt::Auth::User::failedLoginAttempts | ( |  | ) | const

Returns the number of consecutive unsuccessful login attempts.

See also
  setAuthenticated()

## ◆ id()

const std::string & Wt::Auth::User::id | ( |  | ) | const

Returns the user id.

This returns the id that uniquely identifies the user, and acts as a "primary key" to obtain other information for the user in the database.

See also
  AbstractUserDatabase

## ◆ isValid()

bool Wt::Auth::User::isValid | ( |  | ) | const

Returns whether the user is valid.

A invalid user is a sentinel value returned by methods that query the database but could not identify a matching user.

## ◆ lastLoginAttempt()

WDateTime Wt::Auth::User::lastLoginAttempt | ( |  | ) | const

Returns the last login attempt.

See also
  setAuthenticated()

## ◆ operator!=()

bool Wt::Auth::User::operator!= | ( | const User & | other | ) | const

Comparison operator.

See also
  operator==

## ◆ operator==()

bool Wt::Auth::User::operator== | ( | const User & | other | ) | const

Comparison operator.

Two users are equal if they have the same identity and the same database.

## ◆ password()

PasswordHash Wt::Auth::User::password | ( |  | ) | const

Returns the password.

See also
  AbstractUserDatabase::password()

## ◆ removeAuthToken()

void Wt::Auth::User::removeAuthToken | ( | const std::string & | hash | ) | const

Removes an authentication token.

See also
  AbstractUserDatabase::removeAuthToken()

## ◆ removeIdentity()

void Wt::Auth::User::removeIdentity | ( | const std::string & | provider | ) |

Removes an identity.

See also
  addIdentity()

## ◆ setAuthenticated()

void Wt::Auth::User::setAuthenticated | ( | bool | success | ) | const

Logs the result of an authentication attempt.

This changes the number of failed login attempts, and stores the current date as the last login attempt time.

See also
  failedLoginAttempts(), lastLoginAttempt()

## ◆ setEmail()

void Wt::Auth::User::setEmail | ( | const std::string & | address | ) | const

Sets the email address.

See also
  AbstractUserDatabase::setEmail()

## ◆ setEmailToken()

void Wt::Auth::User::setEmailToken | ( | const Token & | token,
|  | EmailTokenRole | role ) const

Sets an email token.

See also
  AbstractUserDatabase::setEmailToken()

## ◆ setIdentity()

void Wt::Auth::User::setIdentity | ( | const std::string & | provider,
|  | const WString & | identity )

Sets an identity.

Unlike addIdentity() this overrides any other identity of the given provider, in case the underlying database supports multiple identities per user.

## ◆ setPassword()

void Wt::Auth::User::setPassword | ( | const PasswordHash & | password | ) | const

Sets a password.

This also clears the email token.

See also
  AbstractUserDatabase::setPassword()
  clearEmailToken()

## ◆ setStatus()

void Wt::Auth::User::setStatus | ( | AccountStatus | status | ) |

Sets the account status.

See also
  AbstractUserDatabase::setStatus()

## ◆ setUnverifiedEmail()

void Wt::Auth::User::setUnverifiedEmail | ( | const std::string & | address | ) | const

Sets the unverified email address.

See also
  AbstractUserDatabase::setUnverifiedEmail()

## ◆ status()

AccountStatus Wt::Auth::User::status | ( |  | ) | const

Returns the account status.

See also
  AbstractUserDatabase::status()

## ◆ unverifiedEmail()

std::string Wt::Auth::User::unverifiedEmail | ( |  | ) | const

Returns the unverified email address.

See also
  AbstractUserDatabase::unverifiedEmail()

## ◆ updateAuthToken()

int Wt::Auth::User::updateAuthToken | ( | const std::string & | hash,
|  | const std::string & | newHash ) const

Updates an authentication token.

See also
  AbstractUserDatabase::updateAuthToken()