Enhanced client-side password validation
This commit is contained in:
@@ -18,6 +18,7 @@ const validationSchema = Yup.object({
|
|||||||
.required("Last Name is required"),
|
.required("Last Name is required"),
|
||||||
email: Yup.string()
|
email: Yup.string()
|
||||||
.trim()
|
.trim()
|
||||||
|
.lowercase()
|
||||||
.min(5)
|
.min(5)
|
||||||
.max(69)
|
.max(69)
|
||||||
.email("Invalid email format")
|
.email("Invalid email format")
|
||||||
@@ -31,6 +32,10 @@ const validationSchema = Yup.object({
|
|||||||
.trim()
|
.trim()
|
||||||
.min(8, "Password must be at least 8 characters")
|
.min(8, "Password must be at least 8 characters")
|
||||||
.max(69, "Password must be at most 69 characters")
|
.max(69, "Password must be at most 69 characters")
|
||||||
|
.matches(
|
||||||
|
/^(?=.*[a-zA-Z])(?=.*[0-9]).{8,}$/,
|
||||||
|
"Password needs to contain both letters and numbers"
|
||||||
|
)
|
||||||
.required("Password is required"),
|
.required("Password is required"),
|
||||||
terms: Yup.boolean().oneOf(
|
terms: Yup.boolean().oneOf(
|
||||||
[true],
|
[true],
|
||||||
@@ -51,7 +56,7 @@ export default function App() {
|
|||||||
const handleSubmit = async (values: any) => {
|
const handleSubmit = async (values: any) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
config.serverAddress + "/users",
|
config.serverAddress + "/users/register",
|
||||||
values
|
values
|
||||||
);
|
);
|
||||||
console.log("User created successfully:", response.data);
|
console.log("User created successfully:", response.data);
|
||||||
|
|||||||
@@ -20,8 +20,15 @@ let validationSchema = yup.object({
|
|||||||
password: yup.string().trim().max(100).required(),
|
password: yup.string().trim().max(100).required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", async (req, res) => {
|
router.post("/register", async (req, res) => {
|
||||||
let data = req.body;
|
let data = req.body;
|
||||||
|
let user = await User.findOne({
|
||||||
|
where: { email: data.email },
|
||||||
|
});
|
||||||
|
if (user) {
|
||||||
|
res.status(400).json({ message: "Email already exists." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
data.id = uuidV4();
|
data.id = uuidV4();
|
||||||
data.password = await argon2.hash(data.password);
|
data.password = await argon2.hash(data.password);
|
||||||
@@ -39,7 +46,7 @@ router.post("/", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/all", async (req, res) => {
|
||||||
let condition = {};
|
let condition = {};
|
||||||
let search = req.query.search;
|
let search = req.query.search;
|
||||||
if (search) {
|
if (search) {
|
||||||
@@ -56,7 +63,7 @@ router.get("/", async (req, res) => {
|
|||||||
res.json(list);
|
res.json(list);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/:id", async (req, res) => {
|
router.get("/individual/:id", async (req, res) => {
|
||||||
let id = req.params.id;
|
let id = req.params.id;
|
||||||
let user = await User.findByPk(id);
|
let user = await User.findByPk(id);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -66,7 +73,7 @@ router.get("/:id", async (req, res) => {
|
|||||||
res.json(user);
|
res.json(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put("/:id", async (req, res) => {
|
router.put("/individual/:id", async (req, res) => {
|
||||||
let id = req.params.id;
|
let id = req.params.id;
|
||||||
let user = await User.findByPk(id);
|
let user = await User.findByPk(id);
|
||||||
|
|
||||||
@@ -98,7 +105,7 @@ router.put("/:id", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:id", async (req, res) => {
|
router.delete("/individual/:id", async (req, res) => {
|
||||||
let id = req.params.id;
|
let id = req.params.id;
|
||||||
let user = await User.findByPk(id);
|
let user = await User.findByPk(id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user