From 432b4dc4e5a321e1fc7516ece1c32914b962da45 Mon Sep 17 00:00:00 2001 From: Jan Szumotalski Date: Wed, 21 May 2025 19:54:37 +0200 Subject: [PATCH] fix: Redesigned user cards --- src/helpers/security.ts | 4 ++++ src/routes/api/admin/accs.ts | 17 +++++++++++++++++ src/schemas/User.ts | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/helpers/security.ts b/src/helpers/security.ts index 9d8deb9..741e8a6 100644 --- a/src/helpers/security.ts +++ b/src/helpers/security.ts @@ -48,6 +48,10 @@ class SecurityHelper { return false } } + + clearAcc(userId: string) { + return this.onTimeout.delete(userId) + } } export default new SecurityHelper() \ No newline at end of file diff --git a/src/routes/api/admin/accs.ts b/src/routes/api/admin/accs.ts index 66c8547..03f0934 100644 --- a/src/routes/api/admin/accs.ts +++ b/src/routes/api/admin/accs.ts @@ -3,6 +3,8 @@ import { Router } from "express" import { Perms, adminCond, adminPerm } from "@/utility"; import capability from "@/helpers/capability"; import Group from "@/schemas/Group"; +import security from "@/helpers/security"; +import { Types } from "mongoose"; const accsRouter = Router() @@ -16,6 +18,13 @@ accsRouter.get('/', async (req, res)=> { res.send(data) }) +accsRouter.get('/:id', async (req, res) => { + res.send({ + ...(await User.findById(req.params.id, {pass: 0})).toJSON(), + lockout: !!security.check(new Types.ObjectId(req.params.id)) + }) +}) + accsRouter.post('/', async (req, res)=> { if (req.body.uname == "admin") return res.status(400).send("This name is reserved").end() if (req.body.flags) { @@ -82,4 +91,12 @@ accsRouter.delete('/:id', async (req, res) => { } }) +accsRouter.delete('/:id/lockout', async (req, res) => { + if (security.clearAcc(req.params.id)) { + res.send({status: 200}).end() + } else { + res.sendStatus(400) + } +}) + export {accsRouter}; \ No newline at end of file diff --git a/src/schemas/User.ts b/src/schemas/User.ts index fa9e821..9edb23e 100644 --- a/src/schemas/User.ts +++ b/src/schemas/User.ts @@ -11,6 +11,7 @@ export interface IUser { fname?: string; surname?: string; groups: Types.ObjectId[]; + regDate: Date; } const userSchema = new Schema({ @@ -21,7 +22,8 @@ const userSchema = new Schema({ locked: {type: Boolean, default: false}, fname: String, surname: String, - groups: [{type: mongoose.Types.ObjectId, ref: "Group"}] + groups: [{type: mongoose.Types.ObjectId, ref: "Group"}], + regDate: {type: Date, default: Date.now} }) export default mongoose.model("logins", userSchema) \ No newline at end of file