This commit is contained in:
Flummi 2022-03-24 05:14:56 +01:00
parent cf21298157
commit f1928a1d0a
3 changed files with 11 additions and 8 deletions

View File

@ -30,6 +30,11 @@ export default (router, tpl) => {
if(!(await lib.verify(req.post.password, user[0].password)))
return res.reply({ body: "user doesn't exist or wrong password" });
const stamp = ~~(Date.now() / 1e3);
await sql("user_sessions") // delete unused sessions
.where('last_action', '<=', (Date.now() - 6048e5))
.andWhere('kmsi', 0)
.del();
const session = lib.md5(lib.createID());
await sql("user_sessions").insert({
@ -39,14 +44,9 @@ export default (router, tpl) => {
created_at: stamp,
last_used: stamp,
last_action: "/login",
kmsi: req.post.kmsi === 'on' ? 1 : 0
kmsi: typeof req.post.kmsi !== 'undefined' ? 1 : 0
});
await sql("user_sessions") // delete unused sessions
.where('last_action', '<=', (Date.now() - 6048e5))
.andWhere('kmsi', 0)
.del();
return res.writeHead(301, {
"Cache-Control": "no-cache, public",
"Set-Cookie": `session=${session}; Path=/; Expires=Fri, 31 Dec 9999 23:59:59 GMT`,

View File

@ -1,6 +1,7 @@
@include(snippets/header_admin)
<table style="width: 100%;">
<tr>
<td></td>
<td>ID</td>
<td>userid</td>
<td>user</td>
@ -11,6 +12,7 @@
</tr>
@each(sessions as session)
<tr>
<td>{{ session.kmsi ? '&#9875;' : '' }}</td>
<td>{{ session.id }}</td>
<td>{{ session.user_id }}</td>
<td>{{ session.user }}</td>

View File

@ -66,13 +66,14 @@
<span class="badge badge-dark" id="tags">
@if(typeof item.tags !== "undefined")
@each(item.tags as tag)
<span @if(session)tooltip="{{ tag.user }}" data-tagid="{{ tag.id }}"@endif class="badge {{ tag.badge }} mr-2">
<span @if(session)tooltip="{{ tag.user }} ({{ tag.normalized }})" data-tagid="{{ tag.id }}"@endif class="badge {{ tag.badge }} mr-2">
<a href="/tag/{{ tag.tag }}">{!! tag.tag !!}</a>@if(session)&nbsp;<a href="#">&#215;</a>@endif
</span>
@endeach
@endif
@if(session)
<a href="#" id="a_addtag">add tag</a>&nbsp;-&nbsp;<a href="#" id="a_toggle">toggle</a>
<a href="#" id="a_addtag">add tag</a>&nbsp;-&nbsp;<a href="#" id="a_toggle">toggle</a>
<datalist id="testlist"></datalist>
@endif
</span>
<span class="badge" id="favs"@if(!item.favorites.length || !session) hidden@endif>