-
-
Save rlemon/a2fa12bfd550ef5a0e7b 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(); | |
require('modules/authentication'); | |
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.use(passport.initialize()); | |
app.use(passport.session()); | |
app.use(app.router); | |
}); | |
app.get('/', function(req,res) { | |
if( !req.user ) { | |
res.redirect('/login'); | |
} | |
res.sendFile(__dirname + '/views/dashboard.html'); | |
}); | |
app.get('/login', function(req,res) { | |
if( req.user ) { | |
res.redirect('/'); | |
} | |
res.sendFile(__dirname + '/views/login.html'); | |
}); | |
app.post('/login', passport.authenticate('local', { failureRedirect: '/login?failed=true' }, function(req, res) { | |
res.redirect('/'); | |
}); | |
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