Advertisement
Guest User

Untitled

a guest
Mar 5th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. router.post('/register', function(req, res){
  2. var email = req.body.email;
  3. var username = req.body.username;
  4. var password = req.body.password;
  5. var password2 = req.body.password2;
  6.  
  7. // Validation
  8. req.checkBody('email', 'Email jest wymagany!').notEmpty();
  9. req.checkBody('email', 'Niepoprawny email!').isEmail();
  10. req.checkBody('username', 'Login jest wymagany!').notEmpty();
  11. req.checkBody('password', 'Hasło jest wymagane!').notEmpty();
  12. req.checkBody('password2', 'Hasła muszą być takie same!').equals(req.body.password);
  13.  
  14. var errors = req.validationErrors();
  15.  
  16. if(errors){
  17. res.render('register',{
  18. errors:errors
  19. });
  20. } else {
  21. if(await User.findOne({email}) !== null) {
  22. res.render('register', {
  23. exist: 'Taki email lub login istnieje już w bazie!'
  24. });
  25. } else {
  26. var newUser = new User({
  27. email:email,
  28. username: username,
  29. password: password
  30. });
  31.  
  32. User.createUser(newUser, function(err, user){
  33. if(err) throw err;
  34. console.log(user);
  35. });
  36.  
  37. req.flash('success_msg', 'Konto założone pomyślnie! Teraz możesz się zalogować');
  38.  
  39. res.redirect('/users/login');
  40. }
  41.  
  42. }
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement