router.post('/reset/:token', [ check('password').not().isEmpty().isLength({min: 6}).withMessage('Must be at least 6 chars long'), check('confirmPassword', 'Passwords do not match').custom((value, {req}) => (value === req.body.password)), ], validate, Password.resetPassword);
router.post('/register', upload.single('profileimage'), [ check('email', 'Email is not valid').isEmail(), check('username', 'Username field is required').not().isEmpty(), check('password', 'Password field is required').not().isEmpty(), check('password').isLength({ min: 3 }).withMessage('Password must be at least 3 chars long'), check('password').matches(/\d/).withMessage('Password must contain a number'), check('password2').custom((value, {req}) => { //custom validator if(value!==req.body.password) { throw new Error('Passwords doesn\'t match'); } return true; }) ], userController.register);
body('old_password') .exists().withMessage(`Old password is required`) }); }).withMessage(`Old password is incorrect`), body('password', `Password is required`) .exists(), body('password', `Password must be between 6 and 72 characters long and contain at least one number`) .exists() .isLength({ min: 6, max: 72 }) .matches(/\d/), body('password', `New password and current password are identical`) .custom((password, { req }) => password !== req.body.old_password), body('password_confirmation', `Passwords don't match`) .exists() .custom((password_confirmation, { req }) => password_confirmation === req.body.password), validateRequest, ], async (req, res, next) => { try { const status = await userController.changeUserPassword(req.user._id, req.body.password); res.json(status); } catch (err) {
router.post('/manage/registration', [ body('login', 'Login is required') .exists(), body('password', 'Password is required') .exists(), body('login', 'Login must be between 6 and 25 characters long') .exists() .isLength({ min: 6, max: 25 }), body('login', 'Login must contain only letters and numbers') .isAlphanumeric(), body('password', 'Password must be between 6 and 72 characters long and contain one number') .exists() .isLength({ min: 6, max: 72 }) .matches(/\d/), body('repeat', 'Passwords does not match') .exists() .custom((value, { req }) => value === req.body.password) ], async (req, res, next) => { const { login, password } = req.body;
router.post('/signup',[ body('username') .isString().notEmpty() .isLength({min: 3}) .withMessage('Invalid username'), body('email', 'Please enter a valid e-mail!') .isEmail().notEmpty() .custom((value, { req }) => { }) .normalizeEmail(), body('password', 'Please enter a valid password') .isAlphanumeric().notEmpty() .isLength({min: 5}) .trim(), body('confirmPassword') .custom((value, {req}) => { const password = req.body.password; if(value !== password) { throw new Error('Passwords have to match!');