Class User
#include <User.h >
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.
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.
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.
const HashArray& data |
key/value data for this User record |
Constructor from key/value data
Constructor for an empty User record
Determine if this is valid data or not
Return value: true if the record is valid (has a valid id).
Clear all data out of this User instance. (Does not change DB.)
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.
Get list of all user ids in DB User table.
Locate User in db by location. Save if changed.
Return value: true if data is saved, false if DB error
Get the id of the User record.
Return value: the id
Get the admin id of the User record.
Return value: the admin id
Get the name of the User record.
Return value: the name
Get the email address of the User record.
Return value: the email address
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
Get the REST API authentication key of the User record.
Return value: the authentication key
Get the timestamp of the User record was created.
Return value: the creation time
Get the year of the User record record was created.
Return value: the creation year
Get the month of the User record record was created.
Return value: the creation month
Get the day of month of the User record record was created.
Return value: the creation day of month
Get the time of the last login of the User record.
Return value: the timestamp of last login
Get the number of logins recorded in the User record.
Return value: the number of logins
Get the current session id of the User record.
Return value: the current session id
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
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
Get the password reset request time of the User record.
Return value: the password reset request time
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
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
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
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
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
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
Get the status of the account being disabled from the User record.
Return value: true if account is disabled, false if account is enabled
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
DbRecNum newId |
new value to set |
Set the id for this User record.
const string& newname |
new value to set |
Set the person's name for this User record.
const string& newkey |
new value to set |
Set the REST API authenticate key for this User record.
time_t newCreated |
new value to set |
Set the record creation date for this User record.
time_t newLastLogin |
new value to set |
Set the last login time for this User record.
int newLoginCount |
new value to set |
Set the login count for this User record.
DbRecNum newSessionId |
new value to set |
Set the session id for this User record.
const string& newEmail |
new value to set |
Set the email address for this User record.
int newAdminId |
new value to set |
Set the admin id for this User record.
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 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.
int newTermsVersion |
new value to set |
Set the agreed upon terms version for this User record.
time_t newResetRequest |
new value to set |
Set the time of password reset request for this User record.
int newFailedLogins |
new value to set |
Set the failed login count for this User record.
time_t newLastFailed |
new value to set |
Set the time of last failed login for this User record.
Clear the last failed group for this User record.
const HashArray& data |
key/value pairs (from toHashArray()) |
Set the field values from the key/value data provided.
const string& newPassword |
new value to set |
Set the plain text password for this User record. It will be encrypted when stored.
const string& newTempPassword |
new value to set |
Set the temporary password for this User record.
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).
Set the timestamp of the password reset request for this User record to now.
Note that the last login attempt failed.
Note the last failed group.
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
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
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
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
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
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
Delete the record from the Datastore.
Return value: true if successfully deleted; false on error (like id==0 or DB error)
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
Convert this instance's data to XML.
Return value: a XMLData of instance's properties
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
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 |
Make sure we're connected to our table in the Datastore
Return value: true upon success, false upon failure
Set a new session id, semi-randomly generated
Return value: new session id
Set the login time to the current time.
Return value: the timestamp set
const string& date |
a date in the form of YYYY-MM-DD |
Convert Datastore date to time
Return value: timestamp for the date
time_t timestamp |
time to convert |
Convert time to Datastoredate format
Return value: text equivalent of date as YYYY-MM-DD