-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscript.js
53 lines (49 loc) · 1.73 KB
/
script.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
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.14.1/firebase-app.js";
import {
getDatabase,
ref,
set,
get,
} from "https://www.gstatic.com/firebasejs/10.14.1/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAodkFYZe0HeRqUJq9CYatff5Ixe9MfJas",
authDomain: "scaler-canteen-d362b.firebaseapp.com",
projectId: "scaler-canteen-d362b",
storageBucket: "scaler-canteen-d362b.appspot.com",
messagingSenderId: "786619487227",
appId: "1:786619487227:web:41b0bb07145e889eda715e",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
const databaseRef = ref(database, "users");
document.getElementById("login-button").addEventListener("click", (e) => {
e.preventDefault();
const phoneNum = document.getElementById("PhoneNum").value;
const password = document.getElementById("Password").value;
if (phoneNum == "" || password == "") {
alert("Please Enter Phone Number and Password");
} else {
get(ref(database, "users/" + phoneNum))
.then((snapshot) => {
if (snapshot.exists()) {
if (snapshot.val().Password == password) {
alert("Login Successful");
window.location.href = "customer/menu.html";
} else {
alert("Incorrect Password");
}
} else {
alert("User Does Not Exist\n"+"Please SignUp");
}
})
.catch((error) => {
console.error(error);
});
}
// document.getElementById('login-form').reset();
});