added username check
This commit is contained in:
parent
ac2fab1476
commit
742e17351e
|
@ -20,6 +20,15 @@ export default async function updateUser(
|
||||||
status: 400,
|
status: 400,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");
|
||||||
|
|
||||||
|
if (!checkUsername.test(user.username))
|
||||||
|
return {
|
||||||
|
response:
|
||||||
|
"Username has to be between 3-30 characters, no spaces and special characters are allowed.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
|
||||||
const userIsTaken = await prisma.user.findFirst({
|
const userIsTaken = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: { not: sessionUser.id },
|
id: { not: sessionUser.id },
|
||||||
|
|
|
@ -52,6 +52,14 @@ export default async function Index(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");
|
||||||
|
|
||||||
|
if (!checkUsername.test(body.username))
|
||||||
|
return res.status(400).json({
|
||||||
|
response:
|
||||||
|
"Username has to be between 3-30 characters, no spaces and special characters are allowed.",
|
||||||
|
});
|
||||||
|
|
||||||
const checkIfUserExists = await prisma.user.findFirst({
|
const checkIfUserExists = await prisma.user.findFirst({
|
||||||
where: emailEnabled
|
where: emailEnabled
|
||||||
? {
|
? {
|
||||||
|
@ -84,8 +92,10 @@ export default async function Index(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(201).json({ response: "User successfully created." });
|
return res.status(201).json({ response: "User successfully created." });
|
||||||
} else if (checkIfUserExists) {
|
} else if (checkIfUserExists) {
|
||||||
res.status(400).json({ response: "Username and/or Email already exists." });
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ response: "Username and/or Email already exists." });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue