fix: Redesigned user cards
This commit is contained in:
@@ -48,6 +48,10 @@ class SecurityHelper {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
clearAcc(userId: string) {
|
||||
return this.onTimeout.delete(userId)
|
||||
}
|
||||
}
|
||||
|
||||
export default new SecurityHelper()
|
||||
@@ -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};
|
||||
@@ -11,6 +11,7 @@ export interface IUser {
|
||||
fname?: string;
|
||||
surname?: string;
|
||||
groups: Types.ObjectId[];
|
||||
regDate: Date;
|
||||
}
|
||||
|
||||
const userSchema = new Schema<IUser>({
|
||||
@@ -21,7 +22,8 @@ const userSchema = new Schema<IUser>({
|
||||
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)
|
||||
Reference in New Issue
Block a user