-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
163 lines (125 loc) · 4.41 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
let activeUser;
let users;
document.getElementById ('registration').style.display ='block';
document.getElementById ('login2').style.display ='none';
if (localStorage.getItem('users') == null) {
users = hardcodedUsers();
} else {
users = JSON.parse(localStorage.getItem("users"))
}
console.log(users)
var isLoggedIn = false;
console.log(isLoggedIn);
var isLoggedInStringified = JSON.stringify(isLoggedIn);
localStorage.setItem('isLoggedIn', isLoggedInStringified);
function register(){
document.getElementById ('registration').style.display ='block';
document.getElementById ('login2').style.display ='none';
}
function login(){
document.getElementById ('registration').style.display ='none';
document.getElementById ('login2').style.display ='block';
}
// This constant will be used to add users to the users array
const fnameUI = document.getElementById('first-name')
const lnameUI = document.getElementById('last-name')
const passwordUI = document.getElementById('password')
const password2UI = document.getElementById('password2')
const EMailUI = document.getElementById('e-mail')
const submitUI = document.getElementById('submit')
const loginUI = document.getElementById('login')
function Signup() {
var fname = fnameUI.value
var lname = lnameUI.value
var password = passwordUI.value
var password2 = password2UI.value
var EMail = EMailUI.value
if (fname.length === 0) {
alert("You need to fill out your First Name");
fnameUI.focus();
return false;
}
if (lname.length === 0) {
alert("You need to fill out your Last Name");
lnameUI.focus();
return false;
}
if(EMail.includes("cbs.edu") === false && EMail.includes("dtu.edu") === false)
{
alert("Please insert an official university EMail");
EMailUI.focus();
return false;
}
for (let i = 0; i < users.length; i++) {
if (EMailUI.value == users[i].EMail) {
alert("This EMail is already in use");
document.getElementById ('registration').style.display ='none';
document.getElementById ('login2').style.display ='block';
document.getElementById('EMaillogin').value = EMailUI.value;
return false;
}
}
if (password != "" && password == password2) {
if(password.length < 6) {
alert("Error: Password must contain at least six characters!");
passwordUI.focus();
passwordUI.value="";
return false;
}
re = /[0-9]/;
if(!re.test(password)) {
alert("Error: password must contain at least one number (0-9)!");
passwordUI.focus();
passwordUI.value="";
return false;
}
re = /[a-z]/;
if(!re.test(password)) {
alert("Error: password must contain at least one lowercase letter (a-z)!");
passwordUI.focus();
passwordUI.value="";
return false;
}
re = /[A-Z]/;
if(!re.test(password)) {
alert("Error: password must contain at least one uppercase letter (A-Z)!");
passwordUI.focus();
passwordUI.value="";
return false;
}
} else {
alert("Error: Please check that you've entered and confirmed your password correctly!");
password2UI.focus();
password2UI.value="";
return false;
}
//this code creates a new user and then pushes it to the users array. It then defines that new user as the currentUser, the one that is going to be navigating the rest of the site.
password = window.btoa(passwordUI.value);
let newUser = new Users(fname, lname, EMail, password)
users.push(newUser);
localStorage.setItem('users', JSON.stringify(users))
activeUser = newUser
localStorage.setItem('activeUser', JSON.stringify(activeUser))
window.location.href = "./Collectinginfo.html";
}
function LogIn() {
let inputEMail = document.getElementById('EMaillogin').value;
let inputPassword = document.getElementById('passwordLogin').value;
if (inputPassword.length === 0 || inputEMail.length === 0) {
alert(" Either the Password or EMail you inserted are incorrect");
return false;
}
//this for loop checks the entry fields agains the user array and if it finds a match sets that user the activeUser
for (let i = 0; i < users.length; i++) {
if (inputEMail == users[i].EMail && inputPassword == window.atob(users[i].password)) {
activeUser = users[i]
localStorage.setItem('activeUser', JSON.stringify(users[i]));
isLoggedIn = true;
localStorage.setItem('isLoggedIn', isLoggedIn);
window.location.href = "./JobList.html";
return true;
}
}
alert('Incorrect EMail or password');
return false;
}