-
-
Save rlemon/14f98e0121d49c28e3db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
passport = require('passport'); | |
var PORT = 3000; | |
var app = express(); | |
app.configure(function() { | |
app.use(express.static(__dirname + '/public')); | |
app.use(express.cookieParser()); | |
app.use(express.bodyParser()); | |
app.use(express.session({ secret: 'shhh it is a secret' })); | |
app.set('view engine', 'ejs'); | |
app.use(passport.initialize()); | |
app.use(passport.session()); | |
app.use(app.router); | |
}); | |
// sets up the authentication Strategy | |
require('./modules/authentication'); | |
app.get('/', function(req,res) { | |
if( !req.user ) { | |
res.redirect('/login'); | |
} | |
res.render('dashboard.ejs', {}); | |
}); | |
app.get('/login', function(req,res) { | |
if( req.user ) { | |
res.redirect('/'); | |
} | |
res.render('login.ejs', {}); | |
}); | |
app.post('/login', passport.authenticate('local', { failureRedirect: '/login' }), function(req, res) { | |
res.redirect('/'); | |
}); | |
app.get('/logout', function(req, res) { | |
req.logout(); | |
res.redirect('/login'); | |
}); | |
app.listen(PORT); | |
console.log("server started and listening on port " + PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment