Skip to content

Commit

Permalink
initial commit. attempting to use connect-auth...but it doesn't appea…
Browse files Browse the repository at this point in the history
…r to be working
  • Loading branch information
abelmartin committed Sep 17, 2011
0 parents commit 664c1d3
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.DS_Store
*.swp
*.swo
node_modules
conf
70 changes: 70 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Module dependencies.
*/

var express = require('express'),
auth = require('connect-auth'),
twitKey = "809JiWRofheAvdYgO4ACA",
twitSec = "tNe4jr0aCiPRe52QVsVY1IJsZKcesf3ORyabmfQ6Ms";

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.cookieParser());
app.use(express.session({ secret: 'foobar' }));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(auth( [
auth.Twitter({
consumerKey: twitKey,
consumerSecret: twitSec})
]) );
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Connect Auth Protection Method
function protect(req, res, next) {
if( req.isAuthenticated() ){ next(); }
else {
req.authenticate(function(error, authenticated) {
if( error ) next(new Error("Problem authenticating"));
else {
if( authenticated === true)next();
else if( authenticated === false ) next(new Error("Access Denied!"));
else {
// Abort processing, browser interaction was required
// (and has happened/is happening)
}
}
})
}
}

// Routes

app.get('/', function(req, res){
res.render('index', {
title: 'Home'
});
});

app.get('/private', protect, function(req, res){
res.render('private', {title: 'Protected'});
});


app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "2.4.3"
, "jade": ">= 0.0.1"
, "connect-auth": "0.4.1"
}
}
8 changes: 8 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
2 changes: 2 additions & 0 deletions views/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1= title
p Welcome to #{title}
20 changes: 20 additions & 0 deletions views/layout.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
!!!
html
head
title Auth App: #{title}
link(rel='stylesheet', href='/stylesheets/style.css')
body
a#Home(href="/") Home
br
a#Home(href="/private") Private
ul#Authenticate
li
a(href="/sign_in") Sign In
li or
li
a(href="/sign_up") Sign Up
ul#Authed
li Hi Abel!
li
a(href="/sign_out")
!= body
2 changes: 2 additions & 0 deletions views/private.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1 THIS IS A PRIVATE PAGE
p This page should require a login.

0 comments on commit 664c1d3

Please sign in to comment.