1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-22 02:31:36 +02:00

🐛 fix claim account

This commit is contained in:
Flam3rboy 2021-10-09 13:04:27 +02:00
parent d1844b65d1
commit 976a8e094b

View File

@ -33,13 +33,17 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
if (body.avatar) body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string);
if (body.banner) body.banner = await handleFile(`/banners/${req.user_id}`, body.banner as string);
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: PrivateUserProjection });
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: [...PrivateUserProjection, "data"] });
if (body.password) {
if (user.data?.hash) {
const same_password = await bcrypt.compare(body.password, user.data.hash || "");
if (!same_password) {
throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
}
} else {
user.data.hash = await bcrypt.hash(body.password, 12);
}
}
user.assign(body);
@ -54,6 +58,10 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
}
await user.save();
// @ts-ignore
delete user.data;
// TODO: send update member list event in gateway
await emitEvent({
event: "USER_UPDATE",