login & anim ok

This commit is contained in:
STEINNI
2025-09-11 20:40:32 +00:00
parent e315a3061e
commit 190d8df334
7 changed files with 114 additions and 239 deletions
+69 -67
View File
@@ -90,81 +90,46 @@ class myUser extends app.LoadedClasses.User {
* @param {*} callBack
*/
async checkAuthenticated(callBack){
const startbtn = document.querySelector('#startbtn')
const gobtn = document.querySelector('#login-dialog button')
document.getElementById('startbtn').addEventListener('click', async () => {
document.getElementById('startbtn').disabled = true
gobtn.addEventListener('click', async () => {
gobtn.disabled = true
if(await this.login()) {
document.querySelector('div.loginerr').classList.remove('show')
console.log('Successful login !!!')
callBack()
} else {
gobtn.disabled = false
}
})
startbtn.addEventListener('click', async () => {
startbtn.disabled = true
this.isAuthenticated = false
const response = await fetch(app.config.userLib.checkauthEndpoint+'?'+crypto.randomUUID())
let payload = null
if(response.ok) { payload = await response.json() }
if(!payload) {
let jsonresp = null
if(response.ok) { jsonresp = await response.json() }
if(!jsonresp ||(!jsonresp.payload)) {
console.error('No valid response from checkauth !?')
document.getElementById('startbtn').disabled = false
} else if(!payload.authenticated){
console.log('==>login',app)
startbtn.disabled = false
} else if(!jsonresp.payload.authenticated){
document.querySelector('div.loginerr').classList.remove('show')
document.getElementById('login-dialog').classList.add('show')
if(jsonresp.payload.locked){
document.querySelector('div.loginerr').classList.add('show')
document.querySelector('div.loginerr').innerHTML = `
The account has been locked !<br>
(Ask an admin to unlock it.)
`
}
} else {
console.log('authenticated!')
this.isAuthenticated = true
callBack()
}
})
// console.log('====> click')
// callBack()
// })
// this.identity = {
// uuid: 'nike',
// email: 'info@nicsys.eu'
// };
// this.roles = ['admin']
// this.isAuthenticated = true
//setTimeout(callBack, 20000);
/*
fetch(app.config.userLib.authEndpoint+'?'+crypto.randomUUID(),{
headers: headers,
method: 'GET',
credentials: 'include'
})
.then(response => response.json())
.then(async resp => {
if(resp.success){
this.authenticationDone = true
this.isAuthenticated = resp.payload.isAuthenticated;
if(resp.payload.isAuthenticated) {
if((!this.identity) || (!this.identity.uuid)) {
this.logoutUrl = resp.payload.logoutUri;
this.parseUserInfo(resp.payload.userInfo);
}
this.platformRestrictions = resp.payload.platformRestrictions || null
if((this.platformRestrictions) && (!this.isVIP())){
this.ShowCurtain()
this.stopKeepAlive()
return // not triggering callback avoids any further ctrl loading by the router
}
if(!app.config.api) await this.getApiServices()
if(app.config.userLib.keepAliveSeconds && (app.config.userLib.keepAliveSeconds>0)) this.startKeepAlive()
callBack();
} else {
console.warn('Authorizer said User was not authenticated !');
this.authUrl = resp.payload.authUrl;
this.logoutUrl = resp.payload.logoutUri;
callBack();
}
} else {
console.error('Server error calling authorizer checkAuthenticated (success not true)');
this.stopKeepAlive() // Just in case KAL is active, because we arrive here from KAL itself
document.location.href = '/eulogin-error.html';
}
})
.catch((err) => {
console.error('Server error calling authorizer checkAuthenticated (Network error)',err);
document.location.href = '/eulogin-error.html';
});
*/
})
}
/**
@@ -173,6 +138,43 @@ class myUser extends app.LoadedClasses.User {
*/
getMessageBusUserInfo() { return(this.identity.uuid) }
async login(){
const response = await fetch(app.config.userLib.loginEndpoint+'?'+crypto.randomUUID(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: document.querySelector('input[name="username"]').value,
passwd: document.querySelector('input[name="password"]').value,
})
})
let jsonresp = null
if(response.ok) { jsonresp = await response.json() }
if(jsonresp && jsonresp.success && jsonresp.payload){
if(jsonresp.payload.authenticated){
this.isAuthenticated = true
this.userInfos = jsonresp.payload.userInfos
return(true)
} else {
document.querySelector('div.loginerr').classList.add('show')
if(!jsonresp.payload.locked){
document.querySelector('div.loginerr').innerHTML = `
Bad username or password !<br>
(${jsonresp.payload.trials} trials left.)
`
} else {
document.querySelector('div.loginerr').innerHTML = `
The account has been locked !<br>
(Ask an admin to unlock it.)
`
}
}
}
this.isAuthenticated = false
this.userInfos = null
return(false)
}
/**
*