mirror of
https://github.com/spacebarchat/server.git
synced 2024-09-21 18:21:36 +02: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.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) {
|
||||
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" } });
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user