Users Class
Static methods for the Users models.
Item Index
Methods
- addLink static
- appId static
- authenticate static
- communityId static
- communityName static
- external
- fetch static
- futureUser
- getLanguage static
- hashPassphrase static
- hashPassphrase static
- identify static
- importIcon static
- isCommunityId static
- links static
- loggedInUser static
- login static
- logout static
- oAuth static
- oAuthClear static
- register static
- requestedIdentifier static
- roles static
- saveContactsFromLinks static
- setLoggedInUser static
- userFromContactInfo static
Properties
Events
- Users/adoptFutureUser
- Users/adoptFutureUser
- Users/adoptFutureUser
- Users/authenticate
- Users/authenticate
- Users/authenticate/insertAppUser
- Users/authenticate/updateAppUser
- Users/authenticate/updateAppUser
- Users/authenticate/updateAppUser
- Users/authenticate/updateAppUser
- Users/insertAppUser
- Users/insertUser
- Users/insertUser
- Users/insertUser
- Users/insertUser
- Users/insertUser
- Users/insertUser
- Users/login
- Users/login
- Users/logout
- Users/logout
- Users/register
- Users/register
- Users/saveContactsFromLinks
- Users/saveContactsFromLinks
- Users/setLoggedInUser
- Users/setLoggedInUser
- Users/setLoggedInUser/updateSessionId
- Users/setLoggedInUser/updateSessionId
- Users/updateUser
Methods
addLink
-
$address
-
[$type=null]
-
[$extraInfo=array()]
Adds a link to someone who is not yet a user
Parameters:
-
$address
StringCould be email address, mobile number, etc.
-
[$type=null]
String optionalcan be "email", "mobile",the name of a platform, or any of the above with optional "_hashed" suffix to indicate that the value has already been hashed. If null, the function tries to guess the $type by using Q_Valid functions.
-
[$extraInfo=array()]
Array optionalAssociative array of information you have imported from the address book. Should contain at least the keys:
- "firstName" => the imported first name
- "lastName" => the imported last name
- "labels" => array of the imported names of the contact groups to add this user to once they sign up
Returns:
Returns true if the link row was created Or returns a string $userId if user already exists and has verified this address.
appId
-
$platform
-
$appId
Get the internal app id and info
Parameters:
-
$platform
StringThe platform or platform for the app
-
$appId
StringCan be either an internal or external app id
Returns:
Returns array($appId, $appInfo)
authenticate
-
$platform
-
[$appId=null]
-
[$authenticated=null]
-
[$import=Q_Config::get('Users','import',$platform)]
Retrieves the currently logged-in user from the session. If the user was not originally retrieved from the database, inserts a new one. Thus, this can also be used to turn visitors into registered users by authenticating with some external platform.
Parameters:
-
$platform
StringCurrently only supports "facebook", "ios" or "android"
-
[$appId=null]
String optionalThe id of the app within the specified platform.
-
[$authenticated=null]
&boolean optionalIf authentication fails, puts false here. Otherwise, puts one of the following:
- 'registered' if user just registered,
- 'adopted' if a futureUser was just adopted,
- 'connected' if a logged-in user just connected the platform account for the first time,
- 'authorized' if a logged-in user was connected to platform but just authorized this app for the first time or true otherwise.
-
[$import=Q_Config::get('Users','import',$platform)]
Array optionalArray of things to import from platform if a new user is being inserted or displayName was not set. Can include various fields of the user on the external platform, such as "email", "first_name", "last_name", "gender" etc. If the email address is imported, it is set without requiring verification, and any email under Users/transactional/authenticated is sent.
Returns:
communityId
()
String
static
Get the id of the main community from the config. Defaults to the app name.
Returns:
The id of the main community for the installed app.
communityName
()
String
static
Get the name of the main community from the config. Defaults to the app name.
Returns:
The name of the main community for the installed app.
external
-
$publisherId
-
$userId
Returns external data about the user
Parameters:
-
$publisherId
StringThe id of the user corresponding to the publisher consuming the external data
-
$userId
StringThe id of the user whose external data is going to be consumed
Returns:
fetch
-
$userId
-
[$throwIfMissing=false]
Intelligently retrieves user by id
Parameters:
-
$userId
String -
[$throwIfMissing=false]
Boolean optionalIf true, throws an exception if the user can't be fetched
Returns:
futureUser
-
$type
-
$value
-
[$status=null]
Returns a user in the database that will correspond to a new user in the future once they authenticate or follow an invite. Inserts a new user if one doesn't already exist.
Parameters:
-
$type
Stringcan be "email", "mobile",the name of a platform, or any of the above with optional "_hashed" suffix to indicate that the value has already been hashed.
-
$value
StringThe value corresponding to the type. The type can be "email", "mobile", the name of a platform, or any of the above with optional "_hashed" suffix to indicate that the value has already been hashed. It can also be "none", in which case the type is ignored, no "identify" rows are inserted into the database at this time. Later, as the user adds an email address or platform uids, they will be inserted.
NOTE: If the person we are representing here comes and registers the regular way, and then later adds an email, mobile, or authenticates with a platform, which happens to match the "future" mapping we inserted in users_identify table, then this futureUser will not be converted, since they already registered a different user. Later on, we may have some sort function to merge users together. -
[$status=null]
&string optionalThe status of the user - 'verified' or 'future'
Returns:
getLanguage
-
$userId
Get default user language from users_user table
Parameters:
-
$userId
String
Returns:
hashPassphrase
-
$passphrase
Hashes a passphrase
Parameters:
-
$passphrase
Stringthe passphrase to hash
Returns:
the hashed passphrase, or "" if the passphrase was ""
hashPassphrase
-
$passphrase
-
$existing_hash
Verifies a passphrase against a hash generated previously
Parameters:
-
$passphrase
Stringthe passphrase to hash
-
$existing_hash
Stringthe hash that is was previously generated
Returns:
whether the password is verified to be correct, or not
identify
-
$type
-
$value
-
[$state='verified']
-
[$normalized=null]
Returns Users_Identifier rows that correspond to the identifier in the database, if any.
Parameters:
-
$type
String | Arraycan be "email", "mobile",the name of a platform, or any of the above with optional "_hashed" suffix to indicate that the value has already been hashed. It could also be an array of ($type => $value) pairs. Then $state should be null.
-
$value
StringThe value corresponding to the type. If $type is
- "email" - this is one of the user's email addresses
- "mobile" - this is one of the user's mobile numbers
- "email_hashed" - this is the standard hash of the user's email address
- "mobile_hashed" - this is the standard hash of the user's mobile number
- $platform - this is the user's id on that platform
-
[$state='verified']
String optionalThe state of the identifier => userId mapping. Could also be 'future' to find identifiers attached to a "future user", and can also be null (in which case we find mappings in all states)
-
[$normalized=null]
&string optional
Returns:
The row corresponding to this type and value, otherwise null
importIcon
-
$user
-
[$urls=array()]
-
[$directory=null]
Imports an icon and sets $user->icon to the url.
Parameters:
-
$user
ArrayThe user for whom the icon should be downloaded
-
[$urls=array()]
Array optionalArray of urls
-
[$directory=null]
String optionalDefaults to APP/files/APP/uploads/Users/USERID/icon/imported
Returns:
the path to the icon directory
isCommunityId
-
$userId
Determine whether a user id is that of a community
Parameters:
-
$userId
StringThe user id to test
Returns:
links
-
$contactInfo
Parameters:
-
$contactInfo
ArrayAn array of key => value pairs, where keys can be "email", "mobile", the name of a platform, or any of the above with optional "_hashed" suffix to indicate that the value has already been hashed.
Returns:
Returns an array of all links to this user's contact info
loggedInUser
-
[$throwIfNotLoggedIn=false]
-
[$startSession=true]
Get the logged-in user's information
Parameters:
-
[$throwIfNotLoggedIn=false]
Boolean optionalWhether to throw a Users_Exception_NotLoggedIn if no user is logged in.
-
[$startSession=true]
Boolean optionalWhether to start a PHP session if one doesn't already exist.
Returns:
login
-
$identifier
-
$passphrase
-
$isHashed
Logs a user in using a login identifier and a pasword
Parameters:
-
$identifier
StringCould be an email address, a mobile number, or a user id.
-
$passphrase
StringThe passphrase to hash, etc.
-
$isHashed
BooleanWhether the first passphrase hash iteration occurred, e.g. on the client
Returns:
logout
()
static
Logs a user out
oAuth
-
$platform
-
[$appId=Q::app()]
Parameters:
-
$platform
StringThe name of the oAuth platform, under Users/apps config
-
[$appId=Q::app()]
String optionalOnly needed if you have multiple apps on platform
Returns:
oAuthClear
-
$platform
-
[$appId=Q::app()]
Parameters:
-
$platform
StringThe name of the oAuth platform, under Users/apps config
-
[$appId=Q::app()]
String optionalOnly needed if you have multiple apps on platform
register
-
$username
-
$identifier
-
[$icon=true]
-
[$options=array()]
Registers a user in the system.
Parameters:
-
$username
StringThe name of the user
-
$identifier
String | ArrayCan be an email address or mobile number. Or it could be an array of $type => $info
-
[identifier]
String optionalan email address or phone number
-
[device]
Array optionalan array with keys "deviceId", "platform", "appId", "version", "formFactor" to store in the Users_Device table for sending notifications
-
[app]
Array optionalan array with "platform" key, and optional "appId"
-
-
[$icon=true]
Array | String | True optionalBy default, the user icon is "default". But you can pass here an array of filename => url pairs, or a gravatar url to download the various sizes from gravatar. Finally, you can pass true to generate an icon instead of using the default icon. If $identifier['app']['platform'] is specified, and $icon==true, then an attempt will be made to download the icon from the user's account on the platform.
-
[$options=array()]
Array optionalAn array of options that could include:
-
[activation]
String optionalThe key under "Users"/"transactional" config to use for sending an activation message. Set to false to skip sending the activation message for some reason.
-
Returns:
requestedIdentifier
-
[$type=null]
Get the email address or mobile number from the request, if it can be deduced. Note: it should still be tested for validity.
Parameters:
-
[$type=null]
&string optionalThe identifier's type will be filled here. Might be "email", "mobile", "facebook" etc.
Returns:
The identifier, or null if one wasn't requested
roles
-
string
-
[$filter=null]
-
[$options=array()]
-
[$userId=null]
Rturn an array of the user's roles relative to a publisher
Parameters:
-
string
Object[$publisherId=Users::communityId()] The id of the publisher relative to whom to calculate the roles. Defaults to the community id.
-
[$filter=null]
String | Array | Db_Expression optionalYou can pass additional criteria here for the label field in the
Users_Contact::select
, such as an array or Db_Range -
[$options=array()]
Array optionalAny additional options to pass to the query, such as "ignoreCache"
-
[$userId=null]
String optionalIf not passed, the logged in user is used, if any
Returns:
An associative array of $roleName => $contactRow pairs
saveContactsFromLinks
-
$contactInfo
-
$userId
Inserts some Users_Contact rows for the locally registered users who have added links to this particular contact information. Removes the links after successfully adding the Users_Contact rows.
Parameters:
-
$contactInfo
ArrayAn array of key => value pairs, where keys can be "email", "mobile", the name of a platform, or any of the above with optional "_hashed" suffix to indicate that the value has already been hashed.
-
$userId
StringThe id of the user who has verified these identifiers
setLoggedInUser
-
$user
-
[$options]
Use with caution! This bypasses the usual methods of authentication. This functionality should not be exposed externally.
Parameters:
-
$user
Users_User | StringThe user object or user id
-
[$options]
Array optionalSome options for the method
-
[notice=Q_Config::expect('Users','login','notice')]
String optionalA notice to show to the newly logged-in user that they have been logged in. This notice only appears if another user was logged in before this method was called, to draw their attention to the sudden switch. To turn off this notice, pass null here.
-
[keepSessionId=false]
Boolean optionalSet to true to skip regenerating the session id, perhaps because you just generated your own session id and you are sure that there cannot be any session fixation attacks.
-
Returns:
Whether logged in user id was changed.
userFromContactInfo
-
$type
-
$value
Returns a user in the database that corresponds to the contact info, if any.
Parameters:
-
$type
Stringcan be "email", "mobile",the name of a platform, or any of the above with optional "_hashed" suffix to indicate that the value has already been hashed.
-
$value
StringThe value corresponding to the type. If $type is
- "email" - this is one of the user's email addresses
- "mobile" - this is one of the user's mobile numbers
- "email_hashed" - this is the standard hash of the user's email address
- "mobile_hashed" - this is the standard hash of the user's mobile number
- $platform - this is the user's id on that platform
Returns:
Properties
$cache
Array
Default: array()
$loggedOut
Boolean
Events
Users/authenticate
After
Event Payload:
-
platform
String -
appId
String
Users/authenticate
Before
Event Payload:
-
platform
String -
appId
String
Users/login
Before
Event Payload:
-
identifier
String -
passphrase
String
Users/logout
Before
One last chance to do something. Hooks shouldn't be able to cancel the logout, though.
Event Payload:
-
user
Users_User
Users/register
Before
Event Payload:
-
username
String -
identifier
String | Array -
icon
String -
platform
String
Users/register
After
Event Payload:
-
username
String -
identifier
String | Array -
icon
String -
user
Users_User -
platform
String
Users/saveContactsFromLinks
Before
Users/saveContactsFromLinks
After
Event Payload:
-
contacts
Array