The ApiSession is part of the ApiService.
beforeLogoutHook
Allows to set up a hook to be executed before logout.
Usage: beforeLogoutHook(hook: function)
Parameters:
hook {function}
- a function returning a promise
Returns: A promise with the method execution result.
check
It checks the user session by executing the com.censhare.api.session.CheckSession
command.
Usage: check(session: string)
Parameters:
session {string}
- current session ID
Returns: A promise resolved with the session data { session: string; ['user-id']: number; ['user-asset-id']: number; ['user-admin-mode']: boolean; }
.
checkLoggedIn
Asserts that the user is currently logged in.
Usage: checkLoggedIn()
Parameters: none
Returns: A promise with the method execution result.
close
Closes the session.
Usage: close()
Parameters: none
Returns: A promise with the method execution result.
createLoginToken
Executes the com.censhare.api.session.CreateLoginToken
command.
Usage: createLoginToken()
Parameters: none
Returns: A promise with the method execution result.
getLocale
Gets the current user locale.
Usage: getLocale()
Parameters: none
Returns: A language code from the censhare master data.
getLoginId
Gets the current user login ID.
Usage: getLoginId()
Parameters: none
Returns: An integer value.
getStartPage
Gets the start page ID.
Usage: getStartPage()
Parameters: none
Returns: An integer value.
getState
Gets the current session state.
Usage: getState()
Parameters: none
Returns: One of the following values: initial, loggedIn, loggingOut, open, closed.
getTimezone
Gets the current user timezone.
Usage: getTimeZone()
Parameters: none
Returns: The timezone value of the Person asset associated to the currently logged-in user.
getUserAdminMode
Event stream of the user switching to admin mode.
Usage: getUserAdminMode()
Parameters: none
Returns: RxJs Observable: true
when user switches to admin mode, otherwise false
.
getUserAssetId
Gets the user asset ID.
Usage: getUserAssetId()
Parameters: none
Returns: ID of the Person asset associated to the currently logged-in user.
getUserId
Gets the current user ID.
Usage: getUserId()
Parameters: none
Returns: An integer value.
isLoggedIn
Checks if the user is currently logged in.
Usage: isLoggedIn()
Parameters: none
Returns: A boolean value.
login
It attempts to login by executing the com.censhare.api.session.Login
command.
Usage: login(login: string, password: string, locale: string, timezone: string)
Parameters:
login {string}
- loginpassword {string}
- passwordlocale {string}
- localetimezone {string}
- timezone
Returns: A promise with the method execution result.
logout
Executes all logout hooks and fires the com.censhare.api.session.Logout
command.
Usage: logout()
Parameters: none
Returns: A promise with the method execution result.
open
Connects to the server and attempts to restore the session.
Usage: open()
Parameters: none
Returns: A promise with the method execution result.
resolveUrl
Returns a qualified HTTP URL for either a censhare URL (censhare://...
) or a path relative to the base of the application (/img/no-image.jpeg
).
Usage: resolveUrl(url: string)
Parameters:
url {string}
- the censhare URL or relative path to be resolved
Returns: A string with the resolved URL.
setUserAdminMode
Turns on or off the admin mode for the current user.
Usage: setUserAdminMode(adminMode: boolean)
Parameters:
adminMode {boolean}
- true or false
Returns: A boolean value.