-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
326 lines (285 loc) · 11.4 KB
/
Copy pathapp.js
File metadata and controls
326 lines (285 loc) · 11.4 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// Facebook Dashboard Post Functionality
function post() {
var post = document.getElementById("post");
var description = document.getElementById("description")
var image = document.getElementById("file")
var file = image.files[0]
var imgUrl = URL.createObjectURL(file)
post.innerHTML += `
<div class="post-box-2 my-3">
<div class="d-flex justify-content-between" style="padding: 7px 13px;">
<div class="links d-flex align-items-center gap-2 py-1">
<img width="40px"
src="./assets/user-profile-icon-vector-avatar-600nw-2558760599-removebg-preview.png"
alt="">
<div class="d-flex flex-column gap-1">
<p class="menu-text">Ayan Zaveri</p>
<div class="d-flex align-items-center gap-2">
<p class="public">13h</p>
<img height="12px"
src="https://static.xx.fbcdn.net/rsrc.php/v4/y5/r/qop9rFQ_Ys1.png?_nc_eui2=AeHJXVfQv0zgxugaFCigGg6IRdYIPs78prZF1gg-zvymtqzrD4TGfDbEjTtLVLRz-zonVXl9UN-9-PjSVoY5H5jl"
alt="">
</div>
</div>
</div>
<div class="post-icons d-flex gap-3 p-2">
<svg viewBox="0 0 20 20" width="20" height="20" fill="currentColor"
class="x14rh7hd x1lliihq x1tzjh5l x1k90msu x2h7rmj x1qfuztq"
style="--x-color: var(--secondary-icon);">
<g fill-rule="evenodd" transform="translate(-446 -350)">
<path
d="M458 360a2 2 0 1 1-4 0 2 2 0 0 1 4 0m6 0a2 2 0 1 1-4 0 2 2 0 0 1 4 0m-12 0a2 2 0 1 1-4 0 2 2 0 0 1 4 0">
</path>
</g>
</svg>
<svg id="remove" viewBox="0 0 20 20" width="20" height="20" fill="currentColor" aria-hidden="true"
class="x14rh7hd x1lliihq x1tzjh5l x1k90msu x2h7rmj x1qfuztq"
style="--x-color: var(--secondary-icon);">
<path
d="M15.543 3.043a1 1 0 1 1 1.414 1.414L11.414 10l5.543 5.542a1 1 0 0 1-1.414 1.415L10 11.414l-5.543 5.543a1 1 0 0 1-1.414-1.415L8.586 10 3.043 4.457a1 1 0 1 1 1.414-1.414L10 8.586l5.543-5.543z">
</path>
</svg>
</div>
</div>
<div class="main-post">
<div style="padding: 0px 13px;">
<p> ${description.value} </p>
</div>
<div class="post-div">
<img class="post-img"
src="${imgUrl}"
alt="">
</div>
</div>
</div>
`;
description.value = " "
image.files = " "
}
// Toggle Eye Functionality
let eyeIcon = document.getElementById("togglePassword")
eyeIcon.onclick = passtoggle
function passtoggle() {
let pass = document.getElementById("password")
if (pass.type === "password") {
pass.type = "text"
eyeIcon.className = "fa-regular fa-eye"
} else {
pass.type = "password"
eyeIcon.className = "fa-regular fa-eye-slash"
}
}
// Register Functionality
function emptyfields() {
let firstName = document.getElementById("firstName").value = ""
let surName = document.getElementById("surName").value = ""
let day = document.getElementById("day").value = "Day"
let month = document.getElementById("month").value = "Month"
let year = document.getElementById("year").value = "Year"
let gender = document.getElementsByName("gender")
let email = document.getElementById("email").value = ""
let password = document.getElementById("password").value = ""
}
function passGen() {
let char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
let numbers = "1234567890"
let specialChar = "!@#$%^&*()-_=+][{}|;:<>.,?/"
let passLength = 3
let pass = ""
for (let i = 0; i < passLength; i++) {
let ranIndex1 = Math.floor(Math.random() * char.length)
let ranIndex2 = Math.floor(Math.random() * numbers.length)
let ranIndex3 = Math.floor(Math.random() * specialChar.length)
pass += char[ranIndex1] + numbers[ranIndex2] + specialChar[ranIndex3]
}
let password = document.getElementById("password").value = pass
console.log(password)
}
function signUp() {
let firstName = document.getElementById("firstName").value
let surName = document.getElementById("surName").value
let day = document.getElementById("day").value
let month = document.getElementById("month").value
let year = document.getElementById("year").value
let gender = document.getElementsByName("gender")
let email = document.getElementById("email").value.trim()
let emailRegEx = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
let password = document.getElementById("password").value
let nunRegEx = /(?=.*\d)/
let speRegEx = /(?=.*[!@#$%^&()`~\-_'+=,.?":{}|<>])/
let missing = [];
if (firstName === "" && surName === "") {
Swal.fire({
icon: "error",
title: "Enter Your Full Name!!!",
text: "Please Enter Your Full Name!",
});
return
}
if (firstName.trim() === "") missing.push("First Name")
if (surName.trim() === "") missing.push("Sur Name")
if (missing.length > 0) {
Swal.fire({
icon: "error",
title: "Enter Your Full Name Correctly",
text: "Please Enter Your " + missing.join(", ")
});
return;
}
if (day === "Day" && month === "Month" && year === "Year") {
Swal.fire({
icon: "error",
title: "Enter Your Date Of Birth!!!",
text: "Please Enter Your Date Of Birth Correctly!",
});
return
}
if (day === "Day") missing.push("Day");
if (month === "Month") missing.push("Month");
if (year === "Year") missing.push("Year");
if (missing.length > 0) {
Swal.fire({
icon: "error",
title: "Incomplete Date of Birth",
text: "Please select: " + missing.join(", ")
});
return;
}
let userGender = ""
for (let i = 0; i < gender.length; i++) {
if (gender[i].checked) {
userGender = gender[i].value
}
}
if (!userGender) {
Swal.fire({
icon: "error",
title: "Enter Your Gender!!!",
text: "Please Enter Your Gender Correctly!",
});
return
}
if (email === "") {
Swal.fire({
icon: "error",
title: "Enter Your Email!!!",
text: "Please Enter Your Email!",
});
return
}
if (!emailRegEx.test(email)) {
Swal.fire({
icon: "error",
title: "Enter Correct Email!!!",
text: "Please Enter Your Email Correctly!",
});
return
}
if (password === "") {
Swal.fire({
icon: "error",
title: "Enter Your Password!!!",
text: "Please Enter Your Password!",
});
return
}
if (password.length < 9) missing.push("Atleast 9 Characters")
if (!nunRegEx.test(password)) missing.push("Atleast Enter one number")
if (!speRegEx.test(password)) missing.push("Atleast Enter one Special Character")
if (missing.length > 0) {
Swal.fire({
icon: "error",
title: "Enter a Stronger PIN!!!",
html: "Please enter:<br><br>" + missing.join("<br>") + " in your Password",
});
return
}
let user = true;
let usersData = JSON.parse(localStorage.getItem("Data"))
for (let i = 0; i < usersData.length; i++) {
if (email === usersData[i].email) {
user = false
Swal.fire({
icon: "error",
title: "User Already Registered",
text: "Log In",
footer: '<a class="forgot-link-2" href="./account.html">Log In</a>'
});
break
}
}
if (user) {
Swal.fire({
icon: "success",
title: "Succesfully Registered In!!!",
text: "Congrats!!! You Have Succesfully Registered",
});
let data = {
fName: firstName,
sName: surName,
email: email,
pass: password,
gender: userGender,
dob: `${day}-${month}-${year}`
}
console.log(data)
let usersArr = JSON.parse(localStorage.getItem("Data")) || [];
usersArr.push(data)
localStorage.setItem("Data", JSON.stringify(usersArr))
emptyfields()
setTimeout(function () {
window.location.href = "/dashboard.html"
}, 3000)
}
}
// Login Functionality
function login() {
let email = document.getElementById("email").value.trim()
let password = document.getElementById("password").value.trim()
let usersData = JSON.parse(localStorage.getItem("Data"))
let user = false
let missing = []
if (email === "" && password === "") {
Swal.fire({
icon: "error",
title: "Fill in both the Fields!!!",
text: "Please Fill in all the Fields!",
footer: '<a class="forgot-link-2" href="./account.html">Register your account</a>'
});
return
}
if (password === "") missing.push("Password")
if (email === "") missing.push("Email")
if (missing.length > 0) {
Swal.fire({
icon: "error",
title: "Enter your " + missing.join() + "!!!",
text: "Please Enter your: " + missing.join(),
footer: '<a class="forgot-link-2" href="./account.html">Register your account</a>'
});
return
}
for (let i = 0; i < usersData.length; i++) {
// console.log(usersData[i].email)
if (email === usersData[i].email && password === usersData[i].pass) {
user = true
Swal.fire({
icon: "success",
title: "Succesfully Logged In",
text: "You will be redirected shortly"
});
setTimeout(function () {
window.location.href = "./dashboard.html"
}, 3000)
break
}
if (!user) {
Swal.fire({
icon: "error",
title: "Invalid Credentials",
text: "Please Enter correct Email or Password",
footer: '<a class="forgot-link-2" href="./account.html">Register your account</a>'
});
}
}
}