Permalink
Browse files

initial commit. attempting to use connect-auth...but it doesn't appea…

…r to be working
  • Loading branch information...
abelmartin committed Sep 17, 2011
0 parents commit 664c1d318e66fcd8e8b448bae02e46f539ecde53
Showing with 117 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +70 −0 app.js
  3. +10 −0 package.json
  4. +8 −0 public/stylesheets/style.css
  5. +2 −0 views/index.jade
  6. +20 −0 views/layout.jade
  7. +2 −0 views/private.jade
@@ -0,0 +1,5 @@
+*.DS_Store
+*.swp
+*.swo
+node_modules
+conf
70 app.js
@@ -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);
@@ -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"
+ }
+}
@@ -0,0 +1,8 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+}
@@ -0,0 +1,2 @@
+h1= title
+p Welcome to #{title}
@@ -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
@@ -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.