new Useris()
Useris is a Js library to be used in B! web applications and must be used together with the NewtonAdapter module. It features a simple way to manage and validate all the forms, inputs and buttons to manage the user actions. You can use Useris when you need to implement one of those features:
LoginForgotChange PasswordReset PasswordManage the smartstatus actionsAdd IdentityShow an error message
Remember that Useris doesn't manage a full login flow. It only manages the html content to add click action and validation features. The real login flow has to be passed as callback. You will find the object to pass to the newton adapter as response in the callback and in most of the cases you should use it without manipulation.
In all the methods you will see an options object with an element params. This element params is optional. If you have yet injected the tmpl inside the html, Useris will not call any template and will not populate any html but it will start to attach events and validation features to the forms.
Useris is based on a simple MVC model. In fact, the UserView module is the referent to the view. When you have to manage event or hide, show, get or add an element, you have to use the UserView module. The controller is not necessary because we don't have to mantain or manipulate any type of datas.
To use Useris you have (before calling any other function) to initialize it with the init method.
Methods
(static) changePassword(options, callbackObject) → {object}
Validate and recognize the object to make the user change its password.
It must be used with the newtonsmartchangepassword template.
- Source:
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
|||||||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Returns:
- Type:
-
object
{
oldPassword: string,
newPassword: string,
repeatedPassword: string
}
Example
Useris.changePassword({
element: document.getElementById('elementId'),
}, {
onSuccess: function(userCredentials){
console.log(userCredentials);
callsToNewtonAdapter.changePassword(userCredentials);
},
onCancel: function(){
window.history.back();
},
onError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
}
});
(static) forgot(options, callbackObject) → {object}
Validate and recognize how to send the link of reset password (msisdn or mail).
It must be used with the smartforgot template;
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
||||||||||||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Returns:
- Type:
-
object
Msisdn case:
{
msisdn: string
}
Email case:
{
email: string
}
Example
Useris.forgot({
element: document.getElementById('elementId'),
regexObject: {
msidn: '',
pin: '',
email: '',
password: '',
generic: '',
genericPassword: ''
}
}, {
onSuccess: function(userCredentials){
console.log(userCredentials);
callsToNewtonAdapter.forgot(userCredentials);
},
onError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
}
});
(static) init(options)
Initialization method of Useris. Please note thtat this method has to be called before any other methods and you should pass a configuration object.
- Source:
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
configuration object
|
Example
Useris.init({
domain: 'www.domain.com',
country: 'ww',
enableAliasCheck: 0,
aliasCheckUrl: 'http://www.aliascheckurl.api/',
disablePinInput: 0,
hybridnews: 0,
store_type: 'itunes',
apikey: api_key,
enableGoogleCheckbox: 0,
emailIdentityEnabled: 1,
identityFbEnabled: 1,
redirectToMipRegisterAtStart: 0,
logger: console,
regexObject: {
msisdn: '.',
pin: '.',
email: '.',
password: '.',
generic: '.',
genericPassword: '.'
}
});
(static) login(options, callbackObject) → {object}
Validate and recognize the login object to be sent to the newton adapter for the login.
It must be used with the smartlogin template.
It also manage the facebook login button. Please note that you have to append the facebook access token once you have logged in with facebook before passing useris response to newton. This why we have decided to leave Useris unaware of Facebook.
To allow the facebook integration remember that you have to create and configurate a facebook app for your web applications.
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
||||||||||||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Returns:
- Type:
-
object
Msisdn case:
{
msisdn: string,
pin: string,
type: 'msisdn',
logged: boolean
}
Email case:
{
email: string,
password: string,
type: 'email',
logged: boolean
}
Generic case:
{
username: string,
password: string,
type: 'generic',
logged: boolean
}
Example
Useris.login({
element: document.getElementById('elementId'),
regexObject: {
msidn: '',
pin: '',
email: '',
password: '',
generic: '',
genericPassword: ''
}
}, {
onSuccess: function(userCredentials){
console.log(userCredentials);
callsToNewtonAdapter.login(userCredentials);
},
onError: function(error){
console.log('Error:', error);
manageError(error);
},
onFacebookSuccess: function(userCredentials){
console.log(userCredentials);
FB.login(function(fbResponse){
if(fbResponse.status === 'connected'){
// override the access_token params
userCredentials.access_token = FB.getAccessToken();
callsToNewtonAdapter.login(userCredentials);
}
}
},
onFacebookError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
}
});
(static) profile(options, callbackObject) → {object}
Validate and expose function for profile editing
It must be used with the newtonsmartstatusprofile template. CallbackSuccess must be called inside onSaveNickname to update the form, passing the newNickname value provided by useris or your call.
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Returns:
- Type:
-
object
{
newNickname: string,
oldNickname: string,
callbackSuccess: function(newNickname),
}
Example
Useris.profile({
element: document.getElementById('elementId'),
access_token: 'abcdefgh1234567890'
}, {
onSaveNickname: function(userCredentials){
console.log(userCredentials);
updateUserProps(userCredentials);
},
onError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
}
});
(static) resetPassword(options, callbackObject) → {object}
Validate and recognize the object to reset a user password.
It must be used with the newtonsmartresetpsw template, it works only for email identity.
- Source:
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
|||||||||||||||||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Returns:
- Type:
-
object
{
password: string,
token: url_params.token,
email: url_params.mail
}
Example
Useris.resetPassword({
element: document.getElementById('elementId'),
regexObject: {
msidn: '',
pin: '',
email: '',
password: '',
generic: '',
genericPassword: ''
},
token: '123459325',
email: 'test@email.com'
}, {
onSuccess: function(userCredentials){
console.log(userCredentials);
callsToNewtonAdapter.resetPassword(userCredentials);
},
onError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
}
});
(static) signup(options, callbackObject) → {object}
Validate and recognize the object to add a new free newton identity.
Remember to check if an identy is already present. If yes you have to delete the old and add the new one
It must be used with the smartsignup template;
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
||||||||||||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Returns:
- Type:
-
object
Email case:
{
email: string,
password: string
}
Example
Useris.signup({
element: document.getElementById('elementId'),
regexObject: {
msidn: '',
pin: '',
email: '',
password: '',
generic: '',
genericPassword: ''
},
access_token: '',
doNotLoad: false,
otherParams: '{}'
}, {
onSuccess: function(userCredentials){
// remember to check if an identy is already present.
// If yes you have to delete the old and add the new one
callsToNewton.signup(userCredentials);
},
onFbSignupSuccess: function(userCredentials){
// fb code
callsToNewton.signup(userCredentials);
},
onError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
}
});
(static) smartstatus(options, callbackObject)
Manage the click on the unsubscription (to unsubscribe a user) and facebook (to add the facebook identity) buttons, calling the relative function.
It must be used with the smartstatus template;
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
||||||||||||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Example
Useris.smartstatus({
element: document.getElementById('elem'useris-username-error'entId'),
access_token: abcdefgh1234567890,
regexObject: {
msidn: '',
pin: '',
email: '',
password: '',
generic: '',
genericPassword: ''
}, {
onUnsubSuccess: function(){
console.log();
callToUnsubscribe();
},
onUnsubError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template laoded', tmplInfo);
}
});
(static) social(options, callbackOnject) → {object}
Validate and expose function for social account
It must be used with the newtonsmartstatussocial template;
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
||||||||||||||||||||||
callbackOnject |
object
|
Object containg all the callbacks |
||||||||||||||||||||||
callbackObject.onTemplateLoaded |
function
|
<optional> |
'no-default' |
Callback executed when the template has been loaded. |
||||||||||||||||||||
callbackObject.onFacebookRegisterSuccess |
function
|
<optional> |
'no-default' |
Callback executed when the template has been loaded. |
||||||||||||||||||||
callbackObject.onFacebookDisconnect |
function
|
<optional> |
'no-default' |
Callback executed when the template has been loaded. |
Returns:
- Type:
-
object
{}
Example
Useris.social({
element: document.getElementById('elementId'),
access_token: 'abcdefgh1234567890'
}, {
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
},
onFacebookRegisterSuccess: function(){
//facebook login code
facebookLogin();
},
onFacebookDisconnect: function(){
//facebook disconnect code
facebookDisconnect();
}
});
(static) triggerError(error)
Expose the useris error manager to the web application to show error or warning message.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
error |
string
|
div to show for the error |
Example
Useris.triggerError('useris-error-newton-error');
(static) userRegistration(options, callbackObject) → {object}
Validate and recognize the object to add a new newton identity.
Remember to check if an identy is already present. If yes you have to delete the old and add the new one
It must be used with the smartaddemail template;
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
Options object
|
||||||||||||||||||||||||||||||||||||||||
callbackObject |
Object
|
Manage the success and error callback
|
Returns:
- Type:
-
object
Email case:
{
email: string,
password: string,
skipped: boolean,
type: 'email',
smsTemplate: string,
params: Object
}
Skipped case:
{
skipped: boolean,
type: 'generic',
smsTemplate: string
}
Example
Useris.userRegistration({
element: document.getElementById('elementId'),
regexObject: {
msidn: '',
pin: '',
email: '',
password: '',
generic: '',
genericPassword: ''
},
skipRegister: 1,
smsTemplate: 'Hello, welcome to the service!',
otherParams: '{}'
}, {
onSuccess: function(userCredentials){
// remember to check if an identy is already present.
// If yes you have to delete the old and add the new one
callsToNewton.addIdentity(userCredentials);
},
onCancel: function(){
window.location.href = '#!';
}
onError: function(error){
console.log('Error:', error);
manageError(error);
},
onTemplateLoaded: function(tmplInfo){
console.log('Template loaded', tmplInfo);
}
});