pianod2
multisource multiuser scriptable networked music player
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Private Types | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
User Class Reference

Data about each user. More...

#include <user.h>

Collaboration diagram for User:
Collaboration graph
[legend]

Public Member Functions

 User (const std::string &username, const std::string &pass, bool encrypt=false)
 Create a new user with the username and password. More...
 
 User (const User &)=delete
 
Useroperator= (const User &)=delete
 
 User (User &&)=default
 
Useroperator= (User &&)=default
 
 ~User ()
 
const std::string & username (void) const
 
void setPassword (const std::string &pass)
 Change the password in a user's record. More...
 
bool authenticate (const char *trypass) const
 Validate a user's credentials (username/password). More...
 
bool authenticate (const std::string &trypass) const
 
bool changePassword (const std::string &old, const std::string &pass)
 Change a user's password, authenticating the old one. More...
 
void assignRank (Rank newrank)
 Set a user's rank. More...
 
bool assignRank (const std::string &newrank)
 Set a user's rank. More...
 
bool haveRank (const Rank rank) const
 Determine if a user has a rank or better. More...
 
Rank getRank (void) const
 
const char * getRankName (void) const
 Get the rank name for the current user. More...
 
void setPrivilege (const Privilege priv, bool setting)
 
bool havePrivilege (const Privilege priv) const
 
bool online (const PianodService &service) const
 Determine if a user is online. More...
 
bool attachData (UserData::DataStore *)
 Attach some data to a user. More...
 
void updateData (void)
 
UserData::DataStoregetData (const std::string &datatype, const std::string &dataid="") const
 Get data associated with a user. More...
 
void removeData (const std::string &datatype, const std::string &dataid="")
 Remove data associated with a user. More...
 

Static Public Member Functions

static void shadow (bool mode)
 
static bool shadow ()
 
static const Privilege getPrivilege (const std::string &privilege)
 Translate a privilege to its enumerator. More...
 
static const Rank getRank (const std::string &rank)
 Translate a rank to its enumerator. More...
 
static const char * getRankName (Rank rank)
 Translate a rank enumerator to its text. More...
 
static const char * getPrivilegeName (Privilege privilege)
 Translate a privilege enumerator to its text. More...
 
static Rank getVisitorRank ()
 
static void setVisitorRank (const std::string &rank)
 
static UsergetStartscriptUser (void)
 Retrieve a user for processing the startup script. More...
 

Protected Member Functions

bool operator< (const User &other)
 
bool operator< (const std::string &other)
 
Parsnip::Data persist () const
 Prepare data for persistence. More...
 

Static Protected Attributes

static Rank visitor_rank = Rank::Listener
 Rank for users that have not authenticated. More...
 

Private Types

enum  user_write_priority_t { CRITICAL = 1, IMPORTANT = 10, NOMINAL = 60, TRIVIAL = 300 }
 
typedef enum User::user_write_priority_t WritePriority
 
using UserDataPair = std::pair< std::string, UserData::DataStore * >
 
using UserDataMap = std::unordered_map< std::string, UserData::DataStore * >
 

Static Private Member Functions

static void scheduleWrite (WritePriority priority)
 
static bool reconstituteUserData (User &user, const Parsnip::Data &data)
 
static User reconstitute_user (const Parsnip::Data &data)
 Create (restore) a user from a Parsnip object. More...
 

Private Attributes

std::string name
 User's login name. More...
 
std::string password
 Encrypted password. More...
 
Rank rank = Rank::None
 Assigned rank. More...
 
EnumeratedArray< Privilege, bool > privileges
 Assigned privileges. More...
 
UserDataMap data
 Data sets attached to the user. More...
 

Static Private Attributes

static bool shadow_mode = false
 
static time_t write_time = 0
 

Friends

class UserManager
 

Detailed Description

Data about each user.

Member Typedef Documentation

◆ UserDataMap

using User::UserDataMap = std::unordered_map <std::string, UserData::DataStore *>
private

◆ UserDataPair

using User::UserDataPair = std::pair <std::string, UserData::DataStore *>
private

◆ WritePriority

Member Enumeration Documentation

◆ user_write_priority_t

Enumerator
CRITICAL 

User removal, privilege change, etc.

IMPORTANT 

User creation.

NOMINAL 

Sources, preferences, data attachments, etc.

TRIVIAL 

Ratings.

Constructor & Destructor Documentation

◆ User() [1/3]

User::User ( const std::string &  username,
const std::string &  pass,
bool  encrypt = false 
)

Create a new user with the username and password.

