getUser

:getUser( userId, callback )

Gets user data based on userId.

Parameters

Name Details
userId The users objectId. (String, required)
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

Examples


registerUser

:registerUser( registrationData, callback )

Adds a new user.

Parameters

Name Details
registrationData A table of data to be stored for the User record. An email and password key are required for the User log in. (Table, required)
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

This method will return either a status code from Mongo DB, or the newly created Users objectId in the return event.

The default mode is to return the status code from Mongo, with 0 being success.

mc:registerUser({
  email = ...,
  password = ...,
  ...
}, function( event )
  print( event.result )
end)

Examples

--== Register user callback ==--
local function onRegisterUser( e )
  print( e.result )
end
--== Register the user ==--
mc:registerUser({
  email = "user@email.com", --REQUIRED
  password = "2468", --REQUIRED
  fav_color = "Blue",
  age = 24,
  dogs = { "danny", "fido", "suzy" }
}, onRegisterUser )

loginUser

:loginUser( email, password, callback )

Logs in the user and starts a session.

Parameters

Name Details
email The users stored email in the user record. (String, required)
password The users password. (String, required)
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

The User object. User will contain at minimum the following keys:

Name Details
objectId Assigned public ID
sessionToken The User session token
... User supplied table key/values

Examples

mc:loginUser("me@home.com", "1234", function( event )
  print( event.result.sessionToken )
  print( event.result.objectId )
end)

getMe

:getMe( callback )

Returns the currently logged in user.

Parameters

Name Details
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

Examples


updateUser

:updateUser( updateData, callback )

Updates a user record.

Parameters

Name Details
updateUser A table of data to be stored for the User record. (Table, required)
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

Examples


linkUserDevice

:linkUserDevice( deviceToken, addToPushBots, callback )

Add a user device to a user record.

Parameters

Name Details
deviceToken The users device token. (String, required)
addToPushBots Also register this device with PushBots.com. (Boolean, optional)
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

Examples


unlinkUserDevice

:unlinkUserDevice( deviceToken, removeFromPushBots, callback )

Removes a user device from a user record.

Parameters

Name Details
deviceToken The users device token. (String, required)
removeFromPushBots Also unregister this device from PushBots.com. (Boolean, optional)
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

Examples


logoutUser

:logoutUser( callback )

Logs out the currently logged in user, deleting the session.

Parameters

Name Details
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

Examples

requestPassword

:requestPassword( email, callback )

Initiates a password reset.

Parameters

Name Details
email The email of the user on record. (String, required)
callback The callback function. If not provided the global callback will be used. (Function, optional)

Returns

Examples