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`,