Guest User

Untitled

a guest
Feb 3rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. router.post('/register', function(req, res) {
  2. var name = req.body.name;
  3. var email = req.body.email;
  4. var username = req.body.username;
  5. var password = req.body.password;
  6. var password2 = req.body.password2;
  7.  
  8. req.checkBody('username', 'Please enter a username').notEmpty();
  9. req.checkBody('email', 'pls enter a email adress').notEmpty().isEmail();
  10. req.checkBody('password', 'pls enter a password').notEmpty();
  11. req.checkBody('password2', 'the password dont match').equals(req.body.password);
  12.  
  13. var errors = req.validationErrors();
  14.  
  15. if(errors) {
  16. res.render('register',{
  17. errors:errors,
  18. })
  19. } else {
  20. var newUser = new User({
  21. email:email,
  22. username: username,
  23. password: password
  24. });
  25. User.createUser(newUser, function(err, user){
  26. if(err) throw err;
  27. console.log(user);
  28. });
  29.  
  30. req.flash('success_msg', 'u create an accoun, u can log');
  31.  
  32. res.redirect('/users/login');
  33. }
  34. })
Add Comment
Please, Sign In to add comment