Show:

Users Class

Users plugin's front end code

Methods

authenticate

(
  • platform
  • onSuccess
  • onCancel
  • [options]
)

Authenticates this session with a given platform

Parameters:

  • platform String

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

  • onSuccess Function

    Called if the user successfully authenticates with the platform, or was already authenticated. It is passed the user information if the user changed.

  • onCancel Function

    Called if the authentication was canceled.

  • [options] Object optional

    object of parameters for authentication function

    • [prompt=null] Function | Boolean optional

      which shows the usual prompt unless it was already rejected once. Can be false, in which case the user is never prompted and the authentication just happens. Can be true, in which case the usual prompt is shown even if it was rejected before. Can be a function with an onSuccess and onCancel callback, in which case it's used as a prompt.

    • [force] Boolean optional

      forces the getLoginStatus to refresh its status

    • [appId=Q.info.app] String optional

      Only needed if you have multiple apps on platform

facebookDialog

(
  • [options]
)

Makes a dialog that resembles a facebook dialog

Parameters:

  • [options] Object optional

    A hash of options, that can include:

    • [title] String optional

      Dialog title.

    • [content] String optional

      Dialog content, can be plain text or some html.

    • [buttons] Array optional

      Array of object containing fields:

      • [label] String optional
        is the label of the button
      • [handler] Function optional
        is a click handler for the button
      • [default] Boolean optional
        is a boolean which makes this button styled as default.
    • [position] Object optional

      Hash of x/y coordinates. By default (or if null) dialog is centered on the screen.

    • [shadow] Boolean optional

      Whether to make a full screen shadow behind the dialog, making other elements on the page inaccessible.

get

(
  • userId
  • callback
)

Users batch getter.

Parameters:

  • userId String

    The user's id

  • callback Function

    if there were errors, first parameter is an array of errors otherwise, first parameter is null and second parameter is a Users.User object

getContacts

(
  • userId
  • [labels]
  • [contactUserIds]
  • callback
)
static

Get a user's contacts

Parameters:

getLabels

(
  • userId
  • [prefix]
  • callback
)
static

Get a user's contact labels

Parameters:

  • userId String
  • [prefix] String optional

    Pass any prefix here, to filter labels by this prefix

  • callback Function

hint

(
  • key
  • elementsOrPoints
  • [options.src]
  • [options.hotspot={x:0.5,y:0.3}]
  • [options.width="200px"]
  • [options.height="200px"]
  • [options.zIndex=99999]
  • [option.dontStopBeforeShown=false]
  • [options.dontRemove=false]
  • [options.audio.src]
  • [options.audio.from=0]
  • [options.audio.until]
  • [options.audio.removeAfterPlaying]
  • [options.show.delay=500]
  • [options.show.initialScale=10]
  • [options.show.duration=500]
  • [options.show.ease=Q.Animation.ease.smooth]
  • [options.hide.duration=500]
  • [options.hide.ease=Q.Animation.ease.smooth]
)
static

Places a hint to click or tap on the screen

Parameters:

  • key String

    A key to ensure the hint appears only the first time for each user. Check Users.hinted to see if this has happened.

  • elementsOrPoints Element | Object | Array

    Indicates where to display the hint. A point should contain properties "x" and "y". Can also be an array of elements or points.

  • [options.src] String optional

    the url of the hint pointer image

  • [options.hotspot={x:0.5,y:0.3}] Point optional

    "x" and "y" represent the location of the hotspot within the image, using fractions between 0 and 1

  • [options.width="200px"] String optional
  • [options.height="200px"] String optional
  • [options.zIndex=99999] Integer optional
  • [option.dontStopBeforeShown=false] Boolean optional

    Don't let Q.Pointer.stopHints stop this hint before it's shown.

  • [options.dontRemove=false] Boolean optional

    Pass true to keep current hints displayed

  • [options.audio.src] String optional

    Can be used to play an audio file.

  • [options.audio.from=0] String optional

    Number of seconds inside the audio to start playing the audio from. Make sure audio is longer than this.

  • [options.audio.until] String optional

    Number of seconds inside the audio to play the audio until. Make sure audio is longer than this.

  • [options.audio.removeAfterPlaying] String optional

    Whether to remove the audio object after playing

  • [options.show.delay=500] Integer optional

    How long to wait after the function call (or after audio file has loaded and starts playing, if one was specified) before showing the hint animation

  • [options.show.initialScale=10] Integer optional

    The initial scale of the hint pointer image in the show animation

  • [options.show.duration=500] Integer optional

    The duration of the hint show animation

  • [options.show.ease=Q.Animation.ease.smooth] Function optional
  • [options.hide.duration=500] Integer optional

    The duration of the hint hide animation

  • [options.hide.ease=Q.Animation.ease.smooth] Function optional

hint

(
  • forType
  • forId
  • [value=1]
  • elementOrPoint
  • [options]
)
Boolean static

Votes for something

Parameters:

  • forType String

    The type of thing to vote for

  • forId String

    The id of thing to vote for

  • [value=1] Number optional

    the value the user has voted for, such as a rating etc.

  • elementOrPoint Element | Object

    Indicates where to display the hint. A point should contain properties "x" and "y".

  • [options] Object optional

    possible options, which can include:

    • [src] String optional

      the url of the image

    • [hotspot={x:0.5,y:0.4}] Point optional

      "x" and "y" represent the location of the hotspot within the image, using fractions between 0 and 1

    • [width="200px"] String optional
    • [height="200px"] String optional
    • [zIndex=99999] Number optional

Returns:

Boolean:

Returns true if the hint with will be shown, or false if a hint with this key was already shown before.

(
  • icon
  • [basename=40]
)
String

