Skip to content

Instantly share code, notes, and snippets.

@rlemon

rlemon/server.js Secret

Created March 26, 2014 22:42
Show Gist options
  • Save rlemon/14f98e0121d49c28e3db to your computer and use it in GitHub Desktop.
Save rlemon/14f98e0121d49c28e3db to your computer and use it in GitHub Desktop.
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