Class User

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class User

Summary
Public Methods
User(id, generalUse)
User(name, generalUse, emailOnly)
User(data)
User()
inline bool valid() const
void clear()
static int find(name, emailOnly)
static DbRecList getAllUserIds()
bool save()
inline DbRecNum getId() const
inline DbRecNum getAdminId() const
inline const string& getName() const
inline const string& getEmail() const
bool isTempPassword(temppasswd)
inline const string& getAuthKey() const
inline time_t getCreateTime() const
inline int getCreateYear() const
inline int getCreateMonth() const
inline int getCreateDay() const
inline time_t getLastLogin() const
inline int getLoginCount() const
inline DbRecNum getSessionId() const
inline int getWorldId() const
inline int getTermsVersion() const
inline time_t getResetRequest() const
inline int getFailedLogins() const
inline int getLastFailed() const
inline int getFailedLoginsGroup() const
inline int getLastFailedGroup() const
int getFailedLoginsOverLastMinute()
int getFailedLoginsOverLastHour()
inline bool isDisabled() const
inline const string& getDomain() const
inline void setId(newId)
inline void setName(newname)
inline void setAuthKey(newkey)
inline void setCreated(newCreated)
inline void setLastLogin(newLastLogin)
inline void setLoginCount(newLoginCount)
inline void setSessionId(newSessionId)
inline void setEmail(newEmail)
inline void setAdminId(newAdminId)
inline void setWorldId(newWorldId)
DbRecNum setNewWorldId(wid)
inline void setTermsVersion(newTermsVersion)
inline void setResetRequest(newResetRequest)
inline void setFailedLogins(newFailedLogins)
inline void setLastFailed(newLastFailed)
void clearLastFailedGroup()
void set(data)
bool setPassword(newPassword)
bool setTempPassword(newTempPassword)
bool setDisabled(isDisabled)
time_t setResetRequest()
time_t setLastFailed()
time_t setLastFailedGroup()
static User validate(username, passwd)
bool validate(passwd)
inline time_t getLastLoginNow()
inline DbRecNum getSessionIdNow()
bool lastLoginStale()
bool lastLoginRecentlyStale()
bool deleteRecord()
HashArray toHashArray(fordb) const
inline XMLData toXML() const
Protected Methods
bool load(id, generalUse)
Private Properties
Private Methods
static bool initdb()
int setNewSessionId()
time_t setNewLoginTime()
static time_t date2time(date)
static string time2date(timestamp)
See Also

#include <User.h >

Summary

Use this class to access user account data as stored in User database table.

If you desire to extend this table so it includes more settings for your user accounts, consider creating a separate UserSettings table that has your specific settings in it.  If you make the id of UserSettings match the id of User, looking up settings will be very quick.

Public Methods

User(id, generalUse)

DbRecNum id

User table record id

bool generalUse

true if not authenticating, false if password data needed

Default value: true


Constructor to load a record from database table from its id.

User(name, generalUse, emailOnly)

string name

user name (if unique) or e-mail address

bool generalUse

true if not authenticating, false if password data needed

Default value: true

bool emailOnly

true if name is e-mail address

Default value: false


Constructor to load a record from database table from a user name or email.

Email address match is sought first, then user name.

User(data)

const HashArray& data

key/value data for this User record


Constructor from key/value data

User()

Constructor for an empty User record

inline bool valid() const

Determine if this is valid data or not

Return value: true if the record is valid (has a valid id).

void clear()

Clear all data out of this User instance. (Does not change DB.)

static int find(name, emailOnly)

string name

user name (if unique) or e-mail address

bool emailOnly

true if name is e-mail address

Default value: false


Locate User in db by e-mail (first) or name (second)

Return value: 0 if record not found, if of record otherwise.

static DbRecList getAllUserIds()

Get list of all user ids in DB User table.

bool save()

Locate User in db by location. Save if changed.

Return value: true if data is saved, false if DB error

inline DbRecNum getId() const

Get the id of the User record.

Return value: the id

inline DbRecNum getAdminId() const

Get the admin id of the User record.

Return value: the admin id

inline const string& getName() const

Get the name of the User record.

Return value: the name

inline const string& getEmail() const

Get the email address of the User record.

Return value: the email address

bool isTempPassword(temppasswd)

string temppasswd

the plain password text to check


Check if the password provided matches the temporary password of the User record

Return value: true if they match, false if they don't

inline const string& getAuthKey() const

Get the REST API authentication key of the User record.

Return value: the authentication key

