Leosac  0.8.0
Open Source Access Control
Leosac::Auth::User Class Reference

Represent a user. More...

#include <User.hpp>

+ Inheritance diagram for Leosac::Auth::User:
+ Collaboration diagram for Leosac::Auth::User:

Public Member Functions

 User (const std::string &username)
 Create a user, specifying an username. More...
 
 User ()
 
 User (const UserId &id)
 Create a user with a predefined UserId. More...
 
virtual ~User ()=default
 
const std::string & username () const noexcept
 Get the username of this user. More...
 
UserId id () const noexcept
 
void password (const std::string &pw)
 Set a new password for the user. More...
 
bool verify_password (const std::string &pw) const
 Verify that the password pw is equal to the user's password. More...
 
std::string password () const
 Returns the password hash + salt (as stored in the database). More...
 
void username (const std::string &username)
 Set a new username. More...
 
IAccessProfilePtr profile () const noexcept
 
void profile (IAccessProfilePtr user_profile)
 
const std::string & firstname () const
 
const std::string & lastname () const
 
const std::string & email () const
 
const ValidityInfovalidity () const
 
void firstname (const std::string &)
 
void lastname (const std::string &)
 
void email (const std::string &)
 
void validity (const ValidityInfo &c)
 
bool is_valid () const
 Check the validity status (enabled / disabled) of the user. More...
 
const UserGroupMembershipSetgroup_memberships () const
 Retrieve the UserGroupMembership that this user is involved with. More...
 
UserRank rank () const
 Get the global rank of the user. More...
 
void rank (UserRank r)
 Set the global rank of the user. More...
 
size_t odb_version () const
 
void add_credential (const Cred::ICredentialPtr &cred)
 
std::vector< Cred::CredentialLWPtrlazy_credentials () const
 
std::vector< Tools::ScheduleMappingLWPtrlazy_schedules_mapping () const
 
void schedule_mapping_added (const Tools::ScheduleMappingPtr &sched_mapping)
 The user has been mapped by a schedule. More...
 

Protected Attributes

UserId id_
 
std::string username_
 This is an (unique) identifier for the user. More...
 
boost::optional< ScryptResultpassword_
 
std::string firstname_
 
std::string lastname_
 
std::string email_
 
UserGroupMembershipSet membership_
 
UserRank rank_
 
std::vector< Cred::CredentialLWPtrcredentials_
 
std::vector< Tools::ScheduleMappingLWPtrschedules_mapping_
 ScheduleMapping object to which we are mapped directly (as user). More...
 
ValidityInfo validity_
 A user can have the same validity than credentials. More...
 
IAccessProfilePtr profile_
 
const size_t version_
 

Friends

class odb::access
 
class ::Leosac::TestAccess
 

Detailed Description

Represent a user.

Definition at line 42 of file User.hpp.

Constructor & Destructor Documentation

◆ User() [1/3]

User::User ( const std::string &  username)

Create a user, specifying an username.

See also
username(const std::string &) for more information regarding username's rules.

Definition at line 40 of file User.cpp.

◆ User() [2/3]

User::User ( )

Definition at line 35 of file User.cpp.

◆ User() [3/3]

User::User ( const UserId id)

Create a user with a predefined UserId.

Parameters
id

Definition at line 48 of file User.cpp.

◆ ~User()

virtual Leosac::Auth::User::~User ( )
virtualdefault

Member Function Documentation

◆ add_credential()

void User::add_credential ( const Cred::ICredentialPtr cred)

Definition at line 192 of file User.cpp.

◆ email() [1/2]

const std::string & User::email ( ) const

Definition at line 93 of file User.cpp.

◆ email() [2/2]

void User::email ( const std::string &  e)

Definition at line 108 of file User.cpp.

◆ firstname() [1/2]

const std::string & User::firstname ( ) const

Definition at line 83 of file User.cpp.

◆ firstname() [2/2]

void User::firstname ( const std::string &  f)

Definition at line 98 of file User.cpp.

◆ group_memberships()

const UserGroupMembershipSet & User::group_memberships ( ) const

Retrieve the UserGroupMembership that this user is involved with.

While the set is always eagerly loaded, the group() and user() method in each Membership will return lazy weak pointer.

Definition at line 133 of file User.cpp.

◆ id()

unsigned long User::id ( ) const
noexcept

Definition at line 128 of file User.cpp.

◆ is_valid()

bool User::is_valid ( ) const

Check the validity status (enabled / disabled) of the user.

Definition at line 123 of file User.cpp.

◆ lastname() [1/2]

const std::string & User::lastname ( ) const

Definition at line 88 of file User.cpp.

◆ lastname() [2/2]

void User::lastname ( const std::string &  l)

Definition at line 103 of file User.cpp.

