Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // have to export everything that we create here so that it's available to the server file
  2. // have to use path because the path is relative to the current directory of routes.js
  3. var path = require('path');
  4.  
  5. module.exports = function (app, passport) {
  6.  
  7. // this is the 'home' page
  8. app.get('/', function (req, res) {
  9. res.sendFile(path.join(__dirname, '../client', '/views/index.html'));
  10. });
  11.  
  12. // this would be the login page
  13. app.get('/login', function (req, res) {
  14. res.sendFile(path.join(__dirname, '../client', '/views/login.html'));
  15. });
  16.  
  17. app.post('/login', passport.authenticate('local', {
  18. successRedirect: '/',
  19. failureRedirect: '/login'
  20. }));
  21.  
  22. // this is the signup form
  23. app.get('/signup', function (req, res) {
  24. res.sendFile(path.join(__dirname, '../client', '/views/signup.html'));
  25. });
  26.  
  27.  
  28.  
  29. // make a profile page
  30. app.get('/profile', function (req, res) {
  31. res.sendFile(path.join(__dirname, '../client', '/views/profile.html'));
  32. });
  33.  
  34. app.get('/logout', function (req, res) {
  35. req.logout();
  36. res.redirect('/');
  37. });
  38.  
  39. // define the is logged in function
  40. function isLoggedIn(req, res, next) {
  41. if (req.isAuthenticated()) return next();
  42.  
  43. res.redirect('/');
  44. }
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement