Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 39ec6f9

Browse files
authored
Merge pull request #7 from rohan-ramakrishnan/master
validation complete
2 parents c655b69 + 1b7e5c9 commit 39ec6f9

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

routes/auth.routes.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,49 @@
1-
const express = require('express');
1+
const express = require("express");
2+
const { body } = require("express-validator/check");
23

34
const router = express.Router();
45

5-
const authControllers = require('../controllers/auth.controllers');
6-
7-
router.post('/register', authControllers.postRegisterController);
8-
9-
router.post('/login', authControllers.postLoginController);
10-
11-
router.post('/logout', authControllers.postLogoutController);
12-
13-
router.get('/verify', authControllers.getVerifyController);
14-
15-
router.post('/reset-password-request', authControllers.postFPassReq);
16-
17-
router.post('/reset-password', authControllers.postResetPassword);
18-
19-
module.exports = router;
6+
const authControllers = require("../controllers/auth.controllers");
7+
8+
router.post(
9+
"/register",
10+
[
11+
body("email").isEmail().withMessage("Email must be valid"),
12+
body("password")
13+
.isLength({ min: 6 })
14+
.withMessage("Password must be at least 6 characters long")
15+
.contains("[0-9]")
16+
.withMessage("Password must contain a number")
17+
.contains("[a-z]")
18+
.withMessage("Password must contain a lowercase letter")
19+
.contains("[A-Z]")
20+
.withMessage("Password must contain an uppercase letter")
21+
.contains("[@$!%*#?&]")
22+
.withMessage("Password must contain a special character"),
23+
body("confirmPassword")
24+
.matches(req.body.password)
25+
.withMessage("Passwords must match"),
26+
],
27+
authControllers.postRegisterController
28+
);
29+
30+
router.post(
31+
"/login",
32+
[
33+
body("email").isEmail().withMessage("Email must be valid"),
34+
body("password")
35+
.isLength({ min: 6 })
36+
.withMessage("Password must be at least 6 characters long"),
37+
],
38+
authControllers.postLoginController
39+
);
40+
41+
router.post("/logout", authControllers.postLogoutController);
42+
43+
router.get("/verify", [], authControllers.getVerifyController);
44+
45+
router.post("/reset-password-request", [], authControllers.postFPassReq);
46+
47+
router.post("/reset-password", [], authControllers.postResetPassword);
48+
49+
module.exports = router;

0 commit comments

Comments
 (0)