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.

57 lines
1.3 KiB

5 years ago
/*
* Signin
*/
function login() {
let apiKey = $('#apikey').val()
5 years ago
let dataJson = {
'apikey': apiKey
}
5 years ago
// Checks input fields
if (!apiKey) {
lib_msg.displayErrors('Admin key is mandatory')
return
5 years ago
}
lib_msg.displayMessage('Processing...')
let deferred = lib_api.signin(dataJson)
5 years ago
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')
}
5 years ago
},
function (jqxhr) {
lib_errors.processError(jqxhr)
5 years ago
}
)
5 years ago
}
/*
* onPageLoaded
*/
$(document).ready(function() {
// Dynamic loading of html and scripts
lib_cmn.includeHTML()
5 years ago
// Sets the event handlers
$('#apikey').keyup(function(evt) {
if (evt.keyCode === 13) {
login()
5 years ago
}
});
$('#signin').click(function() {
login()
})
})