upload testing
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run
This commit is contained in:
1 parent
65b29b105f
commit
dcc4f59552
8 files changed
+845
-357
No files matched your search
+73
-56
@@ -1,79 +1,96 @@
|
||||
const loginform = document.querySelector('.loginform')
|
||||
const loginformbody = document.querySelector('.loginformbody')
|
||||
const loginusername = document.querySelector("#loginusernameinput")
|
||||
const loginpassword = document.querySelector("#loginpasswordinput")
|
||||
const exitbutton = document.querySelector('.exitbutton')
|
||||
const adminpanelsection = document.querySelector('.adminpanel')
|
||||
const headerusername = document.querySelector('.headerusername')
|
||||
const loginform = document.querySelector(".loginform");
|
||||
const loginformbody = document.querySelector(".loginformbody");
|
||||
const loginusername = document.querySelector("#loginusernameinput");
|
||||
const loginpassword = document.querySelector("#loginpasswordinput");
|
||||
const exitbutton = document.querySelector(".exitbutton");
|
||||
const adminpanelsection = document.querySelector(".adminpanel");
|
||||
const headerusername = document.querySelector(".headerusername");
|
||||
|
||||
const hashPassword = async (password) => {
|
||||
const encoder = new TextEncoder()
|
||||
const data = encoder.encode(password)
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', data)
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
||||
const hashHex = hashArray.map(b=>('00' + b.toString(16)).slice(-2)).join('')
|
||||
return hashHex
|
||||
}
|
||||
const encoder = new TextEncoder();
|
||||
const data = encoder.encode(password);
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
const hashHex = hashArray
|
||||
.map((b) => ("00" + b.toString(16)).slice(-2))
|
||||
.join("");
|
||||
return hashHex;
|
||||
};
|
||||
|
||||
if (localStorage.getItem("token") === null) {
|
||||
adminpanelsection.classList.remove('active')
|
||||
loginform.classList.add('active')
|
||||
adminpanelsection.classList.remove("active");
|
||||
loginform.classList.add("active");
|
||||
} else {
|
||||
adminpanelsection.classList.add('active')
|
||||
infosection.classList.add('active')
|
||||
headerusername.innerHTML = JSON.parse(localStorage.getItem('userdata')).username
|
||||
adminpanelsection.classList.add("active");
|
||||
infosection.classList.add("active");
|
||||
headerusername.innerHTML = JSON.parse(
|
||||
localStorage.getItem("userdata"),
|
||||
).username;
|
||||
}
|
||||
|
||||
loginformbody.addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
hashPassword(loginpassword.value).then(hashedpassword => {
|
||||
login(loginusername.value, hashedpassword)
|
||||
})
|
||||
})
|
||||
loginformbody.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
hashPassword(loginpassword.value).then((hashedpassword) => {
|
||||
login(loginusername.value, hashedpassword);
|
||||
});
|
||||
});
|
||||
|
||||
const login = async (username, password) => {
|
||||
const response = await fetch(routes.login(), {
|
||||
method: 'POST',
|
||||
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")
|
||||
}
|
||||
method: "POST",
|
||||
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.status === "403") {
|
||||
notification("Неправильный логин или пароль", "error")
|
||||
notification("Неправильный логин или пароль", "error");
|
||||
}
|
||||
if (response.token) {
|
||||
notification("Успешно", "success")
|
||||
loginform.classList.remove("active")
|
||||
localStorage.setItem("token", response.token)
|
||||
await get_all_settings()
|
||||
adminpanelsection.classList.add('active')
|
||||
await get_user_data()
|
||||
loginusername.value = ""
|
||||
loginpassword.value = ""
|
||||
settingssection.classList.add('active')
|
||||
notification("Успешно", "success");
|
||||
loginform.classList.remove("active");
|
||||
localStorage.setItem("token", response.token);
|
||||
await get_all_settings();
|
||||
adminpanelsection.classList.add("active");
|
||||
await get_user_data();
|
||||
loginusername.value = "";
|
||||
loginpassword.value = "";
|
||||
settingssection.classList.add("active");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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")
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`,
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.then((jsondata) => jsondata)
|
||||
.catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error");
|
||||
});
|
||||
if (response.id) {
|
||||
headerusername.innerHTML = response.username
|
||||
localStorage.setItem("userdata", JSON.stringify(response))
|
||||
headerusername.innerHTML = response.username;
|
||||
localStorage.setItem("userdata", JSON.stringify(response));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exitbutton.addEventListener('click', () => {
|
||||
localStorage.clear()
|
||||
loginform.classList.add('active')
|
||||
notification('Вы вышли', "success")
|
||||
adminpanelsection.classList.remove('active')
|
||||
})
|
||||
const logout = () => {
|
||||
localStorage.clear();
|
||||
loginform.classList.add("active");
|
||||
notification("Вы вышли", "success");
|
||||
adminpanelsection.classList.remove("active");
|
||||
};
|
||||
|
||||
exitbutton.addEventListener("click", () => {
|
||||
logout();
|
||||
});
|
||||
Reference in new issue
Block a user