ХАХАХА Я ЩА ДЕЛАЛ ВООБЩЕМ МИНИ ЗАЩИТУ НА АДМИНА И ПОНЯЛ ЧТО ИСХОДНЫЙ КОТ ОТКРЫТ И МЯУКАТЬ МОЖНО.

This commit is contained in:
neroduckale 2024-01-04 03:28:56 +05:00
parent b1c5e4c5a5
commit 097101bce8
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 399E73062E1A3667
4 changed files with 112 additions and 28 deletions

View file

@ -1,6 +1,6 @@
@page
@model Users
@{ViewData["Title"] = "users";}
<style>
td, th {
padding: 5px 10px;
@ -27,13 +27,44 @@
transition: all;
transition-duration: 300ms;
}
.AdminButtons {
background-color: white;
}
.newuser {
margin-top: 50px;
visibility: hidden;
transition-duration: 0.3s;
}
.margintop {
margin-top: 10px;
}
</style>
<div>
<div id="divine">
<table class="center" id="users">
<tr><th>Айди</th><th>Никнейм</th><th>Масть</th></tr> <!--ряд с ячейками заголовков-->
<tr id="loading"><td>Loading...</td><td>Loading...</td><td>Loading...</td></tr> <!--ряд с ячейками тела таблицы-->
</table>
@{
if (ViewData["Admin"] == "true")
{
<button class="admin" onclick="admin()" id="admin">РЕЖИМ АДМИНА</button>
}
}
</div>
@{
if (ViewData["Admin"] == "true")
{
<div class="newuser" id="newuser">
<span>
<div>nickname</div>
<input id="nickname"/>
<div class="margintop">масть</div>
<input id="mast"/>
<div></div>
<button class="margintop" onclick="neworupdate()">ТАК ТОЧНО!</button>
</span>
</div>
<script src="~/js/admin.js"></script>
}
}
<script src="~/js/site.js"></script>

View file

@ -4,8 +4,11 @@ namespace nrdkwebsite.Pages;
public class Users : PageModel
{
public void OnGet()
public void OnGet(string user)
{
if (user == "admin")
{
ViewData["Admin"] = "true";
}
}
}

View file

@ -0,0 +1,60 @@
function admin() {
document.body.style.background = "black";
document.getElementById("admin").remove();
let adminbuttons = document.getElementsByClassName("ADMINBUT");
for (let item of adminbuttons) {
item.style.display = "";
}
let createuser = document.createElement("button");
createuser.append("НОВЫЙ ПОЛЬЗОВАТЕЛЬ");
createuser.className = "admin";
createuser.addEventListener("click", createclick);
document.getElementById("divine").append(createuser);
}
async function deleteUser(id) {
const response = await fetch(`/api/users/${id}`, {
method: "DELETE",
headers: { "Accept": "application/json" }
});
if (response.ok === true) {
const user = await response.json();
document.getElementById(user.id).remove();
}
else {
const error = await response.json();
console.log(error.message);
}
}
function createclick() {
let form = document.getElementById("newuser");
form.style.visibility = "visible";
}
async function createUser(nickname, mast) {
const response = await fetch("api/users", {
method: "POST",
headers: { "Accept": "application/json", "Content-Type": "application/json" },
body: JSON.stringify({
nickname: nickname,
mast: mast
})
});
if (response.ok === true) {
const user = await response.json();
document.getElementById("users").append(createrow(user, false));
}
else {
const error = await response.json();
console.log(error.message);
}
}
function neworupdate() {
let nickname = document.getElementById("nickname");
let mast = document.getElementById("mast");
createUser(nickname.value, mast.value);
nickname.value = "";
mast.value = "";
}

View file

@ -1,5 +1,5 @@
const loading = document.getElementById("loading");
let loadingLive = true
let loadingLive = true;
async function getUsers() {
// отправляет запрос и получаем ответ
const response = await fetch("/api/users", {
@ -15,41 +15,31 @@ async function getUsers() {
loading.remove();
loadingLive = false
}
users.forEach(user => table.append(create(user)));
users.forEach(user => table.append(createrow(user, true)));
return users;
}
}
function create(user) {
function createrow(user, hidebut) {
let tr = document.createElement("tr");
let tdName = document.createElement("td");
let tdMast = document.createElement("td");
let tdId = document.createElement("td");
let tdBut = document.createElement("td");
let ButtDel = document.createElement("button");
let ButtEdit = document.createElement("button");
tdId.append(user.id);
tdName.append(user.nickname);
tdMast.append(user.mast);
ButtDel.className = "AdminButtons";
ButtDel.append("УДАЛИТЬ");
ButtEdit.append("ИЗМЕНИТЬ");
tdBut.append(ButtDel, ButtEdit);
tdBut.id = "ADMINBUT" + user.id;
tdBut.className = "ADMINBUT"
ButtDel.addEventListener("click", async() => await deleteUser(user.id));
tdBut.append(ButtDel);
tdBut.className = "ADMINBUT";
if (hidebut) {
tdBut.style.display = "none";
}
tr.append(tdId, tdName, tdMast, tdBut);
tr.id = user.id;
return tr;
}
// Добавление пользователя
console.log(getUsers());
console.log("loaded!");
function admin() {
document.body.style.background = "black";
document.getElementById("admin").remove();
let adminbuttons = document.getElementsByClassName("ADMINBUT");
for (let item of adminbuttons) {
item.style.display = "inline";
}
}
getUsers();