settingsv1

This commit is contained in:
Flummi 2021-12-24 11:16:29 +01:00
parent e46bbf1195
commit c0413705a8
2 changed files with 56 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import sql from "../../inc/sql.mjs";
const auth = async (req, res, next) => {
if(!req.session)
return res.redirect("/login");
@ -6,8 +8,17 @@ const auth = async (req, res, next) => {
export default (router, tpl) => {
router.group(/^\/settings/, group => {
group.get(/$/, auth, (req, res) => {
res.end("settings lol");
group.get(/$/, auth, async (req, res) => {
const sessions = await sql("user_sessions")
.where("user_id", req.session.id)
.orderBy("last_used", "desc");
res.reply({
body: tpl.render('settings', {
tmp: null,
sessions
}, req)
});
});
});

43
views/settings.html Normal file
View File

@ -0,0 +1,43 @@
@include(main/header)
<h1>Settings</h1>
<h2>Account</h2>
<table class="table">
<tbody>
<tr>
<td>UserID</td>
<td>{{ session.id }}</td>
</tr>
<tr>
<td>level</td>
<td>{{ session.level }}</td>
</tr>
<tr>
<td>username</td>
<td>{!! session.user !!}</td>
</tr>
</tbody>
</table>
<h2>Sessions</h2>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>browser</th>
<th>created_at</th>
<th>last_used</th>
<th>last_action</th>
</tr>
</thead>
<tbody>
@each(sessions as sess)
<tr>
<td>{{ sess.id }}</td>
<td>{{ sess.browser }}</td>
<td>{{ new Date(sess.created_at * 1e3).toLocaleString("de-DE") }}</td>
<td>{{ new Date(sess.last_used * 1e3).toLocaleString("de-DE") }}</td>
<td><a href="{{ sess.last_action }}" target="_blank">{{ sess.last_action }}</a></td>
</tr>
@endeach
</tbody>
</table>
@include(main/footer)