akf-forum/themes/default/user.ejs

183 lines
No EOL
6.5 KiB
Text

<!DOCTYPE html>
<html lang="en">
<%- include("extra/meta", {title: member.name }) %>
<body>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"></script>
<link rel="stylesheet" href="/css/user.css" />
<%- include("extra/navbar") %>
<div class="content">
<% if(user?.admin || user?.id === member.id){ %>
<details>
<summary class="btn-outline-primary">User Menu:</summary>
<% if (!member.discordID && discord && user?.id === member.id) { %>
<a href="<%=discord%>" class="btn-outline-primary">DC auth</a>
<% } else if(member.discordID && user?.id === member.id) { %>
<a class="btn-outline-primary" id="un_discord">Unauth DC!</a>
<% } %>
<a href="/users/<%=member.id%>/avatar" class="btn-outline-primary">Upload avatar</a>
<link rel="stylesheet" href="/css/modal.css" />
<a class="btn-outline-primary" id="toogle">Edit user!</a>
<div class="modal no-active" id="user-edit">
<div class="modal-content">
<div class="modal-close">
<i id="toogle" class="fa-solid fa-square-xmark"></i>
</div>
<h1 class="title" style="text-align:center;">Edit <a class="see" href="/users/<%= member.id %>"><%= member.name %></a></h1>
<div class="content">
<form id="form" class="see" style="box-shadow:none">
<input type="text" name="name" placeholder="<%=member.name%>" class="input">
<textarea class="input" name="about" rows="4" cols="60" name="content" placeholder="<%=member.about%>"></textarea>
<% if (user?.admin){ %>
Is Admin? <input id='admin' type='checkbox' value='true' name='admin' <%=member.admin ? "checked": ""%>>
<input id='adminHidden' type='hidden' value='false' name='admin'>
<% } %>
<button class="btn-primary" style="width:100%;">Update User!</button>
</form>
</div>
</div>
</div>
<script type="module">
import request from "../../js/request.js";
const form = document.getElementById("form");
document.addEventListener("click", async e => {
if (e.target.id == "delete") {
const response = await request("/api/users/<%= member.id %>", "DELETE");
if (response.state !== "DELETED") return
alert("User is deleted!");
location.reload()
} else if (e.target.id == "undelete") {
const response = await request("/api/users/<%= member.id %>/", "PATCH", {
deleted: false
});
if (response.state == "DELETED") return;
alert("User is undeleted successfully!");
location.reload()
} else if (e.target.id == "un_discord") {
const response = await fetch("/auth/discord/", {
method: "DELETE"
});
alert(await response.text());
location.reload()
} else if (e.target.id.startsWith("last_")) {
let hideLastSeen = e.target.id.replace("last_", "") == "hide" ? true : false;
const response = await request("/api/users/<%= member.id %>/", "PATCH", {
hideLastSeen
});
alert(`Last seen is ${!hideLastSeen?"un":""}hided!`);
location.reload()
} else if (e.target.id == "toogle")
document.getElementById('user-edit').classList.toggle('no-active')
});
form.addEventListener("submit", async e => {
e.preventDefault();
document.getElementById('adminHidden').disabled = document.getElementById("admin").checked;
const object = {};
new FormData(e.target).forEach((value, key) => object[key] = value);
const res = await request("/api/users/<%=member.id%>", "PATCH", object);
if (res) alert(`User is updated!`);
location.reload();
});
</script>
<% if (member.hideLastSeen) {%>
<a id="last_unhide" class="btn-primary">Unhide last seen! </a>
<% } else { %>
<a id="last_hide" class="btn-outline-primary">Hide last seen! </a>
<% } %>
<% if (member.deleted) {%>
<h1>This user has been deleted!</h1>
<a id="undelete" class="btn-primary">Undelete user! </a>
<% } else if (user?.admin){ %>
<a id="delete" class="btn-outline-primary">Delete user! </a>
<% } %>
<% if (user?.admin) {%>
<h2>IP adresses of the user:</h2>
<select>
<% for(const ip of member.ips) { %>
<option><%= ip %></option>
<% } %>
</select>
<% } %>
</details>
<% } %>
<div class="box" style="justify-content:center;">
<img style="width:150px;height:150px;border-radius:50%;" src="<%=member.avatar %>">
</div>
<% if (member.admin) { %>
<h2 class="box-value" style="align-self: center;">Admin</h2>
<% } %>
<div class="box-value" id="about" style="
margin: 10px auto;
box-shadow: 0 0 5px 0 var(--second);
padding: 10px;
width: 100%;
max-width: 800px;
text-align: center;
border-radius: 5px;
background: none;
color: var(--anti);
">
<%= member.about %>
</div>
<script>
const converter = new showdown.Converter();
const about = document.getElementById("about")
about.innerHTML = converter.makeHtml(about.innerText);
</script>
<div class="box">
<h2 class="box-title">Name:</h2>
<h2 class="box-value"><%= member.name %></h2>
</div>
<div class="box">
<h2 class="box-title">Created at:</h2>
<h2 class="box-value"><%= new Date(member.time).toLocaleString() %></h2>
</div>
<% if(!member.hideLastSeen || user?.admin) {%>
<div class="box">
<h2 class="box-title">Last seen at:</h2>
<h2 class="box-value"><%= new Date(member.lastSeen).toLocaleString() %></h2>
</div>
<% } %>
<div class="box">
<a href="/search/messages?authorID=<%= member.id %>" class="box-title">Message:</a>
<a class="box-value"><%= counts.message %></a>
</div>
<div class="box">
<a href="/search/threads?authorID=<%= member.id %>" class="box-title">Thread:</a>
<h2 class="box-value"><%= counts.thread %></h2>
</div>
</div>
<%- include("extra/footer") %>
</body>
</html>