deleted rootfs and auth_service
This commit is contained in:
1 parent
b694830190
commit
85652a4e99
156 files changed
-2051
No files matched your search
@@ -0,0 +1,68 @@
|
||||
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')
|
||||
|
||||
if (localStorage.getItem("token") === null) {
|
||||
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
|
||||
}
|
||||
|
||||
loginformbody.addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
login(loginusername.value, loginpassword.value)
|
||||
})
|
||||
|
||||
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")
|
||||
}
|
||||
})
|
||||
if (response.status === "403") {
|
||||
notification("Неправильный логин или пароль", "error")
|
||||
}
|
||||
if (response.token) {
|
||||
notification("Успешно", "success")
|
||||
loginform.classList.remove("active")
|
||||
localStorage.setItem("token", response.token)
|
||||
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")
|
||||
})
|
||||
if (response.id) {
|
||||
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')
|
||||
})
|
||||
Reference in new issue
Block a user