Useris

Useris

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:

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.

Source:

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

regexObject Object <optional>
{}

Optionals Contains all the regular expressions for input validation (msisdn, pin, email, password and generic regex are allowed)

acccess_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onSuccess function <optional>
'no-default'

Success callback (code managed by the app)

onCancel function <optional>
'no-default'

Cancel callback (code managed by the app)

onError function <optional>
'no-default'

Error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

regexObject Object <optional>
''

Optionals Contains all the regular expressions for input validation (msisdn, pin, email, password and generic regex are allowed)

acccess_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

smsTemplate String <optional>
''

Optionals if set, will take the sms template to recover pin

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onSuccess function <optional>
'no-default'

Success callback (code managed by the app)

onError function <optional>
'no-default'

Error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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

Name Type Attributes Default Description
regexObject Object <optional>

Contains all the regular expressions for input validation (msisdn, pin, email, password and generic regex are allowed)

logger Object <optional>

A different logger by console (optional)

domain string <optional>
''

webapp domain

country string <optional>
''

country of the webapp

enableAliasCheck boolean <optional>
0

to activate the alias features (INDIAN case)

aliasCheckUrl string <optional>
''

api url of the alias

disablePinInput boolean <optional>
0

enable/disable the input PIN for the login (PT case)

hybridnews boolean <optional>
0

used in hybrid environment

store_type string <optional>
''

used in hybrid environment

apikey string <optional>
''

api key of the webapp

enableGoogleCheckbox boolean <optional>
0

enable/disable the Google Checkbox during the login flow

identityFbEnabled boolean <optional>
0

enable/disable Facebook users

emailIdentityEnabled boolean <optional>
0

enable/disable the email identity

redirectRegisterToMipAtStart boolean <optional>
0

enable/disable the smstemplate on addidentity

operatorList boolean <optional>
0

enable/disable the operator login selection

addUsernameEnabled boolean <optional>
0

enable/disable the add username feature

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

regexObject Object <optional>
{}

Optional Contains all the regular expressions for input validation (msisdn, pin, email, password and generic regex are allowed)

acccess_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onSuccess function <optional>
'no-default'

Success callback (code managed by the app)

onError function <optional>
'no-default'

Error callback (code managed by the app)

onFacebookSuccess function <optional>
'no-default'

Facebook success callback (code managed by the app). You have to ovveride the access_token params before passing it to newton

onFacebookError function <optional>
'no-default'

Facebook error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

acccess_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicalls)

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onSaveNickname function <optional>
'no-default'

Success callback (code managed by the app)

onError function <optional>
'no-default'

Error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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) ptAddPassword(options, callbackObject) → {object}

Validate and expose function for account creation portugal

It must be used with the newtonsmartaddpswmsisdn template;

Source:
Parameters:
Name Type Description
options Object

Options object

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

access_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

contentId String <optional>
''

Optionals content_id of smartsection

returnUrl String <optional>
''

Optionals return url to call for php

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

callbackObject object

Object containg all the callbacks

Name Type Attributes Default Description
onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

onAddPassword function <optional>
'no-default'

Callback executed when the click on button.

Returns:
Type:
object
     {}
 
Example
Useris.ptAddPassword({
     element: document.getElementById('elementId'),
     access_token: 'abcdefgh1234567890',
     contentId: 0,
     returnUrl: 'http://www.google.com'
 }, {
     onTemplateLoaded: function(tmplInfo){
         console.log('Template loaded', tmplInfo);
     },
     onAddPassword: function(){
         //add password code
         addpsw();
     }
 });

 

(static) ptChangePassword(options, callbackObject) → {object}

Validate and expose function for account creation portugal

It must be used with the newtonsmartchangepswmsisdn template;

Source:
Parameters:
Name Type Description
options Object

Options object

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

access_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

contentId String <optional>
''

Optionals content_id of smartsection

returnUrl String <optional>
''

Optionals return url to call for php

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

callbackObject object

Object containg all the callbacks

Name Type Attributes Default Description
onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

onChangePassword function <optional>
'no-default'

Callback executed when the click on button.

Returns:
Type:
object
     {}
 
Example
Useris.ptChangePassword({
     element: document.getElementById('elementId'),
     access_token: 'abcdefgh1234567890',
     contentId: 0,
     returnUrl: 'http://www.google.com'
 }, {
     onTemplateLoaded: function(tmplInfo){
         console.log('Template loaded', tmplInfo);
     },
     onChangePassword: function(){
         //chhange password code
         changePassword();
     }
 });

 

(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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

regexObject Object <optional>
{}

Optionals Contains all the regular expressions for input validation (msisdn, pin, email, password and generic regex are allowed)

acccess_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

token string <optional>
''

Token present as url params inside the reset link

email string <optional>
''

Email present as url params inside the reset link

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onSuccess function <optional>
'no-default'

Success callback (code managed by the app)

onError function <optional>
'no-default'

Error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

regexObject Object <optional>
{}

Optionals Contains all the regular expressions for input validation (msisdn, pin, email, password and generic regex are allowed)

acccess_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

ohterParams boolean <optional>
0

params to substitute for mail

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onSuccess function <optional>
'no-default'

Success callback (code managed by the app)

onFbSignupSucces function <optional>
'no-default'

Facebook function to signup with fb identity (code managed by the app)

onError function <optional>
'no-default'

Error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

access_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onUnsubLoggedSuccess function <optional>
'no-default'

Unsubscriptions logged click callback (code managed by the app)

onUnsubLoggedError function <optional>
'no-default'

Unsubscriptions logged click error callback (code managed by the app)

onUnsubUnloggedSuccess function <optional>
'no-default'

Unsubscriptions unlogged click callback (code managed by the app)

onUnsubUnloggedError function <optional>
'no-default'

Unsubscriptions unlogged click error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

access_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

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

Name Type Attributes Default Description
element Object <optional>
false

The div element where the html's tmpl will be injected

regexObject Object <optional>
{}

Optionals Contains all the regular expressions for input validation (msisdn, pin, email, password and generic regex are allowed)

acccess_token String <optional>
''

Optionals if true, the tmpl calls will be called with the params access_token filled

doNotLoad Boolean <optional>
false

Optionals if true, this params will tell useris to not load the template (It doesn't make the apicall)

smsTemplate String <optional>
''

the template of the sms sent (msisdn add identity)

skipRegister boolean <optional>
0

allow a user to have a generic identity

ohterParams boolean <optional>
0

params to substitute for mail

callbackObject Object

Manage the success and error callback

Name Type Attributes Default Description
onSuccess function <optional>
'no-default'

Success callback (code managed by the app)

onError function <optional>
'no-default'

Error callback (code managed by the app)

onTemplateLoaded function <optional>
'no-default'

Callback executed when the template has been loaded.

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);
     }
 });