summary refs log tree commit diff
path: root/api/src/routes/users/@me/disable.ts
blob: 2d3a9850b0043bcfa553749a7443530028e19ee6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { UserModel } from "@fosscord/util";
import { Router, Response, Request } from "express";
import bcrypt from "bcrypt";

const router = Router();

router.post("/", async (req: Request, res: Response) => {
	const user = await UserModel.findOne({ id: req.user_id }).exec(); //User object

	let correctpass = await bcrypt.compare(req.body.password, user!.user_data.hash); //Not sure if user typed right password :/
	if (correctpass) {
		await UserModel.updateOne({ id: req.user_id }, { disabled: true }).exec();

		res.sendStatus(204);
	} else {
		res.status(400).json({ message: "Password does not match", code: 50018 });
	}
});

export default router;