Created
March 26, 2020 04:37
-
-
Save dante-byte/6a14ea84d66c0a9b825a270d489e2ca1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const passport = require('passport'); | |
const userController = require("../controllers/userController"); | |
const { check, validationResult, matchedData } = require("express-validator"); | |
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!icloud.com)(?!outlook.com)(?!protonmail.com)((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ | |
router.get('/client/login', userController.getlogin); | |
router.post('/client/login', | |
[ | |
check("name") | |
.not().isEmpty().withMessage("name required"), | |
check("email").custom(value => { | |
return User.findOne({'email': value}).then(user => { | |
if (user) { | |
return Promise.reject('email in use') | |
} | |
}) | |
}).not().isEmpty().normalizeEmail().matches(regex).withMessage("business email required "), | |
check('username','username required: must match email' ).custom((value, {req}) => (value === req.body.email)), | |
check('password', 'The password must be 5+ chars long and contain a number') | |
.not().isIn(['12345', 'password']).withMessage('password is to simple') | |
.isLength({ min: 5 }) | |
.matches(/\d/), | |
check('password2', 'Passwords do not match').custom((value, {req}) => (value === req.body.password)), | |
], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment