Files
comp2537-assignment2/views/admin.ejs
T
2025-05-12 15:48:29 -07:00

53 lines
2.1 KiB
Plaintext

<%- include("./partials/header") %>
<div class="m-12 flex flex-row justify-center">
<div>
<div class="flex flex-row justify-between w-sm">
<h1 class="text-white font-bold text-xl">Welcome <%= user.name %></h1>
<a class="w-20 text-center py-1 bg-yellow-400 rounded-md font-semibold" href="/logout">Logout</a>
</div>
<br>
<h1 class="text-white text-lg mb-2">Users</h1>
<div class="flex flex-col justify-between">
<% users.forEach((u) => { %>
<div class="mb-4 bg-gray-200 p-4 flex flex-row justify-between rounded-md">
<div class="mr-6 mt-1"><p><%= u.type %></p></div>
<div class="mr-6 mt-1"><p><%= u.name %></p></div>
<div class="mr-6 mt-1"><p><%= u.email %></p></div>
<div>
<% if (u._id == user._id) { %>
<form method="POST" action="/demote">
<input hidden disabed name="userId" id="userId" value="<%= u._id %>">
<button disabled type="submit" class="w-3xs bg-green-600 rounded-md py-1 text-center text-white font-semibold cursor-not-allowed">
Cannot Demote Self
</button>
</form>
<% } else { %>
<% if (u.type == "admin") { %>
<form method="POST" action="/demote">
<input hidden disabed name="userId" id="userId" value="<%= u._id %>">
<button type="submit" class="w-3xs bg-green-600 rounded-md py-1 text-center text-white font-semibold cursor-pointer">
Demote to User
</button>
</form>
<% } else { %>
<form method="POST" action="/promote">
<input hidden disabed name="userId" id="userId" value="<%= u._id %>">
<button type="submit" class="w-3xs bg-red-400 rounded-md py-1 text-center text-white font-semibold cursor-pointer">
Promote to Admin
</button>
</form>
<% } %>
<% } %>
</div>
</div>
<% }) %>
</div>
</div>
</div>
<%- include("./partials/footer") %>