-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathback-script.js
More file actions
114 lines (111 loc) · 3.49 KB
/
back-script.js
File metadata and controls
114 lines (111 loc) · 3.49 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.3/firebase-app.js";
import {
getDatabase,
ref,
get,
set,
child,
update,
push,
remove,
} from "https://www.gstatic.com/firebasejs/9.6.3/firebase-database.js";
const firebaseConfig = {
apiKey: "AIzaSyAXpdLMnPpeXo-LgpW-94orWVhrS4EGN-0",
authDomain: "slash-key.firebaseapp.com",
databaseURL: "https://slash-key-default-rtdb.firebaseio.com",
projectId: "slash-key",
storageBucket: "slash-key.appspot.com",
messagingSenderId: "593448539333",
appId: "1:593448539333:web:fd68e4d6c17f208bcc0cac",
measurementId: "G-2QZGFD4552",
};
function stringify(name){
return name;
}
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase();
const newCache = await caches.open('new-cache');
function register() {
const formData = document.forms["Regform"];
var NAME = formData["Email"].value;
var PASS = formData["Password"].value;
// var JSONData = `[{ sds: {email: ${NAME},pass: ${PASS}}}]`;
// JSONData=JSONData.replace('sds',`${NAME}`);
update(ref(db, `/${NAME}`), {
Name:NAME,
Pass:PASS,
Money:1000,
Email: "not provided",
Phone: "not provided",
Dob: "not provided",
Lvl:"0"
}
).then(() => {
get(child(ref(db), `${NAME}/`)).then((data) => {
console.log(data.val());
// newCache.put('/user.json', new Response(`${data.val()}`))
// console.log("hi");
// const reQuest = '/user.json';
// const response = newCache.match(reQuest);
// console.log(response);
window.location.replace('./Profile.html');
});
});
}
if(document.getElementById("submit")){
document.getElementById("submit").addEventListener("click", () => {
register();
});
}
function profile(){
console.log("hi");
get(child(ref(db), `admin/`)).then((data) => {
console.log(data.val(),"hello");
document.getElementById('urName').innerText= `Name : ${data.val().Name}`;
document.getElementById('urEmail').innerText= `Email : ${data.val().Email}`;
document.getElementById('urDob').innerText= `DOB : ${data.val().Dob}`;
document.getElementById('urLvl').innerText= `Level : ${data.val().Lvl}`;
document.getElementById('urBal').innerText= `Balance : ${data.val().Money}`;
});
}
function waiting(){
if(document.getElementById('urBal')){
profile()
}
else{
setTimeout(()=>{waiting();},1000);
}
}
function dataADD(){
const formData = document.forms["DetailForm"];
var uname = formData.uname.value;
var Nama = formData.Name.value;
var email= formData.email.value;
var phone= formData.phone.value;
var dob = formData.date.value;
update(ref(db, `/admin`), {
Name: Nama,
Email: email,
Phone: phone,
Dob: dob
}
).then(() => {
document.getElementById('msg').innerText="Data updated succesfully";
get(child(ref(db), `admin/`)).then((data) => {
console.log(data.val());
document.getElementById('urName').innerText= `Name : ${data.val().Name}`;
document.getElementById('urEmail').innerText= `Email : ${data.val().Email}`;
document.getElementById('urDob').innerText= `DOB : ${data.val().Dob}`;
document.getElementById('urLvl').innerText= `Level : ${data.val().Lvl}`;
document.getElementById('urBal').innerText= `Balance : ${data.val().Money}`;
});
setTimeout(()=>{document.getElementById('msg').innerText="";},2000)
});
}
if(document.getElementById("profile_update")){
document.getElementById("profile_update").addEventListener("click", () => {
dataADD();
});
}
waiting();