Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1.  
  2. // routes/auth.js
  3.  
  4. router.post('/',
  5. passport.authenticate('local'),
  6. authController.postLogin
  7. );
  8.  
  9. // providers/auth.js
  10.  
  11. passport.use(new LocalStrategy(
  12. function(username, password, done)
  13. if (password == false) {
  14. const newUser = new User();
  15. newUser.name= username;
  16. newUser.icon = "some random";
  17. // other random attributes
  18. newUser.save();
  19. }
  20.  
  21. User.findOne({ username: username }, function (err, user) {
  22. if (err) { return done(err); }
  23.  
  24. // if password is set, check if the credentials match
  25. if (!user) {
  26. return done(null, false, { message: 'Incorrect username' });
  27. }
  28.  
  29. if (!User.hashCompare(password, user.password))
  30. return done(null, false, { message: 'Incorrent password' });
  31.  
  32.  
  33. return done(null, user);
  34. });
  35. }
  36. ));
  37.  
  38. // controllers/auth.js
  39.  
  40. exports.postLogin = (req, res, next) => {
  41. // user is logged in
  42. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement