🐛 fix login undelete/undisable
This commit is contained in:
parent
f700301ccb
commit
b51cb55504
BIN
package-lock.json
generated
BIN
package-lock.json
generated
Binary file not shown.
@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/fosscord/fosscord-api#readme",
|
"homepage": "https://github.com/fosscord/fosscord-api#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fosscord/server-util": "^1.3.48",
|
"@fosscord/server-util": "^1.3.49",
|
||||||
"@types/jest": "^26.0.22",
|
"@types/jest": "^26.0.22",
|
||||||
"@types/json-schema": "^7.0.7",
|
"@types/json-schema": "^7.0.7",
|
||||||
"ajv": "^8.4.0",
|
"ajv": "^8.4.0",
|
||||||
|
|||||||
@ -47,27 +47,20 @@ router.post(
|
|||||||
|
|
||||||
const user = await UserModel.findOne(
|
const user = await UserModel.findOne(
|
||||||
{ $or: query },
|
{ $or: query },
|
||||||
{
|
{ user_data: { hash: true }, id: true, disabled: true, deleted: true, user_settings: { locale: true, theme: true } }
|
||||||
user_data: {
|
|
||||||
hash: true
|
|
||||||
},
|
|
||||||
id: true,
|
|
||||||
user_settings: {
|
|
||||||
locale: true,
|
|
||||||
theme: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
.exec()
|
.exec()
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
throw FieldErrors({ login: { message: req.t("auth:login.INVALID_LOGIN"), code: "INVALID_LOGIN" } });
|
throw FieldErrors({ login: { message: req.t("auth:login.INVALID_LOGIN"), code: "INVALID_LOGIN" } });
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user.disabled && undelete) {
|
if (undelete) {
|
||||||
// undelete refers to un'disable' here
|
// undelete refers to un'disable' here
|
||||||
await UserModel.updateOne({ id: req.user_id }, { disabled: false }).exec();
|
if (user.disabled) await UserModel.updateOne({ id: user.id }, { disabled: false }).exec();
|
||||||
} else if (user.disabled) {
|
if (user.deleted) await UserModel.updateOne({ id: user.id }, { deleted: false }).exec();
|
||||||
return res.status(400).json({ message: req.t("auth:login.ACCOUNT_DISABLED"), code: 20013 });
|
} else {
|
||||||
|
if (user.deleted) return res.status(400).json({ message: "This account is scheduled for deletion.", code: 20011 });
|
||||||
|
if (user.disabled) return res.status(400).json({ message: req.t("auth:login.ACCOUNT_DISABLED"), code: 20013 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// the salt is saved in the password refer to bcrypt docs
|
// the salt is saved in the password refer to bcrypt docs
|
||||||
|
|||||||
Reference in New Issue
Block a user