-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls.js
188 lines (164 loc) · 5.54 KB
/
ls.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
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
const bin = document.getElementById("bin_point")
const profile = document.getElementById("profile_point")
const nav = document.querySelector(".header__nav_me")
const navAll = document.getElementsByClassName("header__nav")
const hello = document.getElementById("header-title")
let exitBtn = document.getElementById("exit_btn")
const ls = document.getElementById("ls_point")
const main = document.querySelector(".main")
userNowId = JSON.parse(localStorage.getItem("lastUserLogged"))[0]
logName = JSON.parse(localStorage.getItem("lastUserLogged"))[1]
hello.textContent = `САЛАМАЛЕЙКУМ ${logName}`
users = JSON.parse(localStorage.getItem("accounts"))
let user
for (let i = 0; i < users.length; i++) {
if (users[i].id == userNowId){
user = users[i]
let removed = users.splice(i, 1);
break
}
}
const userDataDiv = document.getElementById("user-data")
profile.addEventListener("click", (e)=>{
e.stopPropagation() // Я не знаю как работает, но без этого не работает
profile.style.display = "none"
exitBtn.style.display = "block"
exitBtn.style.display = "block"
exitBtn.style.background = "red"
exitBtn.style.color = "white"
exitBtn.style.fontSize = "12px"
exitBtn.innerText = "Выйти???"
exiting = true
ls.style.display = "block"
ls.style.background = "white"
ls.style.color = "black"
ls.style.fontSize = "12px"
ls.innerText = "Личка"
})
exitBtn.addEventListener("click", ()=>{
window.location.href = "login.html"
})
ls.addEventListener("click", ()=>{
window.location.href = "ls.html"
})
document.addEventListener("click", (e) => {
console.log(e)
if (e.target !== exitBtn || e.target !==ls) {
exitBtn.style.display = "none"
ls.style.display = "none"
profile.style.display ="block"
exiting = false
}
})
const mainP = document.createElement("p")
mainP.textContent = `How are you doing, ${logName}?`
mainP.classList.add('main-title')
main.insertAdjacentElement("afterBegin", mainP)
let nameLabel = document.createElement("p")
nameLabel.textContent = "Login"
let userName = document.createElement("input")
userName.type = "text"
userName.readOnly = true
userName.value = user.login
userName.classList.add("userDatas")
const logDiv = document.createElement("div")
logDiv.append(nameLabel)
logDiv.append(userName)
logDiv.classList.add("userDataDivs")
userDataDiv.append(logDiv)
let emLabel = document.createElement("p")
emLabel.textContent = "E-mail"
let userEm = document.createElement("input")
userEm.type = "email"
userEm.readOnly = true
userEm.value = user.em
userEm.classList.add("userDatas")
const emDiv = document.createElement("div")
emDiv.append(emLabel)
emDiv.append(userEm)
userDataDiv.append(emDiv)
emDiv.classList.add("userDataDivs")
let passLabel = document.createElement("p")
passLabel.textContent = "Password"
let userPass = document.createElement("input")
userPass.type = "password"
userPass.readOnly = true
userPass.value = user.pass
userDataDiv.append(passLabel)
userDataDiv.append(userPass)
userPass.classList.add("userDatas")
const passDiv = document.createElement("div")
passDiv.append(passLabel)
passDiv.append(userPass)
userDataDiv.append(passDiv)
passDiv.classList.add("userDataDivs")
let editBtn = document.createElement("button")
editBtn.textContent = "Edit"
editBtn.classList.add("edit_btn")
let editLabel = document.createElement("p")
editLabel.textContent = "Edit/Save"
const editDiv = document.createElement("div")
editDiv.append(editLabel)
editDiv.append(editBtn)
userDataDiv.append(passDiv)
editDiv.classList.add("userDataDivs")
userDataDiv.append(editDiv)
let edit = false
editBtn.addEventListener('click', ()=>{
if (!edit) {
let inputs = document.querySelectorAll(".userDatas")
console.log(inputs);
userName.readOnly = false
userEm.readOnly = false
userPass.readOnly = false
editBtn.textContent = "Save"
edit = true
}
else{
let inputs = document.querySelectorAll(".userDatas")
console.log(inputs);
let errorStill = false
let error = document.createElement("p")
error.style.color = "red"
users.forEach(element => {
if (element.login == userName.value) {
error.textContent = "This login is already zanyat"
errorStill = true
}
else if (element.em == userEm.value) {
error.textContent = "This email is already zanyat"
errorStill = true
}
else if (userPass.value.length < 8){
error.textContent = "This password is too short. It must be at least 8"
errorStill = true
}
});
if (error.textContent != undefined && errorStill == true) {
userDataDiv.append(error)
errorStill = false
}
else{
userName.readOnly = true
userEm.readOnly = true
userPass.readOnly = true
editBtn.textContent = "Edit"
edit = false
save(userName.value, userEm.value, userPass.value)
}
}
})
function save(l, e, p){
const newUser ={
id: userNowId,
login: l,
em: e,
pass: p,
}
users.push(newUser)
localStorage.removeItem("accounts")
localStorage.setItem("accounts", JSON.stringify(users))
localStorage.removeItem("lastUserLogged")
localStorage.setItem("lastUserLogged", JSON.stringify([userNowId, newUser.login]))
location.reload()
}