Calculate the url of a user's icon

Parameters:

  • icon String

    the value of the user's "icon" field

  • [basename=40] String | Number optional

    The last part after the slash, such as "50.png"

Returns:

String:

the url

initFacebook

(
  • callback
  • options
)

Initialize facebook by adding FB script and running FB.init(). Ensures that this is done only once

Parameters:

  • callback Function

    , This function called after Facebook init completed

  • options Object

    for overriding the options passed to FB.init , and also

    • [appId=Q.info.app] String optional

      Only needed if you have multiple apps on platform

(
  • [size=40]
)
String

Calculate the url of a user's icon

Parameters:

  • [size=40] Number optional

    the size of the icon to render.

Returns:

String:

the url

initFacebook.ready

(
  • [appId=Q.info.app]
  • callback
)

You can wrap all uses of FB object with this

Parameters:

  • [appId=Q.info.app] String optional

    only specify this if you have multiple facebook apps

  • callback Function

    this function called after Facebook application access token or user status response

loggedInUserId

() String static

A shorthand way to get the id of the logged-in user, if any

Returns:

String:

the id of the logged-in user, or the empty string if not logged in

login

(
  • [options]
)

Log the user in

Parameters:

  • [options] Object optional

    You can pass several options here

    • [onSuccess] Q.Event optional

      event that occurs when login or authentication "using" a platform is successful. It is passed (user, options, result, used) where user is the Users.User object (null if it was unchanged), options were the options used in the call to Users.login, result is one of "registered", "adopted", "connected" or "authorized" (see Users::authenticate) and 'used' is "native", or the name of the platform used, such as "facebook".

    • [onCancel] Function optional

      event that occurs when login or authentication "using" a platform was canceled.

    • [onResult] Function optional

      event that occurs before either onSuccess, onCancel, or onRequireComplete

    • [successUrl] String optional

      If the default onSuccess implementation is used, the browser is redirected here. Defaults to Q.uris[Q.info.app+'/home']

    • [accountStatusUrl] String optional

      if passed, this URL is hit to determine if the account is complete

    • [onRequireComplete] Function optional

      function to call if the user logged in but account is incomplete. It is passed the user information as well as the response from hitting accountStatusUrl

    • [using] String optional

      can be "native", "facebook" or "native,facebook"

    • [tryQuietly] Boolean optional

      if true, this is same as Users.authenticate, with platform = "using" option

    • [unlessLoggedIn] Boolean optional

      if true, this only proceeds with the login flow if the user isn't already logged in. Can be combined with tryQuietly option.

    • [scope=['email','public_profile','user_friends'] Array optional

      permissions to request from the authentication platform

    • [identifierType="email,mobile"] String optional

      the type of the identifier, which could be "mobile" or "email" or "email,mobile"

    • [appIds={}] Object optional

      Can be used to set custom {platform: appId} pairs

logout

(
  • [options]
)

Log the user out

Parameters:

  • [options] Object optional

    You can pass several options here It is passed the user information if the user changed.

    • [url] String optional

      the URL to hit to log out. You should usually not change this.

    • [using] String optional

      can be "native" or "native,facebook" to log out of both

    • [onSuccess] Q.Event optional

      event that occurs when logout is successful.

    • [welcomeUrl] String optional

      the URL of the page to show on a successful logout

prompt

(
  • platform
  • uid
  • authCallback
  • cancelCallback
  • options
  • options
)

Used when platform user is logged in to platform but not to app. Shows prompt asking if user wants to log in to the app as platform user.

Parameters:

  • platform String

    For now, only "facebook" is supported

  • uid String

    The platform uid

  • authCallback Function

    , this function will be called after user authentication

  • cancelCallback Function

    , this function will be called if user closed social platform login window

  • options Object
    • [dialogContainer=document.body] DOMElement optional

      param with jQuery identifier of dialog container

  • options Object
    • [=Q.info.app] String optional

      Only needed if you have multiple apps on platform

scope

(
  • platform
  • callback
  • options
)

Check permissions granted by platform. Currently only facebook is supported.

Parameters:

  • platform String

    For now, only "facebook" is supported

  • callback Function

    this function will be called after getting permissions from the external platform. The first parameter is the raw data returned. The second parameter is an array of Boolean corresponding to the scope names in options.check, indicating whether they were granted. Callback parameter could be null or response object from social platform

  • options Object
    • [appId=Q.info.app] String optional

      Only needed if you have multiple apps on platform

    • [check=[] Array optional

      Scopes to check.

setIdentifier

(
  • [options]
)

Displays a dialog allowing the user to set a different identifier (email address, mobile number, etc.) as their primary login method

Parameters:

  • [options] Object optional

    You can pass several options here It is passed the user information if the user changed.

    • [identifierType] String optional

      the type of the identifier, which could be "mobile" or "email" or "email,mobile"

    • [userId] String optional

      You can set this to the id of a user in the database who doesn't have any email or mobile number set yet. This can happen if the user was e.g. invited via a printed invitation and lost it, and allows someone to help set up the first identifier for that user.

    • [onSuccess] Q.Event optional

      event that occurs on success

    • [onCancel] Q.Event optional

      event that occurs if the dialog is canceled

    • [onResult] Function optional

      event that occurs before either onSuccess or onCancel

User

(
  • fields
)

Constructs a user from fields, which are typically returned from the server.

Parameters:

Properties

Q.text.Users

Object

Text messages used in dialogs

Events

onDevice

This event is fired when a device has been registered for a logged-in user.

Event Payload:

  • device Object

    See Users_Device

onError

This event is fired if an error occurs in any Users function

Event Payload:

  • err Mixed
  • err2 Mixed