Show:

Users Class

Extends Base_Users
Module: Users

Static methods for the Users models.

Methods

appId

(
  • $platform
  • $appId
)
Array static

Get the internal app id and info

Parameters:

  • $platform String

    The platform or platform for the app

  • $appId String

    Can be either an internal or external app id

Returns:

Array:

Returns array($appId, $appInfo)

authenticate

(
  • $platform
  • [$appId=null]
  • [$authenticated=null]
  • [$import=Q_Config::get('Users','import',$platform)]
)
Users_User static

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 String

    Currently only supports "facebook", "ios" or "android"

  • [$appId=null] String optional

    The id of the app within the specified platform.

  • [$authenticated=null] &boolean optional

    If 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 optional

    Array 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:

String:

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:

String:

The name of the main community for the installed app.

external

(
  • $publisherId
  • $userId
)
Users_External

Returns external data about the user

Parameters:

  • $publisherId String

    The id of the user corresponding to the publisher consuming the external data

  • $userId String

    The id of the user whose external data is going to be consumed

Returns:

Users_External:

fetch

(
  • $userId
  • [$throwIfMissing=false]
)
Users_User | Null static

Intelligently retrieves user by id

Parameters:

  • $userId String
  • [$throwIfMissing=false] Boolean optional

    If true, throws an exception if the user can't be fetched

Returns:

Users_User | Null:

futureUser

(
  • $type
  • $value
  • [$status=null]
)
Users_User

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 String

    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.

  • $value String

    The 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 optional

    The status of the user - 'verified' or 'future'

Returns:

getLanguage

(
  • $userId
)
String static

Get default user language from users_user table

Parameters:

  • $userId String

Returns:

String:

hashPassphrase

(
  • $passphrase
)
String static

Hashes a passphrase

Parameters:

  • $passphrase String

    the passphrase to hash

Returns:

String:

the hashed passphrase, or "" if the passphrase was ""

hashPassphrase

(
  • $passphrase
  • $existing_hash
)
Boolean static

Verifies a passphrase against a hash generated previously

Parameters:

  • $passphrase String

    the passphrase to hash

  • $existing_hash String

    the hash that is was previously generated

Returns:

Boolean:

whether the password is verified to be correct, or not

identify

(
  • $type
  • $value
  • [$state='verified']
  • [$normalized=null]
)
Users_Identify | Null static

Returns Users_Identifier rows that correspond to the identifier in the database, if any.

Parameters:

  • $type String | Array

    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 could also be an array of ($type => $value) pairs. Then $state should be null.

  • $value String

    The 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 optional

    The 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:

Users_Identify | Null:

The row corresponding to this type and value, otherwise null

importIcon

(
  • $user
  • [$urls=array()]
  • [$directory=null]
)
String static

Imports an icon and sets $user->icon to the url.

Parameters:

  • $user Array

    The user for whom the icon should be downloaded

  • [$urls=array()] Array optional

    Array of urls

  • [$directory=null] String optional

    Defaults to APP/files/APP/uploads/Users/USERID/icon/imported

Returns:

String:

the path to the icon directory

isCommunityId

(
  • $userId
)
Boolean static

Determine whether a user id is that of a community

Parameters:

  • $userId String

    The user id to test

Returns:

Boolean:

loggedInUser

(
  • [$throwIfNotLoggedIn=false]
  • [$startSession=true]
)
Users_User | Null static

Get the logged-in user's information

Parameters:

  • [$throwIfNotLoggedIn=false] Boolean optional

    Whether to throw a Users_Exception_NotLoggedIn if no user is logged in.

  • [$startSession=true] Boolean optional

    Whether to start a PHP session if one doesn't already exist.

Returns:

Users_User | Null:

login

(
  • $identifier
  • $passphrase
  • $isHashed
)
Users_User static

Logs a user in using a login identifier and a pasword

Parameters:

  • $identifier String

    Could be an email address, a mobile number, or a user id.

  • $passphrase String

    The passphrase to hash, etc.

  • $isHashed Boolean

    Whether the first passphrase hash iteration occurred, e.g. on the client

