mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
added disable route & check if user is disabled
This commit is contained in:
parent
b4e973c3ca
commit
d5a9e2c378
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"login": {
|
"login": {
|
||||||
"INVALID_LOGIN": "E-Mail or Phone not found",
|
"INVALID_LOGIN": "E-Mail or Phone not found",
|
||||||
"INVALID_PASSWORD": "Invalid Password"
|
"INVALID_PASSWORD": "Invalid Password",
|
||||||
|
"ACCOUNT_DISABLED": "This account is disabled"
|
||||||
},
|
},
|
||||||
"register": {
|
"register": {
|
||||||
"REGISTRATION_DISABLED": "New user registration is disabled",
|
"REGISTRATION_DISABLED": "New user registration is disabled",
|
||||||
|
@ -9,7 +9,8 @@ import RateLimit from "../../middlewares/RateLimit";
|
|||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
// TODO: check if user is deleted/restricted
|
// TODO: check if user is deleted --> prohibit login
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
RateLimit({ count: 5, window: 60, onylIp: true }),
|
RateLimit({ count: 5, window: 60, onylIp: true }),
|
||||||
@ -22,7 +23,7 @@ router.post(
|
|||||||
$gift_code_sku_id: String
|
$gift_code_sku_id: String
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { login, password, captcha_key } = req.body;
|
const { login, password, captcha_key, undelete } = req.body;
|
||||||
const email = adjustEmail(login);
|
const email = adjustEmail(login);
|
||||||
const query: any[] = [{ phone: login }];
|
const query: any[] = [{ phone: login }];
|
||||||
if (email) query.push({ email });
|
if (email) query.push({ email });
|
||||||
@ -62,6 +63,13 @@ router.post(
|
|||||||
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) {
|
||||||
|
// undelete refers to un'disable' here
|
||||||
|
await UserModel.updateOne({ id: req.user_id }, { disabled: false }).exec();
|
||||||
|
} else 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
|
||||||
const same_password = await bcrypt.compare(password, user.user_data.hash || "");
|
const same_password = await bcrypt.compare(password, user.user_data.hash || "");
|
||||||
if (!same_password) {
|
if (!same_password) {
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
|
import { UserModel } from "@fosscord/server-util";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import bcrypt from "bcrypt";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", (req: Request, res: Response) => {
|
router.post("/", async (req: Request, res: Response) => {
|
||||||
// TODO:
|
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);
|
res.sendStatus(204);
|
||||||
|
} else {
|
||||||
|
res.status(400).json({ message: "Password does not match", code: 50018 });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
Reference in New Issue
Block a user