mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
🐛 fix claim account
This commit is contained in:
parent
d1844b65d1
commit
976a8e094b
@ -33,12 +33,16 @@ 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.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);
|
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 (body.password) {
|
||||||
const same_password = await bcrypt.compare(body.password, user.data.hash || "");
|
if (user.data?.hash) {
|
||||||
if (!same_password) {
|
const same_password = await bcrypt.compare(body.password, user.data.hash || "");
|
||||||
throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +58,10 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
|
|||||||
}
|
}
|
||||||
|
|
||||||
await user.save();
|
await user.save();
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
delete user.data;
|
||||||
|
|
||||||
// TODO: send update member list event in gateway
|
// TODO: send update member list event in gateway
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "USER_UPDATE",
|
event: "USER_UPDATE",
|
||||||
|
Loading…
Reference in New Issue
Block a user