Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. passport.use(new LocalStrategy(
  2. function(username, password, done) {
  3.  
  4. console.log(username + "----" + password)
  5.  
  6. if(username == "test" && password == "test"){
  7. console.log("SUCCESS")
  8. done(null, { name: username})
  9. }
  10. else{
  11. done(null, false)
  12. }
  13. }))
  14.  
  15. .. some othe initialization, cookieparser, bodyparser, session ...
  16. app.use(passport.initialize())
  17. app.use(passport.session())
  18.  
  19. app.use('/login', login);
  20.  
  21.  
  22. app.post('/login',passport.authenticate('local', { failureRedirect: '/login' }),
  23. function(req, res) {
  24. res.redirect('/plans');
  25. });
  26.  
  27. app.all('*',function (req, res, next) {
  28.  
  29. console.log(req.isAuthenticated())
  30. if (req.isAuthenticated()) {
  31. return next()
  32. }
  33. res.redirect('/login')
  34. })
  35.  
  36. app.use('/', index);
  37. app.use('/users', users);
  38. app.use('/plans', plans);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement