-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.js
44 lines (41 loc) · 1.5 KB
/
login.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var modal = document.getElementById('myModal');
var modaltext = document.getElementById('modaltext');
var span = document.getElementsByClassName("close")[0];
document.getElementById("login").onclick = function login(){
var request = new XMLHttpRequest();
const phone = document.getElementById("loginphone").value
const password = document.getElementById("loginpassword").value
const message = 'http://localhost:7000/act?role=home&cmd=connexion&phone='+phone+'&password='+password
console.log(message)
if ("withCredentials" in request) {
request.open('GET', message, true);
} else if (typeof XDomainRequest != "undefined") {
request = new XDomainRequest();
request.open('GET', message);
}
request.onload = function (response) {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
console.log(data)
if (data.code==="ETIMEDOUT"){
modal.style.display = "block";
modaltext.textContent = "Inexistant user"
}else if (data.state===false){
modal.style.display = "block";
modaltext.textContent = data.justification
}else if (data.state){
window.location.href = 'choices.html';
}
}
request.send();
};
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}