Class: UserFactory

binding.UserFactory(propertiesopt, …arguments) → {model.User}

new UserFactory(propertiesopt, …arguments) → {model.User}

Parameters:
Name Type Attributes Description
properties Object <optional>

initial properties to set on the instance

arguments * <repeatable>

Additional constructor params passed through the type constructor

Source:
Returns:

The new managed instance

Type
model.User

Extends

Members

(static) DefaultOptions

Properties:
Name Type Description
oauth Object

default properties

Properties
Name Type Description
google Object

default oauth properties for Google

facebook Object

default oauth properties for Facebook

github Object

default oauth properties for GitHub

twitter Object

default oauth properties for Twitter

linkedin Object

default oauth properties for LinkedIn

Source:

(static) LoginOption :number

Type:
  • number
Properties:
Name Type Description
NO_LOGIN number

Do not login the user after a successful registration

SESSION_LOGIN number

Login in after a successful registration and keep the token in a nonpermanent storage, i.e SessionStorage

PERSIST_LOGIN number

Login in after a successful registration and keep the token in a persistent storage, i.e LocalStorage

Source:

(readonly) me :model.User

The current logged in user, or null if the user is not logged in

Type:
Source:

Methods

changeUsername(username, newUsername, password, doneCallbackopt, failCallbackopt) → {Promise.<*>}

Sends an email with a link to change the current username

The user is identified by their current username and password.
The username must be a valid email address.

Parameters:
Name Type Attributes Description
username string

Current username (email) to identify the user

newUsername string

New username (email) to change the current username to

password string

The current password of the user. Has to be passed to the function for security reason

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<*>

