-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script -3- ForgetPass.js
87 lines (80 loc) · 2.82 KB
/
Script -3- ForgetPass.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
let managerEmail = document.querySelector(".email");
let mainPass = document.querySelector(".pass-input");
let confirmPass = document.querySelector(".pass-confirmInput");
let inputButton = document.querySelector(".input-btn");
let showButton = document.querySelector(".showPass-btn");
let resetButton = document.querySelector(".input-btn-submit")
let flag = false;
mainPass.disabled = true;
confirmPass.disabled = true;
if (localStorage.getItem("managerData")) {
var managerDataArray = JSON.parse(localStorage.getItem("managerData"));
}
showButton.addEventListener("click", function () {
let managerPassword;
if (managerEmail.value == "") {
alert("Email is Required!")
}
else {
for (let i = 0; i < managerDataArray.length; i++) {
if (managerEmail.value === managerDataArray[i].managerUsername + "@Company.com") {
managerPassword = managerDataArray[i].managerPassword;
flag = true;
}
}
if (flag == true) {
managerEmail.value = "";
alert("Your Password Is: " + managerPassword);
window.open("Index -1- Login.html", "_self");
}
else {
alert("Company Email Doesn't Match!");
}
}
})
inputButton.addEventListener("click", function () {
mainPass.disabled = false;
confirmPass.disabled = false;
this.style.display = "none";
showButton.style.display = "none";
resetButton.style.display = "flex";
})
resetButton.addEventListener("click", function () {
let flag = false;
let managerIndex;
if (managerEmail.value == '') {
alert("Write Company Email!");
}
else if (managerEmail.value != '') {
for (let i = 0; i < managerDataArray.length; i++) {
if (managerEmail.value === managerDataArray[i].managerUsername + "@Company.com") {
flag = true;
managerIndex = i;
}
}
if (flag == false) {
alert("Email doesn't exist!")
}
else {
if (mainPass.value == "") {
alert("Write a new password!");
}
else if (confirmPass.value == '') {
alert("Confirm your password!");
}
else {
if (confirmPass.value != mainPass.value) {
alert("Passwords do not match!");
mainPass.value = "";
confirmPass.value = "";
}
else {
managerDataArray[managerIndex].managerPassword = mainPass.value;
localStorage.setItem("managerData", JSON.stringify(managerDataArray));
alert("Successful Password Reset ✔️");
window.open("Index -1- Login.html", "_self");
}
}
}
}
})