Version 1.1.0 - Revert to app
All checks were successful
Neutral/pipeline/head This commit looks good
All checks were successful
Neutral/pipeline/head This commit looks good
This commit is contained in:
67
public/javascripts/loginscript.js
Normal file
67
public/javascripts/loginscript.js
Normal file
@ -0,0 +1,67 @@
|
||||
const username = getID("username")
|
||||
const password = getID("password")
|
||||
const submit = getID("submit")
|
||||
|
||||
const loginInfo = new TextResponse("login-info")
|
||||
|
||||
loginInfo.clear()
|
||||
|
||||
submit.addEventListener("click", () => {
|
||||
|
||||
if(!username.value) {
|
||||
|
||||
loginInfo.err("Un nom d'utilisateur est nécéssaire pour se connecter !")
|
||||
|
||||
} else if(!password.value) {
|
||||
|
||||
loginInfo.err("Un mot de passe est nécéssaire pour se connecter !")
|
||||
} else {
|
||||
|
||||
|
||||
login()
|
||||
}
|
||||
})
|
||||
|
||||
password.addEventListener("keyup", (event) => {
|
||||
if (event.key === "Enter") {
|
||||
login()
|
||||
}
|
||||
});
|
||||
|
||||
function login() {
|
||||
|
||||
loginInfo.clear()
|
||||
|
||||
fetch('/login', {
|
||||
method: 'POST',
|
||||
redirect: 'follow',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: username.value,
|
||||
password: password.value
|
||||
})
|
||||
})
|
||||
.then(response => redirect(response))
|
||||
|
||||
async function redirect(response) {
|
||||
|
||||
response = await response.text()
|
||||
|
||||
if(response == "AUTH_FAILED") {
|
||||
|
||||
|
||||
loginInfo.err("Le nom d'utilisateur et le mot de passe sont incorrects.")
|
||||
|
||||
} else if(response == "AUTH_SUCCESS") {
|
||||
|
||||
window.location.href = "/"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user