@harishreddym/baqend
Version:
Baqend JavaScript SDK
883 lines (706 loc) • 40.3 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>Baqend JavaScript SDK 2.14.1 - Source: lib/binding/UserFactory.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/bootstrap-baqend.min.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/font-awesome-4.7.0.css">
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-inner container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Main title -->
<a class="navbar-brand" href="/"><img src="img/logo.png"></a>
</div>
<!-- Expanded navigation -->
<div id="nav" class="navbar-collapse collapse">
<!-- Search -->
<form class="navbar-right form-inline search-form">
<div class="form-group search-form-group">
<input type="search" class="form-control search-input" id="search-query" placeholder="Search Guide" name="q" autocomplete="off">
<div id="search-results" class="search-results">
<p class="search-no-results">Please enter a search query ...</p>
</div>
<i class="search-icon fa fa-search"></i>
</div>
</form>
<!-- Main navigation -->
<ul class="nav navbar-nav">
<li>
<a href="https://dashboard.baqend.com/">Dashboard</a>
</li>
<!-- Guide Navigation -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Guide <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="https://www.baqend.com/guide/">Home</a></li>
<li><a href="https://www.baqend.com/guide/#speed-kit">Speed Kit</a></li>
<li><a href="https://www.baqend.com/guide/#platform">Platform</a></li>
<li><a href="https://www.baqend.com/guide/roadmap/">Roadmap</a></li>
<li><a href="https://www.baqend.com/guide/topics/faq/">FAQ</a></li>
</ul>
</li>
<!-- Starter Kits -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Starter Kits <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="https://www.baqend.com/guide/starter-kits/">Starter Kits Overview</a></li>
<li><a href="https://www.baqend.com/guide/starter-kits/angular2/">Angular 2 Starter Kit</a></li>
<li><a href="https://www.baqend.com/guide/starter-kits/react/">React and Redux Starter Kit</a></li>
<li><a href="https://www.baqend.com/guide/starter-kits/bootstrap/">Bootstrap Starter Kit</a></li>
<li><a href="https://www.baqend.com/guide/starter-kits/ionic2/">Ionic 2 Starter Kit</a></li>
<li><a href="https://www.baqend.com/guide/starter-kits/ionic/">Ionic Starter Kit</a></li>
</ul>
</li>
<li class="active">
<a href="baqend.html">JS API</a>
</li>
<li>
<a href="https://www.baqend.com/tutorial.html">Tutorial</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="box gray pt-32 pb-32">
<div class="container">
<div class="row">
<!-- <div class="col-md-3"></div> -->
<div class="bs-sidebar hidden-print fixed affix" role="complementary">
<input class="filter form-control input-sm" type="text" placeholder="FILTER"/>
<ul class="nav bs-sidenav">
<li class=""><a href="Acl.html" class="nav-name">Acl</a></li>
<li class=""><a href="EntityManager.html" class="nav-name">EntityManager</a></li>
<li class=""><a href="EntityManagerFactory.html" class="nav-name">EntityManagerFactory</a></li>
<li class=""><a href="GeoPoint.html" class="nav-name">GeoPoint</a></li>
<li class=""><a href="RealtimeEvent.html" class="nav-name">RealtimeEvent</a></li>
<li class=""><a href="baqend.html" class="nav-name">baqend</a></li>
<li class="">
<a href="binding.html" class="nav-name">binding</a>
<ul class="nav">
<li class=""><a href="binding.Accessor.html" class="nav-name">Accessor</a></li>
<li class=""><a href="binding.DeviceFactory.html" class="nav-name">DeviceFactory</a></li>
<li class=""><a href="binding.Enhancer.html" class="nav-name">Enhancer</a></li>
<li class=""><a href="binding.Entity.html" class="nav-name">Entity</a></li>
<li class=""><a href="binding.EntityFactory.html" class="nav-name">EntityFactory</a></li>
<li class=""><a href="binding.Factory.html" class="nav-name">Factory</a></li>
<li class=""><a href="binding.File.html" class="nav-name">File</a></li>
<li class=""><a href="binding.FileFactory.html" class="nav-name">FileFactory</a></li>
<li class=""><a href="binding.Managed.html" class="nav-name">Managed</a></li>
<li class=""><a href="binding.ManagedFactory.html" class="nav-name">ManagedFactory</a></li>
<li class=""><a href="binding.Role.html" class="nav-name">Role</a></li>
<li class=""><a href="binding.User.html" class="nav-name">User</a></li>
<li class=""><a href="binding.UserFactory.html" class="nav-name">UserFactory</a></li>
</ul>
</li>
<li class="">
<a href="caching.html" class="nav-name">caching</a>
<ul class="nav">
<li class=""><a href="caching.BloomFilter.html" class="nav-name">BloomFilter</a></li>
</ul>
</li>
<li class="">
<a href="connector.html" class="nav-name">connector</a>
<ul class="nav">
<li class=""><a href="connector.Connector.html" class="nav-name">Connector</a></li>
<li class=""><a href="connector.FetchConnector.html" class="nav-name">FetchConnector</a></li>
<li class=""><a href="connector.IFrameConnector.html" class="nav-name">IFrameConnector</a></li>
<li class=""><a href="connector.Message.html" class="nav-name">Message</a></li>
<li class=""><a href="connector.NodeConnector.html" class="nav-name">NodeConnector</a></li>
<li class=""><a href="connector.ObservableStream.html" class="nav-name">ObservableStream</a></li>
<li class=""><a href="connector.WebSocketConnector.html" class="nav-name">WebSocketConnector</a></li>
<li class=""><a href="connector.XMLHttpConnector.html" class="nav-name">XMLHttpConnector</a></li>
<li class=""><a href="connector.ChannelMessage.html" class="nav-name">ChannelMessage</a></li>
</ul>
</li>
<li class="">
<a href="error.html" class="nav-name">error</a>
<ul class="nav">
<li class=""><a href="error.CommunicationError.html" class="nav-name">CommunicationError</a></li>
<li class=""><a href="error.EntityExistsError.html" class="nav-name">EntityExistsError</a></li>
<li class=""><a href="error.IllegalEntityError.html" class="nav-name">IllegalEntityError</a></li>
<li class=""><a href="error.PersistentError.html" class="nav-name">PersistentError</a></li>
<li class=""><a href="error.RollbackError.html" class="nav-name">RollbackError</a></li>
</ul>
</li>
<li class="">
<a href="metamodel.html" class="nav-name">metamodel</a>
<ul class="nav">
<li class=""><a href="metamodel.Attribute.html" class="nav-name">Attribute</a></li>
<li class=""><a href="metamodel.BasicType.html" class="nav-name">BasicType</a></li>
<li class=""><a href="metamodel.CollectionAttribute.html" class="nav-name">CollectionAttribute</a></li>
<li class=""><a href="metamodel.DbIndex.html" class="nav-name">DbIndex</a></li>
<li class=""><a href="metamodel.EmbeddableType.html" class="nav-name">EmbeddableType</a></li>
<li class=""><a href="metamodel.EntityType.html" class="nav-name">EntityType</a></li>
<li class=""><a href="metamodel.ListAttribute.html" class="nav-name">ListAttribute</a></li>
<li class=""><a href="metamodel.ManagedType.html" class="nav-name">ManagedType</a></li>
<li class=""><a href="metamodel.MapAttribute.html" class="nav-name">MapAttribute</a></li>
<li class=""><a href="metamodel.Metamodel.html" class="nav-name">Metamodel</a></li>
<li class=""><a href="metamodel.ModelBuilder.html" class="nav-name">ModelBuilder</a></li>
<li class=""><a href="metamodel.PluralAttribute.html" class="nav-name">PluralAttribute</a></li>
<li class=""><a href="metamodel.SetAttribute.html" class="nav-name">SetAttribute</a></li>
<li class=""><a href="metamodel.SingularAttribute.html" class="nav-name">SingularAttribute</a></li>
<li class=""><a href="metamodel.Type.html" class="nav-name">Type</a></li>
</ul>
</li>
<li class="">
<a href="model.html" class="nav-name">model</a>
<ul class="nav">
<li class=""><a href="model.Device.html" class="nav-name">Device</a></li>
<li class=""><a href="model.Role.html" class="nav-name">Role</a></li>
<li class=""><a href="model.User.html" class="nav-name">User</a></li>
</ul>
</li>
<li class="">
<a href="partialupdate.html" class="nav-name">partialupdate</a>
<ul class="nav">
<li class=""><a href="partialupdate.EntityPartialUpdateBuilder.html" class="nav-name">EntityPartialUpdateBuilder</a></li>
<li class=""><a href="partialupdate.PartialUpdateBuilder.html" class="nav-name">PartialUpdateBuilder</a></li>
<li class=""><a href="partialupdate.UpdateOperation.html" class="nav-name">UpdateOperation</a></li>
</ul>
</li>
<li class="">
<a href="query.html" class="nav-name">query</a>
<ul class="nav">
<li class=""><a href="query.Builder.html" class="nav-name">Builder</a></li>
<li class=""><a href="query.Filter.html" class="nav-name">Filter</a></li>
<li class=""><a href="query.Node.html" class="nav-name">Node</a></li>
<li class=""><a href="query.Operator.html" class="nav-name">Operator</a></li>
<li class=""><a href="query.Query.html" class="nav-name">Query</a></li>
<li class=""><a href="query.Stream.html" class="nav-name">Stream</a></li>
<li class=""><a href="query.Condition.html" class="nav-name">Condition</a></li>
</ul>
</li>
<li class="">
<a href="util.html" class="nav-name">util</a>
<ul class="nav">
<li class=""><a href="util.Code.html" class="nav-name">Code</a></li>
<li class=""><a href="util.Lockable.html" class="nav-name">Lockable</a></li>
<li class=""><a href="util.Logger.html" class="nav-name">Logger</a></li>
<li class=""><a href="util.Metadata.html" class="nav-name">Metadata</a></li>
<li class=""><a href="util.Modules.html" class="nav-name">Modules</a></li>
<li class=""><a href="util.Permission.html" class="nav-name">Permission</a></li>
<li class=""><a href="util.PushMessage.html" class="nav-name">PushMessage</a></li>
<li class=""><a href="util.TokenStorage.html" class="nav-name">TokenStorage</a></li>
<li class=""><a href="util.ValidationResult.html" class="nav-name">ValidationResult</a></li>
<li class=""><a href="util.Validator.html" class="nav-name">Validator</a></li>
<li class=""><a href="util.TokenStorageFactory.html" class="nav-name">TokenStorageFactory</a></li>
</ul>
</li>
</ul>
</div>
<div class="col-md-12" id="main">
<div class="content">
<h1 class="page-title">Source: lib/binding/UserFactory.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>'use strict';
const EntityFactory = require('./EntityFactory');
/**
* @class binding.UserFactory
* @extends binding.EntityFactory<model.User>
*
* Creates a new instance of the managed type of this factory
* @param {Object=} properties initial properties to set on the instance
* @param {...*} arguments Additional constructor params passed through the type constructor
* @return {model.User} The new managed instance
*/
const UserFactory = EntityFactory.extend(/** @lends binding.UserFactory.prototype */ {
/**
* The current logged in user, or <code>null</code> if the user is not logged in
* @type model.User
* @readonly
*/
get me() {
return this.db.me;
},
/**
* Register a new user with the given username and password, if the username is not used by an another user.
* @param {string|model.User} user The username as a string or a <User> Object, which must contain the username.
* @param {string} password The password for the given user
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default logs the user in after a successful
* registration and keeps the user logged in over multiple sessions
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>} The created user object, for the new registered user.
*/
register(user, password, loginOption, doneCallback, failCallback) {
if (loginOption instanceof Function) {
return this.register(user, password, true, loginOption, doneCallback);
}
const userObj = typeof user === 'string' ? this.fromJSON({ username: user }) : user;
return this.db.register(userObj, password, loginOption === undefined ? true : loginOption)
.then(doneCallback, failCallback);
},
/**
* Log in the user with the given username and password and starts a user session
* @param {string} username The username of the user
* @param {string} password The password of the user
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default keeps the user logged in over
* multiple sessions
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*/
login(username, password, loginOption, doneCallback, failCallback) {
if (loginOption instanceof Function) {
return this.login(username, password, true, loginOption, doneCallback);
}
return this.db.login(username, password, loginOption === undefined ? true : loginOption)
.then(doneCallback, failCallback);
},
/**
* Log in the user assiciated with the given token and starts a user session.
* @param {string} token The user token.
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default keeps the user logged in over
* multiple sessions
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*/
loginWithToken(token, loginOption, doneCallback, failCallback) {
if (loginOption instanceof Function) {
return this.loginWithToken(token, true, loginOption, doneCallback);
}
this.db.token = token;
return this.db.renew(loginOption).then(doneCallback, failCallback);
},
/**
* Log out the current logged in user and ends the active user session
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<*>}
*/
logout(doneCallback, failCallback) {
return this.db.logout().then(doneCallback, failCallback);
},
/**
* Change the password of the given user
*
* @param {string} username Username to identify the user
* @param {string} password Current password of the user
* @param {string} newPassword New password of the user
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*/
newPassword(username, password, newPassword, doneCallback, failCallback) {
// detect signature newPassword(token, newPassword, [loginOption=true][, doneCallback[, failCallback]])
if (typeof newPassword === 'string') {
return this.db.newPassword(username, password, newPassword).then(doneCallback, failCallback);
}
const arg = arguments;
const token = arg[0];
const newPassword2 = arg[1];
let loginOption2 = arg[2];
let doneCallback2 = arg[3];
let failCallback2 = arg[4];
if (loginOption2 instanceof Function) {
failCallback2 = doneCallback2;
doneCallback2 = loginOption2;
loginOption2 = true;
}
return this.db.newPasswordWithToken(token, newPassword2, loginOption2).then(doneCallback2, failCallback2);
},
/**
* Sends an email with a link to reset the password for the given username
*
* The username must be a valid email address.
*
* @param {string} username Username (email) to identify the user
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<*>}
*/
resetPassword(username, doneCallback, failCallback) {
return this.db.resetPassword(username).then(doneCallback, failCallback);
},
/**
* 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.
*
* @param {string} username Current username (email) to identify the user
* @param {string} newUsername New username (email) to change the current username to
* @param {string} password The current password of the user. Has to be passed to the function for security reason
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<*>}
*/
changeUsername(username, newUsername, password, doneCallback, failCallback) {
return this.db.changeUsername(username, newUsername, password, doneCallback, failCallback);
},
/**
* Requests a perpetual token for the given user
*
* Only users with the admin role are allowed to request an API token.
*
* @param {binding.User|String} user The user object or id of the user object
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<*>}
*/
requestAPIToken(user, doneCallback, failCallback) {
return this.db.requestAPIToken(this.managedType.typeConstructor, user).then(doneCallback, failCallback);
},
/**
* Revoke all created tokens for the given user
*
* This method will revoke all previously issued tokens and the user must login again.
*
* @param {binding.User|String} user The user object or id of the user object
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<*>}
*/
revokeAllTokens(user, doneCallback, failCallback) {
return this.db.revokeAllTokens(this.managedType.typeConstructor, user).then(doneCallback, failCallback);
},
});
/**
* Change the password of a user, which will be identified by the given token from the reset password e-mail
*
* @see resetPassword
* @param {string} token Token from the reset password e-mail
* @param {string} newPassword New password of the user
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true]
* The default keeps the user logged in over multiple sessions
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*
* @function
* @name newPassword
* @memberOf binding.UserFactory.prototype
*/
/**
* 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: <code>https://example.net/db/User/OAuth/google</code> and copy the
* client id and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is
* logged in.
*
* @param {string} clientID
* @param {Object=} options
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default keeps the user logged in over
* multiple sessions
* @param {string} [options.title="Login"] sets the title of the popup window
* @param {number} [options.width=585] defines the width of the popup window
* @param {number} [options.height=545] defines the height of the popup window
* @param {string} [options.scope="email"] the range of rights requested from the user
* @param {Object} [options.state={}]
* @param {number} [options.timeout=5 * 60 * 1000]
* @param {string} [options.redirect=""] 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.
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*
* @function
* @name loginWithGoogle
* @memberOf binding.UserFactory.prototype
*/
/**
* 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.
*
* @param {string} clientID
* @param {Object=} options
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default keeps the user logged in over
* multiple sessions
* @param {string} [options.title="Login"] sets the title of the popup window
* @param {number} [options.width=1140] defines the width of the popup window
* @param {number} [options.height=640] defines the height of the popup window
* @param {string} [options.scope="email"] the range of rights requested from the user
* @param {Object} [options.state={}]
* @param {number} [options.timeout=5 * 60 * 1000]
* @param {string} [options.redirect=""] 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.
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*
* @function
* @name loginWithFacebook
* @memberOf binding.UserFactory.prototype
*/
/**
* 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.
*
* @param {string} clientID
* @param {Object=} options
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default keeps the user logged in over*
* multiple sessions
* @param {string} [options.title="Login"] sets the title of the popup window
* @param {number} [options.width=1040] defines the width of the popup window
* @param {number} [options.height=580] defines the height of the popup window
* @param {string} [options.scope="user:email"] the range of rights requested from the user
* @param {Object} [options.state={}]
* @param {number} [options.timeout=5 * 60 * 1000]
* @param {string} [options.redirect=""] 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.
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*
* @function
* @name loginWithGitHub
* @memberOf binding.UserFactory.prototype
*/
/**
* 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.
*
* @param {string} clientID
* @param {Object=} options
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default keeps the user logged in over
* multiple sessions
* @param {string} [options.title="Login"] sets the title of the popup window
* @param {number} [options.width=740] defines the width of the popup window
* @param {number} [options.height=730] defines the height of the popup window
* @param {number} [options.timeout=5 * 60 * 1000]
* @param {string} [options.redirect=""] 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.
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*
* @function
* @name loginWithTwitter
* @memberOf binding.UserFactory.prototype
*/
/**
* 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.
*
* @param {string} clientID
* @param {Object=} options
* @param {boolean|binding.UserFactory.LoginOption} [loginOption=true] The default keeps the user logged in over
* multiple sessions
* @param {string} [options.title="Login"] sets the title of the popup window
* @param {number} [options.width=630] defines the width of the popup window
* @param {number} [options.height=530] defines the height of the popup window
* @param {string} [options.scope=""] the range of rights requested from the user
* @param {Object} [options.state={}]
* @param {number} [options.timeout=5 * 60 * 1000]
* @param {string} [options.redirect=""] 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.
* @param {binding.Entity~doneCallback=} doneCallback Called when the operation succeed.
* @param {binding.Entity~failCallback=} failCallback Called when the operation failed.
* @return {Promise<model.User>}
*
* @function
* @name loginWithLinkedIn
* @memberOf binding.UserFactory.prototype
*/
/**
* Creates a new user object
*
* @function
* @name new
* @param {Object<string, *>} properties Additional properties which will be applied to the created instance
* @return {model.User} A new created user
* @memberOf binding.UserFactory.prototype
*/
/**
* @alias binding.UserFactory.LoginOption
* @enum {number}
*/
UserFactory.LoginOption = {
/**
* Do not login the user after a successful registration
*/
NO_LOGIN: -1,
/**
* Login in after a successful registration and keep the token in a nonpermanent storage, i.e SessionStorage
*/
SESSION_LOGIN: 0,
/**
* Login in after a successful registration and keep the token in a persistent storage, i.e LocalStorage
*/
PERSIST_LOGIN: 1,
};
/**
* @alias binding.UserFactory.DefaultOptions
* @property {Object} oauth default properties
* @property {Object} oauth.google default oauth properties for Google
* @property {Object} oauth.facebook default oauth properties for Facebook
* @property {Object} oauth.github default oauth properties for GitHub
* @property {Object} oauth.twitter default oauth properties for Twitter
* @property {Object} oauth.linkedin default oauth properties for LinkedIn
*/
UserFactory.DefaultOptions = {
google: {
width: 585,
height: 545,
scope: 'email',
},
facebook: {
width: 1140,
height: 640,
scope: 'email',
},
github: {
width: 1040,
height: 580,
scope: 'user:email',
},
twitter: {
width: 740,
height: 730,
},
linkedin: {
width: 630,
height: 530,
scope: '',
},
};
['Google', 'Facebook', 'GitHub', 'Twitter', 'LinkedIn'].forEach((name) => {
const methodName = 'loginWith' + name;
// do not use a lambda here since we will loose the this context
UserFactory[methodName] = function (clientID, options, doneCallback, failCallback) {
if (options instanceof Function) {
return this[methodName](clientID, {}, options, doneCallback);
}
const opt = Object.assign({}, UserFactory.DefaultOptions[name.toLowerCase()], options || {});
return this.db.loginWithOAuth(name, clientID, opt).then(doneCallback, failCallback);
};
});
module.exports = UserFactory;
</code></pre>
</article>
</section>
<!-- <footer>
<strong>Baqend JavaScript SDK 2.14.1</strong><br>
© 2019 Baqend GmbH<br>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun, 06 Jan 2019 05:00:21 GMT
</footer> -->
</div>
</div>
</div>
</div>
</div>
<div id="footer" style="position:relative; z-index:1;">
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-3 sitemap">
<h4>Product</h4>
<a href="https://www.baqend.com/platform.html">Platform</a>
<a href="https://www.baqend.com/speedkit.html">Speed Kit</a>
<a href="https://www.baqend.com/features.html">Features</a>
<a href="https://www.baqend.com/pricing.html">Platform Pricing</a>
<a href="https://www.baqend.com/pricing_speedkit.html">Speed Kit Pricing</a>
<a href="https://www.baqend.com/agencies.html">Agencies</a>
<a href="https://www.baqend.com/enterprise.html">Enterprise</a>
<a href="https://www.baqend.com/features.html#download">Community Edition</a>
<a href="https://www.baqend.com/support.html">Support</a>
</div>
<div class="col-xs-6 col-sm-3 sitemap">
<h4>Company</h4>
<a href="https://www.baqend.com/about.html">About us</a>
<a href="https://medium.baqend.com">Baqend Blog</a>
<a href="https://www.baqend.com/hiring.html">Jobs</a>
<a href="https://www.baqend.com/press.html">Press</a>
<a href="https://thesis.app.baqend.com/">Bachelor/Master theses</a>
<a href="https://www.weblabs.hamburg/">WebLabs.Hamburg</a>
</div>
<div class="col-xs-6 col-sm-3 sitemap">
<h4>Developer</h4>
<a href="https://dashboard.baqend.com/login">Login</a>
<a href="https://dashboard.baqend.com/register">Sign Up</a>
<a href="https://www.baqend.com/guide">Developer Docs</a>
<a href="https://www.baqend.com/guide/roadmap/">Roadmap</a>
<a href="https://www.baqend.com/guide/starter-kits">Starter Kits</a>
<a href="https://www.baqend.com/js-sdk/latest/baqend.html">JS SDK</a>
<a href="https://stackoverflow.com/questions/tagged/baqend/">Stackoverflow</a>
</div>
<div class="col-xs-6 col-sm-3 contact">
<h4>Contact</h4>
<p class="contact-information">
<span>
Baqend GmbH<br />
Stresemannstr. 23<br />
22769 Hamburg<br />
Germany
</span>
</p>
<p class="contact-information">
Email: <a style="display: inline-block" href="mailto:support@baqend.com">support@baqend.com</a>
</p>
<p class="contact-information">
Tel: <a style="display: inline-block" href="tel:+494060940539">+49 40 60940539</a>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center social">
<a href="https://twitter.com/baqendcom"><i class="fa fa-twitter fa-fw"></i></a>
<a href="https://github.com/Baqend"><i class="fa fa-github fa-fw"></i></a>
<a href="https://medium.baqend.com/"><i class="fa fa-medium fa-fw"></i></a>
<a href="https://www.facebook.com/baqend"><i class="fa fa-facebook fa-fw"></i></a>
<a href="https://www.youtube.com/channel/UCsImg6Ts8UEp6-7LE9CP2-Q"><i class="fa fa-youtube fa-fw"></i></a>
</div>
</div>
</div>
<footer>
<div class="container">
<div class="legal text-center">
<div>
<strong>Baqend JavaScript SDK 2.14.1</strong><br>
© 2019 Baqend GmbH<br>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun, 06 Jan 2019 05:00:21 GMT
</div>
<a href="mailto:info@baqend.com">Contact</a> -
<a href="https://dashboard.baqend.com/privacy">Privacy Policy</a> -
<a href="https://dashboard.baqend.com/terms">Terms of Service</a> -
<a href="https://dashboard.baqend.com/imprint">Imprint</a>
</div>
</div>
</footer>
</div>
<script> prettyPrint(); </script>
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script src="scripts/bootstrap.min.js"> </script>
<script src="scripts/linenumber.js"> </script>
<script src="scripts/filter.js"> </script>
<script data-main="scripts/search.js" src="scripts/require.js"></script>
</body>
</html>