Encrypt the password if requested (if not, it's already encrypted).

Parameters
usernameThe user ID assigned the new user.
passThe password for the new user.
encryptWhether to encrypt the password (user data restored from file will already be enciphered).

◆ User() [2/3]

User::User ( const User )
delete

◆ User() [3/3]

User::User ( User &&  )
default

◆ ~User()

User::~User ( )

Member Function Documentation

◆ assignRank() [1/2]

bool User::assignRank ( const std::string &  newrank)

Set a user's rank.

Parameters
newrankThe text name of the rank to assign to the user.
Returns
true if the text name is valid, false otherwise.
Here is the call graph for this function:

◆ assignRank() [2/2]

void User::assignRank ( Rank  newrank)

Set a user's rank.

Parameters
newrankThe rank enumerator to assign the user.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ attachData()

bool User::attachData ( UserData::DataStore element)

Attach some data to a user.

The data is persisted with the user's record. On success, the pointer passed is stored in the user's record; it must not be freed. On failure, it is the responsibility of the caller to destroy it.

Parameters
elementThe data to attach.
Returns
true on success, false on errror.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ authenticate() [1/2]

bool User::authenticate ( const char *  trypass) const

Validate a user's credentials (username/password).

Parameters
trypassThe password, unenciphered. It is enciphered and compared to the ciphered password on file.
Returns
true on correct password, false otherwise.
Here is the caller graph for this function:

◆ authenticate() [2/2]

bool User::authenticate ( const std::string &  trypass) const
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ changePassword()

bool User::changePassword ( const std::string &  old,
const std::string &  pass 
)

Change a user's password, authenticating the old one.

Parameters
oldThe user's old password, unenciphered.
passThe new password, unenciphered.
Returns
true if the old password was valid, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getData()

UserData::DataStore * User::getData ( const std::string &  datatype,
const std::string &  dataid = "" 
) const

Get data associated with a user.

Parameters
datatypeThe data type portion of the key.
dataidThe ID portion of the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPrivilege()

const Privilege User::getPrivilege ( const std::string &  privilege)
static

Translate a privilege to its enumerator.

Parameters
privilegeThe privilege name.
Returns
The privilege enumerator.
Exceptions
Invalidargument if the privilege string is invalid.
Here is the caller graph for this function:

◆ getPrivilegeName()

const char * User::getPrivilegeName ( Privilege  privilege)
static

Translate a privilege enumerator to its text.

Parameters
privilegeThe privilege to lookup.
Returns
The corresponding privilege name (string).
Here is the caller graph for this function:

◆ getRank() [1/2]

const Rank User::getRank ( const std::string &  rank)
static

Translate a rank to its enumerator.

Parameters
rankThe rank name.
Returns
The rank enumerator.
Exceptions
Invalidargument if the rank string is invalid.

◆ getRank() [2/2]

Rank User::getRank ( void  ) const
inline
Here is the caller graph for this function:

◆ getRankName() [1/2]

const char * User::getRankName ( Rank  rank)
static

Translate a rank enumerator to its text.

Parameters
rankThe rank to lookup.
Returns
The corresponding rank name (string).

◆ getRankName() [2/2]

const char * User::getRankName ( void  ) const

Get the rank name for the current user.

Returns
Rank name (string) for the current user.
Here is the caller graph for this function:

◆ getStartscriptUser()

User * User::getStartscriptUser ( void  )
static

Retrieve a user for processing the startup script.

Returns
A fake administrator user with all privileges.
Here is the caller graph for this function:

◆ getVisitorRank()

static Rank User::getVisitorRank ( )
inlinestatic
Here is the caller graph for this function:

◆ havePrivilege()

bool User::havePrivilege ( const Privilege  priv) const
Here is the caller graph for this function:

◆ haveRank()

bool User::haveRank ( const Rank  minimum) const

Determine if a user has a rank or better.

Parameters
minimumThe desired rank.
Returns
true if the user's rank is the minimum or better.

◆ online()

bool User::online ( const PianodService service) const

Determine if a user is online.

Parameters
serviceReference to the service to be checked for logins.
Returns
true if user has at least one authenticated connection.
Here is the caller graph for this function:

◆ operator<() [1/2]

bool User::operator< ( const std::string &  other)
inlineprotected

◆ operator<() [2/2]

bool User::operator< ( const User other)
inlineprotected

◆ operator=() [1/2]

User& User::operator= ( const User )
delete

◆ operator=() [2/2]

User& User::operator= ( User &&  )
default

◆ persist()

Parsnip::Data User::persist ( ) const
protected

Prepare data for persistence.

Returns
A Parsnip Data object ready for serialization.

◆ reconstitute_user()

User User::reconstitute_user ( const Parsnip::Data data)
staticprivate

Create (restore) a user from a Parsnip object.

Parameters
dataThe root parsnip object containing the user information.
Returns
A user structure.
Exceptions
Throwsan exception if the object does not provide a minimally valid user, which is name, password, rank.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconstituteUserData()

static bool User::reconstituteUserData ( User user,
const Parsnip::Data data 
)
staticprivate

◆ removeData()

void User::removeData ( const std::string &  datatype,
const std::string &  dataid = "" 
)

Remove data associated with a user.

The data is freed if found.

Parameters
datatypeThe data type portion of the key.
dataidThe ID portion of the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduleWrite()

void User::scheduleWrite ( WritePriority  priority)
staticprivate
Here is the caller graph for this function:

◆ setPassword()

void User::setPassword ( const std::string &  pass)

Change the password in a user's record.

Parameters
passThe new password.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPrivilege()

void User::setPrivilege ( const Privilege  priv,
bool  setting 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setVisitorRank()

void User::setVisitorRank ( const std::string &  rank)
static
Here is the caller graph for this function:

◆ shadow() [1/2]

static bool User::shadow ( )
inlinestatic
Here is the caller graph for this function:

◆ shadow() [2/2]

void User::shadow ( bool  mode)
static

◆ updateData()

void User::updateData ( void  )
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ username()

const std::string& User::username ( void  ) const
inline
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ UserManager

friend class UserManager
friend

Member Data Documentation

◆ data

UserDataMap User::data
private

Data sets attached to the user.

◆ name

std::string User::name
private

User's login name.

◆ password

std::string User::password
private

Encrypted password.

◆ privileges

EnumeratedArray<Privilege, bool> User::privileges
private

Assigned privileges.

◆ rank

Rank User::rank = Rank::None
private

Assigned rank.

◆ shadow_mode

bool User::shadow_mode = false
staticprivate

◆ visitor_rank

Rank User::visitor_rank = Rank::Listener
staticprotected

Rank for users that have not authenticated.

◆ write_time

time_t User::write_time = 0
staticprivate

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