diff --git a/web/css/loginform.css b/web/css/loginform.css index fdc9bd6..5f60f4b 100644 --- a/web/css/loginform.css +++ b/web/css/loginform.css @@ -28,7 +28,6 @@ background-color: gray; backdrop-filter: blur(5px); border-radius: 10px; - /* box-shadow: -5px -5px 30px 30px gray; */ } .loginformheader { @@ -51,7 +50,7 @@ display: flex; } -.loginforminputbodyflex>button { +.loginforminputbodyflex > button { margin: 10px; } diff --git a/web/css/message.css b/web/css/message.css index d69d710..a97851d 100644 --- a/web/css/message.css +++ b/web/css/message.css @@ -1,19 +1,33 @@ -.message { - width: 100%; +* { + transition: 0.3s; +} + +.notificationsection { + width: max-content; + height: 100vh; + position: fixed; + top: 10px; + right: 0; + pointer-events: none; + z-index: 16; +} + +.notification { + width: max-content; height: 0; overflow: hidden; pointer-events: none; z-index: 10; border-radius: 10px; - position: fixed; top: 0; - left: 0; - transition: 0.3s; + right: 0; cursor: pointer; opacity: 0.8; + margin: 10px; + padding: 0 10px; } -.messagetextbox { +.notificationtextbox { width: 100%; height: 100%; display: grid; @@ -22,19 +36,19 @@ pointer-events: none; } -.messagetext { +.notificationtext { width: 100%; text-align: center; pointer-events: none; } -.message.active.error { +.notification.active.error { pointer-events: all; height: 10%; background-color: rgb(233, 70, 70); } -.message.active.success { +.notification.active.success { pointer-events: all; height: 10%; background-color: rgb(76, 209, 76); diff --git a/web/index.html b/web/index.html index 66525bb..faa0829 100644 --- a/web/index.html +++ b/web/index.html @@ -1,155 +1,231 @@ - + - - - - - - - admin - - - + + + + + + + admin + + + -
-
-

Login

-
- - +
+ +

Login

+
+ + +
+
+ + +
+
+ +
+
-
- - -
-
- -
- -
-
-
-

Add User

-
- - +
+ +

Add User

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -
-
-
-

Change User Data

-
- - +
+ +

Change User Data

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-
- - -
-
- - -
-
- - -
-
- - -
- -
-
-
-

Are you sure?

-
- - +
+
+

Are you sure?

+
+ + +
+
-
-
-
-
-

Change Password

-
- - +
+ +

Change Password

+
+ + +
+
+ + +
+
-
- - + +
+ +
+ + + + + + + + + + + + + + +
idusernameemailgroupis_superuserdeletechange passwordchange user data
- -
- -
-
-

-
-
- -
- - - - - - - - - - - - - - -
idusernameemailgroupis_superuserdeletechange passwordchange user data
-
- - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/web/js/login.js b/web/js/login.js index a2af6da..5cc92cd 100644 --- a/web/js/login.js +++ b/web/js/login.js @@ -1,83 +1,93 @@ -const loginform = document.querySelector('#loginform') -const loginformbody = document.querySelector('#loginformbody') -const loginforminputusername = document.querySelector('#loginforminputusername') -const loginforminputpassword = document.querySelector('#loginforminputpassword') -const exitbutton = document.querySelector('#exitbutton') -const usernameheader = document.querySelector('.usernameheader') +const loginform = document.querySelector("#loginform"); +const loginformbody = document.querySelector("#loginformbody"); +const loginforminputusername = document.querySelector( + "#loginforminputusername", +); +const loginforminputpassword = document.querySelector( + "#loginforminputpassword", +); +const exitbutton = document.querySelector("#exitbutton"); +const usernameheader = document.querySelector(".usernameheader"); if (localStorage.getItem("token") === null) { - loginform.classList.add("active") + loginform.classList.add("active"); } -loginformbody.addEventListener('submit', (e) => { - e.preventDefault() - hashPassword(loginforminputpassword.value).then(hashedpassword => { - login(loginforminputusername.value, hashedpassword) - }) -}) +loginformbody.addEventListener("submit", (e) => { + e.preventDefault(); + hashPassword(loginforminputpassword.value).then((hashedpassword) => { + login(loginforminputusername.value, hashedpassword); + }); +}); const login = async (username, password) => { - const response = await fetch(routes.login(), { - method: 'POST', - headers: { - Accept: 'application/json', - // 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', - }, - // mode: 'no-cors', - body: `{"username":"${username}","password":"${password}"}` - }).then(data => data.json()).then(jsondata => jsondata).catch((error) => { - if (error.message === "Unexpected end of JSON input") { - notification(`Ошибка на сервере: Создайте файл users.json и запишите в него первого пользователя`, "error") - } else { - notification(`Ошибка на сервере: ${error}`, "error") - } - }) - if (response.error) { - loginforminputusername.classList.add('is-invalid') - loginforminputpassword.classList.add('is-invalid') - notification("Неправильный логин или пароль", "error") - } - if (response.token) { - notification("Успешно", "success") - loginform.classList.remove("active") - localStorage.setItem("token", response.token) - await get_user_data() - loginforminputusername.value = "" - loginforminputpassword.value = "" - loginforminputusername.classList.remove('is-invalid') - loginforminputpassword.classList.remove('is-invalid') - } -} + const response = await fetch(routes.login(), { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: `{"username":"${username}","password":"${password}"}`, + }) + .then((data) => data.json()) + .then((jsondata) => jsondata) + .catch((error) => { + if (error.message === "Unexpected end of JSON input") { + notification( + `Ошибка на сервере: Создайте файл users.json и запишите в него первого пользователя`, + "error", + ); + } else { + notification(`Ошибка на сервере: ${error}`, "error"); + } + }); + if (response.error) { + loginforminputusername.classList.add("is-invalid"); + loginforminputpassword.classList.add("is-invalid"); + notification("Неправильный логин или пароль", "error"); + } + if (response.token) { + notification("Успешно", "success"); + loginform.classList.remove("active"); + localStorage.setItem("token", response.token); + await get_user_data(); + loginforminputusername.value = ""; + loginforminputpassword.value = ""; + loginforminputusername.classList.remove("is-invalid"); + loginforminputpassword.classList.remove("is-invalid"); + } +}; const get_user_data = async () => { - const response = await fetch(routes.user(), { - method: "POST", - body: `{"token":"${localStorage.getItem("token")}"}` - }).then(data => data.json()).then(jsondata => jsondata).catch((error) => { - notification(`Ошибка на сервере: ${error}`, "error") - }) - if (response.is_superuser) { - await get_all_users() - usernameheader.innerHTML = response.username - } else { - document.querySelector('#alluserstablebody').innerHTML = "" - loginform.classList.add("active") - notification("Вы не можете войти потому что не являетесь администратором", "error") - localStorage.clear() - } - if (response.id) { - localStorage.setItem("userdata", JSON.stringify(response)) - } -} + const response = await fetch(routes.user(), { + method: "POST", + body: `{"token":"${localStorage.getItem("token")}"}`, + }) + .then((data) => data.json()) + .then((jsondata) => jsondata) + .catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error"); + }); + if (response.is_superuser) { + await get_all_users(); + usernameheader.innerHTML = response.username; + } else { + document.querySelector("#alluserstablebody").innerHTML = ""; + loginform.classList.add("active"); + notification( + "Вы не можете войти потому что не являетесь администратором", + "error", + ); + localStorage.clear(); + } + if (response.id) { + localStorage.setItem("userdata", JSON.stringify(response)); + } +}; -message.addEventListener('click', () => { - message.classList.remove("active") -}) - -exitbutton.addEventListener('click', () => { - localStorage.removeItem('token') - localStorage.removeItem('userdata') - loginform.classList.add('active') - notification('Вы вышли', "success") -}) +exitbutton.addEventListener("click", () => { + localStorage.removeItem("token"); + localStorage.removeItem("userdata"); + loginform.classList.add("active"); + notification("Вы вышли", "success"); +}); diff --git a/web/js/message.js b/web/js/message.js index 8014faa..e1a9c7b 100644 --- a/web/js/message.js +++ b/web/js/message.js @@ -1,18 +1,34 @@ -const message = document.querySelector('.message') -const messagetext = document.querySelector('.messagetext') +const notificationsection = document.querySelector(".notificationsection"); const notification = (text, type) => { - if (type === "error") { - message.classList.remove('success') - message.classList.add('error') - } else { - message.classList.remove('error') - message.classList.add('success') - } - messagetext.innerHTML = text - message.classList.add('active') + const notificationbox = document.createElement("div"); + const notificationtextbox = document.createElement("div"); + const notificationtext = document.createElement("h3"); + notificationtext.classList.add("notificationtext"); + notificationtextbox.append(notificationtext); + notificationtextbox.classList.add("notificationtextbox"); + notificationtextbox.classList.add("card-header"); + notificationbox.append(notificationtextbox); + notificationbox.classList.add("notification"); + notificationbox.addEventListener("click", () => { + notificationbox.classList.remove("active"); + }); + notificationsection.append(notificationbox); + if (type === "error") { + notificationbox.classList.remove("success"); + notificationbox.classList.add("error"); + } else { + notificationbox.classList.remove("error"); + notificationbox.classList.add("success"); + } + notificationtext.innerHTML = text; + setTimeout(() => { + notificationbox.classList.add("active"); + }, 300); + setTimeout(() => { + notificationbox.classList.remove("active"); setTimeout(() => { - message.classList.remove('active') - }, 2000) -} - + notificationsection.removeChild(notificationbox); + }, 200); + }, 3000); +};