Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed blog, added login.
Added dependence on connect-flash to allow for flash messages.
  • Loading branch information
jimib committed Sep 13, 2012
1 parent 8fe8768 commit a5912d9
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 24 deletions.
10 changes: 0 additions & 10 deletions app/controllers/blog.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/home.js
@@ -1,4 +1,4 @@
module.exports = function(){
module.exports = function(app){
var viewsDir = "home/";

return{
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/login.js
@@ -0,0 +1,23 @@
module.exports = function(app){
var viewsDir = "login/";

return{
loginGET : function(req, res, next){
//display the login form
req.flash('info', "You are logged in");
res.render(viewsDir + "index");
},
loginPOST : function(req, res, next){
//process the login post
res.render(viewsDir + "index");
},
logout : function(req, res, next){
//logout
res.render(viewsDir + "index");
},
getUser : function(req, res, next){
//load the user for the current session

}
}
}
6 changes: 3 additions & 3 deletions app/libs/routes.js
Expand Up @@ -6,9 +6,9 @@ module.exports = function(app){
app.routes = chauffeur(app, function(map){
map.get("/", app.controllers.home.index, "index");
//namespace
map.resource("blog", app.controllers.blog, function(map){
});
map.get("/login", app.controllers.login.loginGET, "loginGET");
map.post("/login", app.controllers.login.loginPOST, "loginPOST");
map.get("/logout", app.controllers.login.logout, "logout");
});

console.log(util.inspect(app.routes));
Expand Down
29 changes: 19 additions & 10 deletions app/middleware/environment.js
@@ -1,15 +1,24 @@
var flash = require("connect-flash");
var express = require("express");

module.exports = function(app){
app.use(app.router);
app.use(express.static(__dirname + '/../public'));
app.use(express.errorHandler());
app.configure(function(){
//enable our view engine
app.set('views', __dirname + '/../views');
app.set('view engine', 'jade');

app.use(express.cookieParser('keyboard cat'));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.use(flash());

app.use(function(req, res, next) {
res.locals.flash = function() { return req.flash() };
next();
});

app.use(app.router);
app.use(express.static(__dirname + '/../public'));
app.use(express.errorHandler());
});

// Optional since express defaults to CWD/views
app.set('views', __dirname + '/../views');

// Set our default template engine to "jade"
// which prevents the need for extensions
// (although you can still mix and match)
app.set('view engine', 'jade');
}
12 changes: 12 additions & 0 deletions app/views/_layout.jade
@@ -0,0 +1,12 @@
html
head
block head
body
- msg = flash();
if(msg)
if(msg.error)
p.error= msg.error
if(msg.info)
p.info= msg.info
h1 Title
block body
6 changes: 6 additions & 0 deletions app/views/login/index.jade
@@ -0,0 +1,6 @@
extends ../_layout

block head

block body
p Hello World
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -7,6 +7,7 @@
},
"dependencies": {
"express": "3.0.0rc4",
"connect-flash" : "latest",
"jade": "*",
"chauffeur" : "git://github.com/jimib/nodejs-chauffeur.git#master",
"earlybird" : "git://github.com/jimib/nodejs-earlybird.git#master",
Expand Down

0 comments on commit a5912d9

Please sign in to comment.