login(username, password, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Log in the user with the given username and password and starts a user session

Parameters:
Name Type Attributes Default Description
username string

The username of the user

password string

The password of the user

loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over
multiple sessions

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

loginWithFacebook(clientID, optionsopt, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Logs the user in with Facebook via OAuth

Prompts the user for the Facebook login in a new window. Before using OAuth you need to setup your application
on the provider website, add the redirect uri: https://example.net/db/User/OAuth/facebook and copy the client id
and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.

Parameters:
Name Type Attributes Default Description
clientID string
options Object <optional>
loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over
multiple sessions

options.title string <optional>
"Login"

sets the title of the popup window

options.width number <optional>
1140

defines the width of the popup window

options.height number <optional>
640

defines the height of the popup window

options.scope string <optional>
"email"

the range of rights requested from the user

options.state Object <optional>
{}
options.timeout number <optional>
5 * 60 * 1000
options.redirect string <optional>
""

if set this changes the oauth behaviour to redirect mode, i.e. this site is
closed to open the providers login page. Once the login is finished this redirect url will be opened
with the logged-in user's token attached.

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

loginWithGitHub(clientID, optionsopt, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Logs the user in with GitHub via OAuth

Prompts the user for the GitHub login in a new window. Before using OAuth you need to setup your application
on the provider website, add the redirect uri: https://example.net/db/User/OAuth/github and copy the client id
and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.

Parameters:
Name Type Attributes Default Description
clientID string
options Object <optional>
loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over*
multiple sessions

options.title string <optional>
"Login"

sets the title of the popup window

options.width number <optional>
1040

defines the width of the popup window

options.height number <optional>
580

defines the height of the popup window

options.scope string <optional>
"user:email"

the range of rights requested from the user

options.state Object <optional>
{}
options.timeout number <optional>
5 * 60 * 1000
options.redirect string <optional>
""

if set this changes the oauth behaviour to redirect mode, i.e. this site is
closed to open the providers login page. Once the login is finished this redirect url will be opened
with the logged-in user's token attached.

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

loginWithGoogle(clientID, optionsopt, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Logs the user in with Google via OAuth

Prompts the user for the Google login in a new window. Before using OAuth you need to setup your application
on the provider website, add the redirect uri: https://example.net/db/User/OAuth/google and copy the
client id and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is
logged in.

Parameters:
Name Type Attributes Default Description
clientID string
options Object <optional>
loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over
multiple sessions

options.title string <optional>
"Login"

sets the title of the popup window

options.width number <optional>
585

defines the width of the popup window

options.height number <optional>
545

defines the height of the popup window

options.scope string <optional>
"email"

the range of rights requested from the user

options.state Object <optional>
{}
options.timeout number <optional>
5 * 60 * 1000
options.redirect string <optional>
""

if set this changes the oauth behaviour to redirect mode,
i.e. this site is closed to open the providers login page.
Once the login is finished this redirect url will be opened with the logged-in user's token attached.

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

loginWithLinkedIn(clientID, optionsopt, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Logs the user in with LinkedIn via OAuth

Prompts the user for the LinkedIn login in a new window. Before using OAuth you need to setup your application
on the provider website, add the redirect uri: https://example.net/db/User/OAuth/linkedin and copy the client id
and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.

Parameters:
Name Type Attributes Default Description
clientID string
options Object <optional>
loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over
multiple sessions

options.title string <optional>
"Login"

sets the title of the popup window

options.width number <optional>
630

defines the width of the popup window

options.height number <optional>
530

defines the height of the popup window

options.scope string <optional>
""

the range of rights requested from the user

options.state Object <optional>
{}
options.timeout number <optional>
5 * 60 * 1000
options.redirect string <optional>
""

if set this changes the oauth behaviour to redirect mode, i.e. this site is
closed to open the providers login page. Once the login is finished this redirect url will be opened
with the logged-in user's token attached.

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

loginWithToken(token, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Log in the user assiciated with the given token and starts a user session.

Parameters:
Name Type Attributes Default Description
token string

The user token.

loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over
multiple sessions

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

loginWithTwitter(clientID, optionsopt, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Logs the user in with Twitter via OAuth

Prompts the user for the Twitter login in a new window. Before using OAuth you need to setup your application
on the provider website, add the redirect uri: https://example.net/db/User/OAuth/twitter and copy the client id
and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.

Parameters:
Name Type Attributes Default Description
clientID string
options Object <optional>
loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over
multiple sessions

options.title string <optional>
"Login"

sets the title of the popup window

options.width number <optional>
740

defines the width of the popup window

options.height number <optional>
730

defines the height of the popup window

options.timeout number <optional>
5 * 60 * 1000
options.redirect string <optional>
""

if set this changes the oauth behaviour to redirect mode,
i.e. this site is
closed to open the providers login page. Once the login is finished this redirect url will be opened
with the logged-in user's token attached.

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

logout(doneCallbackopt, failCallbackopt) → {Promise.<*>}

Log out the current logged in user and ends the active user session

Parameters:
Name Type Attributes Description
doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<*>

new(properties) → {model.User}

Creates a new user object

Parameters:
Name Type Description
properties Object.<string, *>

Additional properties which will be applied to the created instance

Source:
Returns:

A new created user

Type
model.User

newPassword(username, password, newPassword, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Change the password of the given user

Parameters:
Name Type Attributes Description
username string

Username to identify the user

password string

Current password of the user

newPassword string

New password of the user

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<model.User>

newPassword(token, newPassword, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Change the password of a user, which will be identified by the given token from the reset password e-mail

Parameters:
Name Type Attributes Default Description
token string

Token from the reset password e-mail

newPassword string

New password of the user

loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default keeps the user logged in over multiple sessions

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
See:
  • resetPassword
Returns:
Type
Promise.<model.User>

register(user, password, loginOptionopt, doneCallbackopt, failCallbackopt) → {Promise.<model.User>}

Register a new user with the given username and password, if the username is not used by an another user.

Parameters:
Name Type Attributes Default Description
user string | model.User

The username as a string or a Object, which must contain the username.

password string

The password for the given user

loginOption boolean | binding.UserFactory.LoginOption <optional>
true

The default logs the user in after a successful
registration and keeps the user logged in over multiple sessions

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:

The created user object, for the new registered user.

Type
Promise.<model.User>

requestAPIToken(user, doneCallbackopt, failCallbackopt) → {Promise.<*>}

Requests a perpetual token for the given user

Only users with the admin role are allowed to request an API token.

Parameters:
Name Type Attributes Description
user binding.User | String

The user object or id of the user object

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<*>

resetPassword(username, doneCallbackopt, failCallbackopt) → {Promise.<*>}

Sends an email with a link to reset the password for the given username

The username must be a valid email address.

Parameters:
Name Type Attributes Description
username string

Username (email) to identify the user

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<*>

revokeAllTokens(user, doneCallbackopt, failCallbackopt) → {Promise.<*>}

Revoke all created tokens for the given user

This method will revoke all previously issued tokens and the user must login again.

Parameters:
Name Type Attributes Description
user binding.User | String

The user object or id of the user object

doneCallback binding.Entity~doneCallback <optional>

Called when the operation succeed.

failCallback binding.Entity~failCallback <optional>

Called when the operation failed.

Source:
Returns:
Type
Promise.<*>