some bug fixed
This commit is contained in:
1 parent
e310ed83b7
commit
bff7788c70
8 files changed
+39
-18
No files matched your search
+3
-3
@@ -126,7 +126,7 @@ void add_user(const httplib::Request& request, httplib::Response& response) {
|
|||||||
all_users.push_back(nlohmann::json::parse(new_user_data));
|
all_users.push_back(nlohmann::json::parse(new_user_data));
|
||||||
|
|
||||||
std::ofstream usersfilew("users.json");
|
std::ofstream usersfilew("users.json");
|
||||||
usersfilew << all_users.dump();
|
usersfilew << all_users.dump(4);
|
||||||
usersfilew.close();
|
usersfilew.close();
|
||||||
|
|
||||||
response.set_content("{\"status\":\"ok\"}", "application/json");
|
response.set_content("{\"status\":\"ok\"}", "application/json");
|
||||||
@@ -176,7 +176,7 @@ void del_user(const httplib::Request& request, httplib::Response& response) {
|
|||||||
}
|
}
|
||||||
if (!found) {response.set_content("{\"status\":\"can't find this user\"}", "application/json");return;}
|
if (!found) {response.set_content("{\"status\":\"can't find this user\"}", "application/json");return;}
|
||||||
std::ofstream usersfilew("users.json");
|
std::ofstream usersfilew("users.json");
|
||||||
usersfilew << all_users.dump();
|
usersfilew << all_users.dump(4);
|
||||||
usersfilew.close();
|
usersfilew.close();
|
||||||
response.set_content("{\"status\":\"ok\"}", "application/json");
|
response.set_content("{\"status\":\"ok\"}", "application/json");
|
||||||
}
|
}
|
||||||
@@ -252,7 +252,7 @@ void change_password(const httplib::Request& request, httplib::Response& respons
|
|||||||
}
|
}
|
||||||
if (!found) {response.set_content("{\"status\":\"can't find this user\"}", "application/json");return;}
|
if (!found) {response.set_content("{\"status\":\"can't find this user\"}", "application/json");return;}
|
||||||
std::ofstream usersfilew("users.json");
|
std::ofstream usersfilew("users.json");
|
||||||
usersfilew << all_users.dump();
|
usersfilew << all_users.dump(4);
|
||||||
usersfilew.close();
|
usersfilew.close();
|
||||||
response.set_content("{\"status\":\"ok\"}", "application/json");
|
response.set_content("{\"status\":\"ok\"}", "application/json");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<div class="header">
|
<div class="header">
|
||||||
<button class="exitbutton headerbutton">Exit</button>
|
<button class="exitbutton headerbutton">Exit</button>
|
||||||
<button class="adduserbutton headerbutton">Adduser</button>
|
<button class="adduserbutton headerbutton">Adduser</button>
|
||||||
|
<h1 class="usernameheader"></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form loginform">
|
<div class="form loginform">
|
||||||
|
|||||||
@@ -24,16 +24,19 @@ adduserformbody.addEventListener('submit', async (e) => {
|
|||||||
group: groupinput.value,
|
group: groupinput.value,
|
||||||
is_superuser: is_superuserinput.checked?"1":"0"
|
is_superuser: is_superuserinput.checked?"1":"0"
|
||||||
}
|
}
|
||||||
console.log({...new_user, token: localStorage.getItem('token')})
|
|
||||||
const status = await fetch(routes.adduser(), {
|
const status = await fetch(routes.adduser(), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: `{"token":"${localStorage.getItem('token')}","username":"${new_user.username}","password":"${new_user.password}","group":"${new_user.group}","is_superuser":"${new_user.is_superuser}"}`
|
body: `{"token":"${localStorage.getItem('token')}","username":"${new_user.username}","password":"${new_user.password}","group":"${new_user.group}","is_superuser":"${new_user.is_superuser}"}`
|
||||||
}).then(data => data.json()).then(jsondata => jsondata)
|
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
|
||||||
console.log(status)
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
if (status.status === "ok") {
|
if (status.status === "ok") {
|
||||||
adduserform.classList.remove('active')
|
adduserform.classList.remove('active')
|
||||||
get_all_users()
|
get_all_users()
|
||||||
notification("Пользователь успешно добавлен", "success")
|
notification("Пользователь успешно добавлен", "success")
|
||||||
|
usernameinput.value = ""
|
||||||
|
passwordinput.value = ""
|
||||||
|
groupinput.value = ""
|
||||||
}
|
}
|
||||||
if (status.status === "user already exists") {
|
if (status.status === "user already exists") {
|
||||||
notification("Пользователь с таким именем уже существует", "error")
|
notification("Пользователь с таким именем уже существует", "error")
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ changepasswordformbody.addEventListener('submit', async e => {
|
|||||||
const status = await fetch(routes.change_password_url(), {
|
const status = await fetch(routes.change_password_url(), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: `{"token":"${localStorage.getItem('token')}","userid":"${changepassuserid}","new_password":"${changepasswordnewpassword.value}"}`
|
body: `{"token":"${localStorage.getItem('token')}","userid":"${changepassuserid}","new_password":"${changepasswordnewpassword.value}"}`
|
||||||
}).then(data => data.json()).then(jsondata => jsondata)
|
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
|
||||||
console.log(status)
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
if (status.status === "ok") {
|
if (status.status === "ok") {
|
||||||
notification("Пароль успешно изменен", "success")
|
notification("Пароль успешно изменен", "success")
|
||||||
changepasswordform.classList.remove('active')
|
changepasswordform.classList.remove('active')
|
||||||
|
changepasswordnewpassword.value = ""
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -24,10 +24,12 @@ confirmformok.addEventListener('click', async () => {
|
|||||||
const status = await fetch(routes.deluser(), {
|
const status = await fetch(routes.deluser(), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: `{"token":"${localStorage.getItem('token')}","userid":"${useridtodelete}"}`
|
body: `{"token":"${localStorage.getItem('token')}","userid":"${useridtodelete}"}`
|
||||||
}).then(data => data.json()).then(jsondata => jsondata)
|
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
console.log(status)
|
})
|
||||||
if (status.status === "ok") {
|
if (status.status === "ok") {
|
||||||
|
confirmform.classList.remove('active')
|
||||||
|
get_all_users()
|
||||||
notification("Пользователь успешно удален", "success")
|
notification("Пользователь успешно удален", "success")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -2,8 +2,9 @@ const get_all_users = async () => {
|
|||||||
const response = await fetch(routes.all_users(), {
|
const response = await fetch(routes.all_users(), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||||
}).then(data => data.json()).then(jsondata => jsondata)
|
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
|
||||||
console.log(response)
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
const alluserstablebody = document.querySelector('.alluserstablebody')
|
const alluserstablebody = document.querySelector('.alluserstablebody')
|
||||||
alluserstablebody.innerHTML = ""
|
alluserstablebody.innerHTML = ""
|
||||||
for (const user of response) {
|
for (const user of response) {
|
||||||
|
|||||||
+14
-5
@@ -4,13 +4,11 @@ const loginforminputusername = document.querySelector('#loginforminputusername')
|
|||||||
const loginforminputpassword = document.querySelector('#loginforminputpassword')
|
const loginforminputpassword = document.querySelector('#loginforminputpassword')
|
||||||
const loginformbutton = document.querySelector('.loginformbutton')
|
const loginformbutton = document.querySelector('.loginformbutton')
|
||||||
const exitbutton = document.querySelector('.exitbutton')
|
const exitbutton = document.querySelector('.exitbutton')
|
||||||
|
const usernameheader = document.querySelector('.usernameheader')
|
||||||
// loginformbody.unbind('submit')
|
|
||||||
|
|
||||||
loginformbody.addEventListener('submit', (e) => {
|
loginformbody.addEventListener('submit', (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
login(loginforminputusername.value, loginforminputpassword.value)
|
login(loginforminputusername.value, loginforminputpassword.value)
|
||||||
// console.log(loginform, loginforminputpassword, loginforminputusername, loginformbutton)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const login = async (username, password) => {
|
const login = async (username, password) => {
|
||||||
@@ -23,7 +21,13 @@ const login = async (username, password) => {
|
|||||||
},
|
},
|
||||||
// mode: 'no-cors',
|
// mode: 'no-cors',
|
||||||
body: `{"username":"${username}","password":"${password}"}`
|
body: `{"username":"${username}","password":"${password}"}`
|
||||||
}).then(data => data.json()).then(jsondata => jsondata)
|
}).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") {
|
if (response.status === "403") {
|
||||||
notification("Неправильный логин или пароль", "error")
|
notification("Неправильный логин или пароль", "error")
|
||||||
}
|
}
|
||||||
@@ -32,6 +36,8 @@ const login = async (username, password) => {
|
|||||||
loginform.classList.remove("active")
|
loginform.classList.remove("active")
|
||||||
localStorage.setItem("token", response.token)
|
localStorage.setItem("token", response.token)
|
||||||
get_user_data(response.token)
|
get_user_data(response.token)
|
||||||
|
loginforminputusername.value = ""
|
||||||
|
loginforminputpassword.value = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,9 +45,12 @@ const get_user_data = async (token) => {
|
|||||||
const response = await fetch(routes.user(), {
|
const response = await fetch(routes.user(), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||||
}).then(data => data.json()).then(jsondata => jsondata)
|
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
if (response.is_superuser === "1") {
|
if (response.is_superuser === "1") {
|
||||||
get_all_users()
|
get_all_users()
|
||||||
|
usernameheader.innerHTML = response.username
|
||||||
} else {
|
} else {
|
||||||
document.querySelector('.alluserstablebody').innerHTML = ""
|
document.querySelector('.alluserstablebody').innerHTML = ""
|
||||||
loginform.classList.add("active")
|
loginform.classList.add("active")
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
} else {
|
} else {
|
||||||
document.querySelector('.loginform').classList.add('active')
|
document.querySelector('.loginform').classList.add('active')
|
||||||
}
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
})
|
})
|
||||||
|
usernameheader.innerHTML = JSON.parse(localStorage.getItem('userdata')).username
|
||||||
} else {
|
} else {
|
||||||
document.querySelector('.loginform').classList.add('active')
|
document.querySelector('.loginform').classList.add('active')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user