Skip to content

Commit

Permalink
Added login middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiran Ryali committed Feb 25, 2011
1 parent 08f7534 commit b893cec
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app.js
Expand Up @@ -2,13 +2,14 @@
/**
* Module dependencies.
*/

fs = require('fs');
io = require('socket.io');
express = require('express');
app = express.createServer();
RedisStore = require('connect-redis');

// Global Helpers
require('./globalfn.js');

// Configuration
require('./config');
Expand Down
2 changes: 1 addition & 1 deletion config/init.js
@@ -1,4 +1,4 @@
//client = app.client = require("redis").createClient();
client = app.client = require("redis").createClient();
questions = app.questions = [];

var time = new Date();
Expand Down
Empty file added globalfn.js
Empty file.
Binary file added routes/.question.js.swp
Binary file not shown.
14 changes: 11 additions & 3 deletions routes/question.js
@@ -1,5 +1,13 @@
// Routes
app.get('/', function(req, res){
function isLoggedIn(req, res, next){
if ( true ){
next();
} else {
next(new Error("Please login to do that"));
}
}

// Routes
app.get('/', isLoggedIn, function(req, res){
time = new Date();
res.render('index', {
locals: {
Expand All @@ -9,7 +17,7 @@
});
});

app.post('/ask', function(req, res, next){
app.post('/ask', isLoggedIn, function(req, res, next){
time = new Date();
var newQuestion = {title: 'test', time: time.getTime(), vote:1};
questions.push(newQuestion);
Expand Down
5 changes: 2 additions & 3 deletions test/app.test.js
Expand Up @@ -5,8 +5,7 @@
* Module dependencies.
*/

var app = require('../app')
, assert = require('assert');
var app = require('../app') , assert = require('assert');


module.exports = {
Expand All @@ -18,4 +17,4 @@ module.exports = {
assert.includes(res.body, '<title>Express</title>');
});
}
};
};
4 changes: 4 additions & 0 deletions views/login.jade
@@ -0,0 +1,4 @@
form( action:'/login' method:'post' )
input( type: 'text', name:'username', value:'Your username')
input( type: 'text', name:'password', value:'Your password')
input( type: 'submit', value: 'login')

0 comments on commit b893cec

Please sign in to comment.