◆ lazy_credentials()

std::vector< Leosac::Cred::CredentialLWPtr > User::lazy_credentials ( ) const

Definition at line 176 of file User.cpp.

◆ lazy_schedules_mapping()

std::vector< Leosac::Tools::ScheduleMappingLWPtr > User::lazy_schedules_mapping ( ) const

Definition at line 181 of file User.cpp.

◆ odb_version()

size_t User::odb_version ( ) const

Definition at line 171 of file User.cpp.

◆ password() [1/2]

std::string User::password ( ) const

Returns the password hash + salt (as stored in the database).

The use of this function should be rather sparse.

Definition at line 154 of file User.cpp.

◆ password() [2/2]

void User::password ( const std::string &  pw)

Set a new password for the user.

Parameters
<tt>pw</tt>A cleartext representation of the password.

Definition at line 138 of file User.cpp.

◆ profile() [1/2]

IAccessProfilePtr User::profile ( ) const
noexcept

Definition at line 73 of file User.cpp.

◆ profile() [2/2]

void User::profile ( IAccessProfilePtr  user_profile)

Definition at line 78 of file User.cpp.

◆ rank() [1/2]

UserRank User::rank ( ) const

Get the global rank of the user.

Definition at line 161 of file User.cpp.

◆ rank() [2/2]

void User::rank ( UserRank  r)

Set the global rank of the user.

Definition at line 166 of file User.cpp.

◆ schedule_mapping_added()

void User::schedule_mapping_added ( const Tools::ScheduleMappingPtr sched_mapping)

The user has been mapped by a schedule.

See also
Auth::Door::schedule_mapping_added

Definition at line 186 of file User.cpp.

◆ username() [1/2]

const std::string & User::username ( ) const
noexcept

Get the username of this user.

Definition at line 55 of file User.cpp.

◆ username() [2/2]

void User::username ( const std::string &  username)

Set a new username.

A few rules regarding usernames:

  • Username are always case insensitive, and are store in lower case.
  • Only alphanumeric ASCII characters, "_", "." and "-" are allowed.
Note
This function will throw if the username is invalid.

Definition at line 62 of file User.cpp.

◆ validity() [1/2]

const ValidityInfo & User::validity ( ) const

Definition at line 113 of file User.cpp.

◆ validity() [2/2]

void User::validity ( const ValidityInfo c)

Definition at line 118 of file User.cpp.

◆ verify_password()

bool User::verify_password ( const std::string &  pw) const

Verify that the password pw is equal to the user's password.

Parameters
pwA cleartext string representing the password you want to check.
Returns
True is pw is the correct password, false otherwise.

Definition at line 144 of file User.cpp.

Friends And Related Function Documentation

◆ ::Leosac::TestAccess

friend class ::Leosac::TestAccess
friend

Definition at line 199 of file User.hpp.

◆ odb::access

friend class odb::access
friend

Definition at line 198 of file User.hpp.

Member Data Documentation

◆ credentials_

std::vector<Cred::CredentialLWPtr> Leosac::Auth::User::credentials_
protected

Definition at line 179 of file User.hpp.

◆ email_

std::string Leosac::Auth::User::email_
protected

Definition at line 170 of file User.hpp.

◆ firstname_

std::string Leosac::Auth::User::firstname_
protected

Definition at line 168 of file User.hpp.

◆ id_

UserId Leosac::Auth::User::id_
protected

Definition at line 155 of file User.hpp.

◆ lastname_

std::string Leosac::Auth::User::lastname_
protected

Definition at line 169 of file User.hpp.

◆ membership_

UserGroupMembershipSet Leosac::Auth::User::membership_
protected

Definition at line 173 of file User.hpp.

◆ password_

boost::optional<ScryptResult> Leosac::Auth::User::password_
protected

Definition at line 166 of file User.hpp.

◆ profile_

IAccessProfilePtr Leosac::Auth::User::profile_
protected

Definition at line 192 of file User.hpp.

◆ rank_

UserRank Leosac::Auth::User::rank_
protected

Definition at line 176 of file User.hpp.

◆ schedules_mapping_

std::vector<Tools::ScheduleMappingLWPtr> Leosac::Auth::User::schedules_mapping_
protected

ScheduleMapping object to which we are mapped directly (as user).

Definition at line 185 of file User.hpp.

◆ username_

std::string Leosac::Auth::User::username_
protected

This is an (unique) identifier for the user.

Definition at line 163 of file User.hpp.

◆ validity_

ValidityInfo Leosac::Auth::User::validity_
protected

A user can have the same validity than credentials.

Definition at line 190 of file User.hpp.

◆ version_

const size_t Leosac::Auth::User::version_
protected

Definition at line 195 of file User.hpp.


The documentation for this class was generated from the following files: