-
Notifications
You must be signed in to change notification settings - Fork 0
/
activeUser.js
92 lines (82 loc) · 2.59 KB
/
activeUser.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
let activeUser = localStorage.getItem("activeUser") || null;
let userDatabase = JSON.parse(localStorage.getItem("userDatabase")) || [];
let leaderBoardDatabase = JSON.parse(localStorage.getItem("leaderBoard")) || [];
console.log(activeUser);
// activeUser = "Archie"
let account = document.getElementById("account") || null;
let signbutton = document.getElementById("signbutton") || null;
let leaderBoard = document.getElementById("leaderBoard") || null;
if (activeUser != null) {
account.innerText = activeUser.username;
signbutton.style.display = "none";
leaderBoard.style.display = "block";
}
let recordFormat = {
id: "",
wordcount: 0,
accuracy: 0,
time: "",
};
let accountForm = {
mobile: "",
username: "",
password: "",
};
// sign in
let signinForm = document.getElementById("signinform");
signinForm.addEventListener("submit", function (e) {
signinAccount(e);
});
function signinAccount(e) {
e.preventDefault();
let username = document.getElementById("mobileSignIn");
let password = document.getElementById("passwordSignIn");
let signinState = false;
userDatabase.forEach(function (elem) {
if (username.value == elem.mobile && password.value == elem.password) {
localStorage.setItem("activeUser", elem);
alert("Account logged in");
window.location.reload();
}
});
console.log(e);
}
// sign up
let signupForm = document.getElementById("signupform");
signinForm.addEventListener("submit", function (e) {
createAccount(e);
});
function createAccount(e) {
console.log(e)
e.preventDefault();
let mobile = document.getElementById("mobile");
let username = document.getElementById("username");
let password = document.getElementById("password");
accountForm.mobile = mobile.value;
accountForm.username = username.value;
accountForm.password = password.value;
let signinState = false;
userDatabase.forEach(function (elem) {
if (mobile.value == elem.mobile) {
signinState = true;
}
});
userDatabase.append(accountForm);
alert("Account created");
if (!signinState) {
localStorage.setItem("userDatabase", JSON.stringify(userDatabase));
}
}
function DataPushToLocalServer(userid, Data) {}
function buttonSignUpF() {
let buttonSignIn = document.getElementById("signinDiv");
let buttonSignUp = document.getElementById("signupDiv");
buttonSignUp.style.display = "block";
buttonSignIn.style.display = "none";
}
function buttonSignInF() {
let buttonSignIn = document.getElementById("signinDiv");
let buttonSignUp = document.getElementById("signupDiv");
buttonSignUp.style.display = "none";
buttonSignIn.style.display = "block";
}