arche / internal/archesrv/templates/srv_admin_users.html

commit 154431fd
 1{{ define "title" }}Users — admin{{ end }}
 2{{ define "navextra" }}<a href="/admin/users">users</a> <a href="/admin/invites">invites</a>{{ end }}
 3{{ define "srv_admin_users.html" }}{{ template "head" . }}
 4<div class="container">
 5    <h2 style="margin-bottom: 16px">User management</h2>
 6    <table style="margin-bottom: 24px">
 7        <thead>
 8            <tr>
 9                <th>ID</th>
10                <th>Username</th>
11                <th>Role</th>
12                <th></th>
13            </tr>
14        </thead>
15        <tbody>
16            {{ range .Users }}
17            <tr>
18                <td style="color: #aaa; font-size: 12px">{{.ID}}</td>
19                <td>{{.Username}}</td>
20                <td>
21                    {{ if .IsAdmin }}<span class="badge badge-private">admin</span>{{ else }}<span class="badge badge-public">user</span>{{ end }}
22                </td>
23                <td>
24                    {{ if ne .ID $.User.ID }}
25                    <button onclick="deleteUser({{.ID}}, '{{.Username}}')"
26                            style="background: #c0392b;
27                                   font-size: 12px;
28                                   padding: 2px 8px">Delete</button>
29                {{ else }}
30                    <span style="font-size: 12px; color: #aaa">(you)</span>
31                    {{ end }}
32                </td>
33            </tr>
34            {{ end }}
35        </tbody>
36    </table>
37    <details>
38        <summary style="cursor: pointer; font-size: 13px; color: #555">Create user</summary>
39        <form method="post" action="/admin/users" style="margin-top: 12px">
40            <div class="field">
41                <label>Username</label>
42                <input type="text" name="username" required />
43            </div>
44            <div class="field">
45                <label>Password</label>
46                <input type="password" name="password" required />
47            </div>
48            <div class="field">
49                <label style="display: flex; align-items: center; gap: 6px; cursor: pointer">
50                    <input type="checkbox" name="is_admin" value="1" />
51                    Admin
52                </label>
53            </div>
54            <button type="submit">Create user</button>
55        </form>
56    </details>
57</div>
58<script>
59function deleteUser(id, name) {
60	if (!confirm('Delete user "' + name + '"? This cannot be undone.')) return;
61	fetch("/admin/users/" + id, { method: "DELETE" }).then(function(r) {
62		if (r.ok) {
63			location.reload();
64		} else {
65			r.text().then(alert);
66		}
67	});
68}
69</script>
70{{ template "foot" . }}
71{{ end }}