Returns:

logout

() static

Logs a user out

oAuth

(
  • $platform
  • [$appId=Q::app()]
)
Zend_Oauth_Client static

Parameters:

  • $platform String

    The name of the oAuth platform, under Users/apps config

  • [$appId=Q::app()] String optional

    Only needed if you have multiple apps on platform

Returns:

Zend_Oauth_Client:

oAuthClear

(
  • $platform
  • [$appId=Q::app()]
)
static

Parameters:

  • $platform String

    The name of the oAuth platform, under Users/apps config

  • [$appId=Q::app()] String optional

    Only needed if you have multiple apps on platform

register

(
  • $username
  • $identifier
  • [$icon=true]
  • [$options=array()]
)
Users_User static

Registers a user in the system.

Parameters:

  • $username String

    The name of the user

  • $identifier String | Array

    Can be an email address or mobile number. Or it could be an array of $type => $info

    • [identifier] String optional

      an email address or phone number

    • [device] Array optional

      an array with keys "deviceId", "platform", "appId", "version", "formFactor" to store in the Users_Device table for sending notifications

    • [app] Array optional

      an array with "platform" key, and optional "appId"

  • [$icon=true] Array | String | True optional

    By 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 optional

    An array of options that could include:

    • [activation] String optional

      The 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]
)
String | Null static

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 optional

    The identifier's type will be filled here. Might be "email", "mobile", "facebook" etc.

Returns:

String | Null:

The identifier, or null if one wasn't requested

roles

(
  • string
  • [$filter=null]
  • [$options=array()]
  • [$userId=null]
)
Array static

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 optional

    You can pass additional criteria here for the label field in the Users_Contact::select, such as an array or Db_Range

  • [$options=array()] Array optional

    Any additional options to pass to the query, such as "ignoreCache"

  • [$userId=null] String optional

    If not passed, the logged in user is used, if any

Returns:

Array:

An associative array of $roleName => $contactRow pairs

setLoggedInUser

(
  • $user
  • [$options]
)
Boolean static

Use with caution! This bypasses the usual methods of authentication. This functionality should not be exposed externally.

Parameters:

  • $user Users_User | String

    The user object or user id

  • [$options] Array optional

    Some options for the method

    • [notice=Q_Config::expect('Users','login','notice')] String optional

      A 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 optional

      Set 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:

Boolean:

Whether logged in user id was changed.

userFromContactInfo

(
  • $type
  • $value
)
Users_User | Null static

Returns a user in the database that corresponds to the contact info, if any.

Parameters:

  • $type String

    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.

  • $value String

    The 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:

Users_User | Null:

Properties

$cache

Array

Default: array()

$loggedOut

Boolean

Events

Users/adoptFutureUser

Before

Event Payload:

Users/adoptFutureUser

Before

Event Payload:

Users/adoptFutureUser

After

Event Payload:

Users/authenticate

After

Event Payload:

  • platform String
  • appId String

Users/authenticate

Before

Event Payload:

  • platform String
  • appId String

Users/authenticate/insertAppUser

After

Event Payload:

Users/authenticate/updateAppUser

Before

Event Payload:

Users/authenticate/updateAppUser

Before

Event Payload:

Users/authenticate/updateAppUser

After

Event Payload:

Users/authenticate/updateAppUser

After

Event Payload:

Users/insertAppUser

Before

Event Payload:

Users/insertUser

After

Event Payload:

Users/insertUser

After

Event Payload:

Users/insertUser

Before

Event Payload:

Users/insertUser

Before

Event Payload:

Users/insertUser

After

Event Payload:

Users/insertUser

Before

Event Payload:

Users/login

After

Event Payload:

  • identifier String
  • passphrase String
  • 'user' Users_User

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:

Users/logout

After

After the logout has taken place

Event Payload:

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/setLoggedInUser

After

Event Payload:

Users/setLoggedInUser

Before

Event Payload:

Users/setLoggedInUser/updateSessionId

After

Event Payload:

Users/setLoggedInUser/updateSessionId

Before

Event Payload:

Users/updateUser

After

Event Payload: