You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
56 lines
1.3 KiB
/*
|
|
* Signin
|
|
*/
|
|
function login() {
|
|
let apiKey = $('#apikey').val()
|
|
let dataJson = {
|
|
'apikey': apiKey
|
|
}
|
|
|
|
// Checks input fields
|
|
if (!apiKey) {
|
|
lib_msg.displayErrors('Admin key is mandatory')
|
|
return
|
|
}
|
|
|
|
lib_msg.displayMessage('Processing...')
|
|
|
|
let deferred = lib_api.signin(dataJson)
|
|
deferred.then(
|
|
function (result) {
|
|
const auth = result['authorizations']
|
|
const accessToken = auth['access_token']
|
|
if (lib_auth.isAdmin(accessToken)) {
|
|
lib_auth.setAccessToken(accessToken)
|
|
const refreshToken = auth['refresh_token']
|
|
lib_auth.setRefreshToken(refreshToken)
|
|
sessionStorage.setItem('activeTab', '')
|
|
lib_msg.displayInfo('Successfully connected to your backend')
|
|
// Redirection to default page
|
|
lib_cmn.goToDefaultPage()
|
|
} else {
|
|
lib_msg.displayErrors('You must sign in with the admin key')
|
|
}
|
|
},
|
|
function (jqxhr) {
|
|
lib_errors.processError(jqxhr)
|
|
}
|
|
)
|
|
}
|
|
|
|
/*
|
|
* onPageLoaded
|
|
*/
|
|
$(document).ready(function() {
|
|
// Dynamic loading of html and scripts
|
|
lib_cmn.includeHTML()
|
|
// Sets the event handlers
|
|
$('#apikey').keyup(function(evt) {
|
|
if (evt.keyCode === 13) {
|
|
login()
|
|
}
|
|
});
|
|
$('#signin').click(function() {
|
|
login()
|
|
})
|
|
})
|
|
|