misc
This commit is contained in:
@ -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`,
|
||||
|
Reference in New Issue
Block a user