inline time_t getCreateTime() const

Get the timestamp of the User record was created.

Return value: the creation time

inline int getCreateYear() const

Get the year of the User record record was created.

Return value: the creation year

inline int getCreateMonth() const

Get the month of the User record record was created.

Return value: the creation month

inline int getCreateDay() const

Get the day of month of the User record record was created.

Return value: the creation day of month

inline time_t getLastLogin() const

Get the time of the last login of the User record.

Return value: the timestamp of last login

inline int getLoginCount() const

Get the number of logins recorded in the User record.

Return value: the number of logins

inline DbRecNum getSessionId() const

Get the current session id of the User record.

Return value: the current session id

inline int getWorldId() const

Get the tenet id in the User record. Different users belong to different tenets, whether the tenet is a company, an organization, group, or whatever. If a user has multiple projects, this can be the active project id.

It is used and interpreted by the app, so it can be used per app needs.

Return value: the tenet id

inline int getTermsVersion() const

Get the terms version of a User Agreement of the User record that the user has accepted.

This may be necessary to understand what can be done with the user's data.

Presumably the app is tracking user acceptance of a User Agreement provided by the application.

It is used and interpreted by the app, so it can be used per app needs.

Return value: the terms version

inline time_t getResetRequest() const

Get the password reset request time of the User record.

Return value: the password reset request time

inline int getFailedLogins() const

Get the failed login count of the User record.

This is used by usergw to detect someone trying to hack a user account.

Return value: the failed login count

inline int getLastFailed() const

Get the timestamp of the last failed login of the User record.

This is used by usergw to detect someone trying to hack a user account.

Return value: the timestamp of the last failed logi

inline int getFailedLoginsGroup() const

Get the timestamp of the last failed login of the User record.

This is used by usergw to detect someone trying to hack a user account.

Return value: the timestamp of the last failed login

inline int getLastFailedGroup() const

Get the timestamp of the last failed login of the User record.

This is used by usergw to detect someone trying to hack a user account.

Return value: the timestamp of the last failed login

int getFailedLoginsOverLastMinute()

Get the count of failed logins over the last minute of the User record.

Return value: the count of failed logins over the last minute

int getFailedLoginsOverLastHour()

Get the count of failed logins over the last hour of the User record.

Return value: the count of failed logins over the last hour

inline bool isDisabled() const

Get the status of the account being disabled from the User record.

Return value: true if account is disabled, false if account is enabled

inline const string& getDomain() const

Future use. Get the domain of the User record. This is application-specific, perhaps used to determine a user's home UI.

Return value: the id

inline void setId(newId)

DbRecNum newId

new value to set


Set the id for this User record.

inline void setName(newname)

const string& newname

new value to set


Set the person's name for this User record.

inline void setAuthKey(newkey)

const string& newkey

new value to set


Set the REST API authenticate key for this User record.

inline void setCreated(newCreated)

time_t newCreated

new value to set


Set the record creation date for this User record.

inline void setLastLogin(newLastLogin)

time_t newLastLogin

new value to set


Set the last login time for this User record.

inline void setLoginCount(newLoginCount)

int newLoginCount

new value to set


Set the login count for this User record.

inline void setSessionId(newSessionId)

DbRecNum newSessionId

new value to set


Set the session id for this User record.

inline void setEmail(newEmail)

const string& newEmail

new value to set


Set the email address for this User record.

inline void setAdminId(newAdminId)

int newAdminId

new value to set


Set the admin id for this User record.

inline void setWorldId(newWorldId)

DbRecNum newWorldId

new value to set


Set the tenet id for this User record.  Different users belong to different tenets, whether the tenet is a company, an organization, group, or whatever. If a user has multiple projects, this can be the active project id.

It is used and interpreted by the app, so it can be used per app needs.

DbRecNum setNewWorldId(wid)

DbRecNum wid

new value to set


Set the tenet id for this User record and immediately save to DB.

Different users belong to different tenets, whether the tenet is a company, an organization, group, or whatever. If a user has multiple projects, this can be the active project id.

It is used and interpreted by the app, so it can be used per app needs.

inline void setTermsVersion(newTermsVersion)

int newTermsVersion

new value to set


Set the agreed upon terms version for this User record.

inline void setResetRequest(newResetRequest)

time_t newResetRequest

new value to set


Set the time of password reset request for this User record.

inline void setFailedLogins(newFailedLogins)

int newFailedLogins

new value to set


Set the failed login count for this User record.

inline void setLastFailed(newLastFailed)

