Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/register', async (req, res) => {
- const newUser = await usersDb();
- // Define the user
- const email = req.body.email;
- const username = req.body.username;
- const password = req.body.password;
- const confirmPassword = req.body.confirmPassword;
- req.check('email', 'Email is required.').notEmpty();
- req.check('email', 'Email provided is not valid.').isEmail();
- req.check('username', 'Username is required.').notEmpty();
- req.check('password', 'Password is required.').notEmpty();
- req.check('confirmPassword', 'Confirm password is required.').notEmpty();
- // Start user already exist check
- let emailCheck = await newUser.findOne({ 'email': email });
- let userNameCheck = await newUser.findOne({ 'username': username});
- req.check('email', 'This email is taken').custom(async value => value === emailCheck.email);
- // Get errors
- let errors = req.validationErrors();
- if (errors) {
- console.log(errors);
- res.render('index', {
- errors: errors
- });
- } else { // If no pre-errors, continue with registration check
- if (!errors) {
- console.log('Run this block if no errors');
- }
- }
- });
Add Comment
Please, Sign In to add comment