-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_staff.js
executable file
·73 lines (69 loc) · 2.15 KB
/
login_staff.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
var usernamec, workc = "staff",
passwordc, rollnov = document.getElementById("name").value;
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
function check() {
usernamec = document.getElementById("name").value;
passwordc = document.getElementById("pas").value;
fetch('http://localhost:8080/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
rollno: usernamec,
password: passwordc
})
})
.then(result => {
return result.json();
})
.then(user => {
console.log(user);
if (!user) {
alert("unsuccessfull login credentials")
}
//storing token in localstorage.
localStorage.setItem('token', user.token);
localStorage.setItem('id', user.userId);
window.open("staff/homepagestaff.html", "_self");
})
.catch(err => {
console.log(err);
});
// var database = firebase.database();
// var ref = database.ref('student/' + rollnov);
// ref.on("value", gotdata, errordata);
}
var k;
function gotdata(data) {
//console.log(data.val());
var dat = data.val();
var keys = Object.keys(dat);
for (var i = 0; i < keys.length; i++) {
if (keys[i] == usernamec) {
k = keys[i];
//console.log(k);
if (dat[k].pasword == passwordc && dat[k].Work == workc) {
console.log("kk");
window.location.href = "staff/homepagestaff.html";
}
}
}
}
function errordata(err) {
console.log("error");
}