daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Oct 20th, 2018 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.post('/register', upload.single('profileImage'), function(req, res, next) {
  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 conPassword = req.body.conPassword;
  7.  
  8. if(req.file) {
  9.     console.log('Uploading file...');
  10.     var profileImage = req.file.filename;
  11. } else {
  12.     console.log('No file uploaded...');
  13.     var profileImage = 'noImage.jpg';
  14. }
  15.  
  16. // Form validations
  17. req.checkBody('name', 'Name field is required').notEmpty();
  18. req.checkBody('email', 'Email field is required').notEmpty();
  19. req.checkBody('email', 'Email is not valid').isEmail();
  20. req.checkBody('username', 'Username field is required').notEmpty();
  21. req.checkBody('password', 'password field is required').notEmpty();
  22. req.checkBody('conPassword', 'Passwords do not match').equals(req.body.password);
  23.  
  24. //Check for errors
  25. var errors = req.validationErrors();
  26.  
  27. if(errors){
  28.     res.render('register', {
  29.         errors: errors
  30.     });
  31. } else {
  32.     newUser = new user({
  33.         name: name,
  34.         email: email,
  35.         username: username,
  36.         password: password,
  37.         profileImage: profileImage
  38.     });
  39.  
  40.     user.createUser(newUser, function(err, user){
  41.         if(err) throw err;
  42.         console.log(user);
  43.     });
  44.  
  45.     req.flash('success', 'You are now registered and can login');
  46.  
  47.     res.location('/');
  48.     res.redirect('/');
  49. }
  50.    
  51. router.post('/login', passport.authenticate('local', {failureRedirect: '/users/login', failureFlash: 'Invalid username or password'}), function(req, res) {
  52.     req.flash('success', 'You are now logged in');
  53.     //res.redirect('/users/' + req.user.username);
  54.     res.redirect('/');
  55. });
  56.    
  57. .container
  58.         != messages()
  59.         block content
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top