time_t newLastFailed

new value to set


Set the time of last failed login for this User record.

void clearLastFailedGroup()

Clear the last failed group for this User record.

void set(data)

const HashArray& data

key/value pairs (from toHashArray())


Set the field values from the key/value data provided.

bool setPassword(newPassword)

const string& newPassword

new value to set


Set the plain text password for this User record. It will be encrypted when stored.

bool setTempPassword(newTempPassword)

const string& newTempPassword

new value to set


Set the temporary password for this User record.

bool setDisabled(isDisabled)

bool isDisabled

true to disable the user from logging in, false to enable user login

Default value: true


Set the this User record as disabled (or not).

time_t setResetRequest()

Set the timestamp of the password reset request for this User record to now.

time_t setLastFailed()

Note that the last login attempt failed.

time_t setLastFailedGroup()

Note the last failed group.

static User validate(username, passwd)

const string& username

the user e-mail to authenticate

const string& passwd

the plain text password to check against the user


Given a correct login user and password combination, load the User record.

If the password is incorrect or the user name is unknown, no User record is loaded.

Return value: an empty User record if the username is unknown or the passwd does not match; return a valid User record if username known and passwd matdches

bool validate(passwd)

const string& passwd

the plain text password to check


Given a password, determine if it matches the encrypted password in the User record.

Note: if you loaded this User record with generalUse flag as true, then this call will always fail since the password is missing.

Return value: true if the password is correct, false if it does not match

inline time_t getLastLoginNow()

Pull the current value of the last login directly from the database table for this user.

If your app caches User records, this function is handy for bypassing a stale cache value.

Return value: last login timestamp

inline DbRecNum getSessionIdNow()

Pull the current session id of the last login directly from the database table for this user.

If your app caches User records, this function is handy for bypassing a stale cache value.

Return value: current session id

bool lastLoginStale()

Return true if the user's session has timed out (it's 24+ hours old)

Return value: true if session timeout, false if session still active

bool lastLoginRecentlyStale()

Determine if the user's session just recently went stale.

This can be used as a 5 minutes grace period for a session that just expired.

Return value: true if it recently became stale (or still active), false if definitely expired

bool deleteRecord()

Delete the record from the Datastore.

Return value: true if successfully deleted; false on error (like id==0 or DB error)

HashArray toHashArray(fordb) const

bool fordb

false to include Id; true to exclude Id, which is handy for sending to Datastore

Default value: false


Convert this instance's data into a HashArray.

This is the complement of set()

Return value: a HashArray of instance's properties

inline XMLData toXML() const

Convert this instance's data to XML.

Return value: a XMLData of instance's properties

Protected Methods

bool load(id, generalUse)

DbRecNum id

the id of the record to load

bool generalUse

Default value: true


Load data from the Datastore with the provided Id.

Return value: true upon success; false upon faliure

Private Properties

DbRecNum id

Table record number/id

string name

Human name on account

string Password

Password to login (encrypted)

string AuthKey

User's authentication token/key (REST API)

Datemath Created

The date this account was created

Datemath LastLogin

The date of the last login by this user

int LoginCount

The number of times this user has logged in successfully

DbRecNum SessionId

Session Id for ensuring authenticity of user throughout session

string Email

Email address of the user

DbRecNum AdminId

(not implemented)

DbRecNum WorldId

Tenant id; MAE app-specific

int TermsVersion

User has agreed to this terms version (app-specific)

Datemath ResetRequest

Timestamp of last password reset request

string TempPassword

Temporary password from reset request

int FailedLogins

Ongoing tally of failed logins

Datemath LastFailed

Timestamp of last failed login

int FailedLoginsGroup

Burst of logins count

Datemath LastFailedGroup

bool Disabled

Flag: F is User active; T if User not allowed to login

static Datastore db

Our connection to DB table data

bool changed

Flag: true if any data in this instance has changed


Private Methods

static bool initdb()

Make sure we're connected to our table in the Datastore

Return value: true upon success, false upon failure

int setNewSessionId()

Set a new session id, semi-randomly generated

Return value: new session id

time_t setNewLoginTime()

Set the login time to the current time.

Return value: the timestamp set

static time_t date2time(date)

const string& date

a date in the form of YYYY-MM-DD


Convert Datastore date to time

Return value: timestamp for the date

static string time2date(timestamp)

time_t timestamp

time to convert


Convert time to Datastoredate format

Return value: text equivalent of date as YYYY-MM-DD

See Also

User database table