STAT.account
Initiating Account
haccount data-[args]
* data-logout: url to return after logging OUT (window.location)
* data-success: url to return after logging IN (window.location; if blank, page will refresh. Omit attribute to disable)
* data-account: "persist" will fire account.login(account.validate) on same page
Basic Account Init:
<div id="stat-account" class="haccount" data-success="/stat/2.0/docs/dashboard.html" data-logout="/stat/2.0/"></div>
stat.account.login(successCallback, failureCallback, cancelable)
Params
* successCallback: (function) callback to initiate upon logging in successfully
* failureCallback: (function) callback to initiate upon login failure
* cancelable: (bool) add close button to login modal [default: true; data-account="persist" mode: false]
Run login process
stat.account.login();
Run login process and fire custom callback when successful
stat.account.login(myFunc)
stat.account.ready(callback)
Fire callback when user has been validated.
If the user is not validated, it will wait until the user is validated before returning the callback
stat.account.ready(myFunc)
stat.account.ready(function(){
// Fire my ajax
});
STAT.account.check()
Check that the accountjs library is loaded : returns bool
stat.account.check('lib')
Check that the account header module exists : returns bool
stat.account.check('header')
Check to see if user data exists (only happens if user is valid) : returns bool
stat.account.check('valid')
Check to see if the user has a token in localStorage : returns bool
stat.account.check('token')
Check to see if the client is https : returns bool
stat.account.check('https')
stat.account.user.data
Stored object that contains user data if user is validated.
console.log(stat.account.user.data);
Example of checking against roles:
stat.account.user.data.roles.includes('myRole')
// Returns true if 'myRole' exists
account.storage.userdata.get();
returns available userdata and roles from current users sessionStorage
account.storage.userdata.get();