Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Upgraded express to 3.x

  • Loading branch information...
commit 37986074d43d2194f8e6c5f3234e9a7f1c88ede4 1 parent fd422ff
Mike Valstar authored September 30, 2012
24  addUser.js
@@ -16,17 +16,17 @@ var db = new Database();
16 16
 db.connect('mongodb://localhost/mv');
17 17
 
18 18
 if(process.argv.length == 4){
19  
-	// 0 will be node, 1 will be the script
20  
-	
21  
-	var au = db.model('adminUser');
22  
-	var usr = new au({login: process.argv[2], password: hashString(process.argv[3]) });
23  
-	usr.save(function(err){
24  
-		console.log("User added to database");
25  
-		process.exit(0); // Success
26  
-	});
27  
-	
  19
+    // 0 will be node, 1 will be the script
  20
+    
  21
+    var au = db.model('adminUser');
  22
+    var usr = new au({login: process.argv[2], password: hashString(process.argv[3]) });
  23
+    usr.save(function(err){
  24
+        console.log("User added to database");
  25
+        process.exit(0); // Success
  26
+    });
  27
+    
28 28
 }else{
29  
-	console.error("Script requires exactly 2 arguments");
30  
-	console.error("Usage: node addUser.js <email> <password>");
31  
-	process.exit(1); // Failure
  29
+    console.error("Script requires exactly 2 arguments");
  30
+    console.error("Usage: node addUser.js <email> <password>");
  31
+    process.exit(1); // Failure
32 32
 }
55  app.js
@@ -3,26 +3,29 @@
3 3
  */
4 4
 process.env.TZ = 'GMT';
5 5
 var   express = require('express')
6  
-	, mongoStore = require('session-mongoose');
7  
-	
8  
-var app = module.exports = express.createServer();
  6
+    , http = require('http')
  7
+    , path = require('path')
  8
+    , mongoStore = require('session-mongoose');
  9
+    
  10
+var app = express();
9 11
 
10 12
 // Configuration
11 13
 app.configure(function(){
12  
-	app.set('views', __dirname + '/views');
13  
-	app.set('view engine', 'jade');
14  
-	app.use(express.bodyParser());
15  
-	app.use(express.methodOverride());
16  
-	app.use(express.cookieParser());
17  
-	
18  
-	var mongooseSessionStore = new mongoStore({
19  
-	    url: "mongodb://localhost/mv",
20  
-	    interval: 1200000
21  
-	});
22  
-	
23  
-	app.use(express.session( {cookie: {maxAge: 1200000}, store: mongooseSessionStore, secret: "mv secret" }));
24  
-	app.use(app.router);
25  
-	app.use(express.static(__dirname + '/htdocs'));
  14
+    app.set('views', __dirname + '/views');
  15
+    app.set('view engine', 'jade');
  16
+    app.use(express.bodyParser());
  17
+    app.use(express.methodOverride());
  18
+    app.use(express.cookieParser());
  19
+    app.use(require('less-middleware')({ src: __dirname + '/htdocs' }));
  20
+    
  21
+    var mongooseSessionStore = new mongoStore({
  22
+        url: "mongodb://localhost/mv",
  23
+        interval: 1200000
  24
+    });
  25
+    
  26
+    app.use(express.session( {cookie: {maxAge: 1200000}, store: mongooseSessionStore, secret: "mv secret" }));
  27
+    app.use(app.router);
  28
+    app.use(express.static(path.join(__dirname, 'htdocs')));
26 29
 });
27 30
 
28 31
 // Error Handling
@@ -30,12 +33,15 @@ var error = require('./lib/ErrorHandler');
30 33
 
31 34
 app.configure('development', function(){
32 35
   //app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
33  
-	app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
  36
+    app.set('port', process.env.PORT || 3000);
  37
+    app.use(express.logger('dev'));
  38
+    app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
34 39
 });
35 40
 
36 41
 app.configure('production', function(){
37 42
   //app.use(express.errorHandler()); 
38  
-	app.use(error());
  43
+  app.set('port', process.env.PORT || 80);
  44
+  app.use(error());
39 45
 });
40 46
 
41 47
 // Database
@@ -58,18 +64,19 @@ pp.initPages(app, db);
58 64
 
59 65
 // 404 Page
60 66
 app.use(function(req, res, next){
61  
-	res.render('404.jade', {title: "404 - Page Not Found", showFullNav: false, status: 404, url: req.url });
  67
+    res.render('404.jade', {title: "404 - Page Not Found", showFullNav: false, status: 404, url: req.url });
62 68
 });
63 69
 
64 70
 // Example error pages
65 71
 app.get('/ErrorExample', function(req, res, next){
66  
-	next(new Error('keyboard cat!')); // trigger an error
  72
+    next(new Error('keyboard cat!')); // trigger an error
67 73
 });
68 74
 
69 75
 app.get('/ErrorExample2', function(req, res){
70  
-	res.render('404.jade'); // force an error.. we did not set the title
  76
+    res.render('404.jade'); // force an error.. we did not set the title
71 77
 });
72 78
 
73 79
 
74  
-app.listen(3000);
75  
-console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
  80
+http.createServer(app).listen(app.get('port'), function(){
  81
+  console.log("Express server listening on port %d in %s mode.\n", app.get('port'), app.settings.env);
  82
+});
456  lib/AdminPages.js
@@ -11,234 +11,234 @@ var AdminPages = module.exports = function AdminPages(){};
11 11
 
12 12
 AdminPages.prototype = {
13 13
 
14  
-	  db: null
  14
+      db: null
15 15
 
16  
-	, initPages: function(app, db){
17  
-	
18  
-		this.db = db;
19  
-		var self = this;
20  
-		
21  
-		// login related
22  
-		app.get ('/Admin/Login', function(req, res) { self.pageLogin(req, res); } );
23  
-		app.post('/Admin/Login', function(req, res) { self.pageLoginPost(req, res); }  );
24  
-		app.get ('/Admin/Logout', function(req, res) { self.pageLogout(req, res); }  );
25  
-		
26  
-		// post related
27  
-		app.get ('/Admin/PostList', function(req, res) { self.pagePostList(req, res); }  );
28  
-		app.get ('/Admin/NewPost', function(req, res) { self.pagePost(req, res); }  );
29  
-		app.post('/Admin/Post', function(req, res) { self.pagePostPost(req, res); }  );
30  
-		app.get ('/Admin/Post/:id', function(req, res) { self.pagePost(req, res); }  );
31  
-		
32  
-		// misc.
33  
-		app.get ('/Admin', function(req, res) { self.pageIndex(req, res); } );
34  
-	}
35  
-	
36  
-	, _checkLogin: function(req, res){
37  
-		if(req.session && req.session.loggedIn === true)
38  
-			return true;
  16
+    , initPages: function(app, db){
  17
+    
  18
+        this.db = db;
  19
+        var self = this;
  20
+        
  21
+        // login related
  22
+        app.get ('/Admin/Login', function(req, res) { self.pageLogin(req, res); } );
  23
+        app.post('/Admin/Login', function(req, res) { self.pageLoginPost(req, res); }  );
  24
+        app.get ('/Admin/Logout', function(req, res) { self.pageLogout(req, res); }  );
  25
+        
  26
+        // post related
  27
+        app.get ('/Admin/PostList', function(req, res) { self.pagePostList(req, res); }  );
  28
+        app.get ('/Admin/NewPost', function(req, res) { self.pagePost(req, res); }  );
  29
+        app.post('/Admin/Post', function(req, res) { self.pagePostPost(req, res); }  );
  30
+        app.get ('/Admin/Post/:id', function(req, res) { self.pagePost(req, res); }  );
  31
+        
  32
+        // misc.
  33
+        app.get ('/Admin', function(req, res) { self.pageIndex(req, res); } );
  34
+    }
  35
+    
  36
+    , _checkLogin: function(req, res){
  37
+        if(req.session && req.session.loggedIn === true)
  38
+            return true;
39 39
 
40  
-		res.redirect('/Admin/Login');
41  
-		return false;
42  
-	}
43  
-	
44  
-	, pageLogin: function(req, res){
45  
-		res.render('admin/login', {
46  
-			title: 'Login',
47  
-			showFullNav: false
48  
-		});
49  
-	} 
50  
-	
51  
-	, pageLogout: function(req, res){
52  
-		delete req.session.loggedIn;
53  
-		res.redirect('/Admin/Login');
54  
-	}
55  
-	
56  
-	, pageLoginPost: function(req, res){
57  
-		if(req.body && req.body.password && req.body.email){
58  
-			var adminuser = this.db.model('adminUser');
59  
-			adminuser.findOne(
60  
-				  {	  login: 		req.body.email 
61  
-					, password: 	hashString(req.body.password) }
62  
-				, function(err, row){
63  
-				
64  
-				if(err){
65  
-					res.render('admin/login', {
66  
-						title: 'Login',
67  
-						showFullNav: false,
68  
-						error_text: err
69  
-					});			
70  
-				}else{
71  
-					if(row){
72  
-						req.session.loggedIn = true; // register user is logged in
73  
-						res.redirect('/Admin');
74  
-					}else{
75  
-						res.render('admin/login', {
76  
-							title: 'Login',
77  
-							showFullNav: false,
78  
-							error_text: 'User not found, Please try again',
79  
-							email: req.body.email
80  
-						});	
81  
-					}
82  
-				}
83  
-			});
84  
-		}else{
85  
-			res.render('admin/login', {
86  
-				title: 'Login',
87  
-				showFullNav: false,
88  
-				error_text: 'Error processing login.'
89  
-			});	
90  
-		}
91  
-	}
92  
-	
93  
-	, pageIndex: function(req, res){
94  
-		if( !this._checkLogin(req, res) ) return;
95  
-		
96  
-		res.render('admin/index', {
97  
-			title: 'Admin Index',
98  
-			showFullNav: false
99  
-		});
100  
-	}
101  
-	
102  
-	/* Blog post related */
103  
-	, pagePostList: function(req, res){ // List of blog posts
104  
-		if( !this._checkLogin(req, res) ) return;
105  
-		
106  
-		var blogpost = this.db.model('blogPost');
107  
-		
108  
-		var query = blogpost.find().sort("posted", -1).limit(1000).exec(function(err, docs){
109  
-			res.render('admin/postlist', {
110  
-				title: 'Post Listing',
111  
-				posts: docs,
112  
-				showFullNav: false
113  
-			});
114  
-		});
115  
-	}
116  
-	
117  
-	, pagePost: function(req, res){ // Edit/New Page
118  
-		if( !this._checkLogin(req, res) ) return;
119  
-		
120  
-		if(req.params.id){ // Old Post
121  
-		
122  
-			var blogpost = this.db.model('blogPost');
123  
-			blogpost.findOne({sid: req.params.id}, function(err, row){
124  
-				if(!row){
125  
-					res.redirect('/Admin/NewPost');
126  
-					return;
127  
-				}
128  
-				
129  
-				res.render('admin/post', {
130  
-					title: req.params.id + ' - ' + row.title,
131  
-					post: row,
132  
-					showFullNav: false
133  
-				});
134  
-			});
135  
-		
136  
-		}else{ // New Post
137  
-			var newid = 1;
138  
-			var blogpost = this.db.model('blogPost');
139  
-			blogpost.find().sort("sid", -1).limit(1).exec(function(err, doc){
140  
-				if(err)
141  
-					console.info(err);
142  
-					
143  
-				if(!doc || doc.length == 0){
144  
-					newid = 1;
145  
-				}else{
146  
-					newid = doc[0].sid + 1;
147  
-				}
148  
-		
149  
-				res.render('admin/post', {
150  
-					title: 'New Blog Post',
151  
-					post: {	id		: "",
152  
-							sid		: newid,
153  
-							author	: "mikevalstar@gmail.com",
154  
-							title	: "",
155  
-							img_lg	: "",
156  
-							img_sm	: "",
157  
-							content	: "",
158  
-							short	: "",
159  
-							group	: "",
160  
-							ext_link: "",
161  
-							posted	: "",
162  
-							edited	: "",
163  
-						},
164  
-					showFullNav: false
165  
-				});
166  
-			});
167  
-		}
168  
-	}
169  
-	
170  
-	, pagePostPost: function(req, res){
171  
-		if( !this._checkLogin(req, res) ) return;
172  
-		
173  
-		if(req.body.id && req.body.id != ""){
174  
-			// old page
175  
-			var blogpost = this.db.model('blogPost');
176  
-			
177  
-			blogpost.update(
178  
-				{_id: req.body.id},
179  
-				{
180  
-					sid		: req.body.sid,
181  
-					title	: req.body.title,
182  
-					img_lg	: req.body.img_lg,
183  
-					img_sm	: req.body.img_sm,
184  
-					content	: req.body.content,
185  
-					short	: req.body.short,
186  
-					group	: req.body.group,
187  
-					ext_link: req.body.ext_link,
188  
-				},
189  
-				{ multi: false },
190  
-				function(err, numrows){
191  
-					if(err){
192  
-						console.log(err);
193  
-					}else{
194  
-						console.log("Updated ("+numrows+") blog post(s) at internal id: " + req.body.id);
195  
-					}
196  
-					
197  
-					res.redirect('/Admin/Post/' + req.body.sid);
198  
-				});
199  
-			
200  
-		}else{
201  
-			// new page
202  
-			var blogpost = this.db.model('blogPost');
203  
-			
204  
-			// max id + 1
205  
-			var newid = 1;
206  
-			blogpost.find().sort("sid", -1).limit(1).exec(function(err, doc){
207  
-				if(err)
208  
-					console.info(err);
209  
-					
210  
-				if(!doc || doc.length == 0){
211  
-					newid = 1;
212  
-				}else{
213  
-					newid = doc[0].sid + 1;
214  
-				}
215  
-				
216  
-				// new blog post
217  
-				var post = new blogpost({
218  
-					sid		: req.body.sid == "" ? parseInt(newid) : req.body.sid,
219  
-					author	: "mikevalstar@gmail.com",
220  
-					title	: req.body.title,
221  
-					img_lg	: req.body.img_lg,
222  
-					img_sm	: req.body.img_sm,
223  
-					content	: req.body.content,
224  
-					short	: req.body.short,
225  
-					group	: req.body.group,
226  
-					ext_link: req.body.ext_link,
227  
-				});
228  
-				
229  
-				post.save(function(err){
230  
-					if(err){
231  
-						console.log(err);
232  
-					}else{
233  
-						console.log("Inserted new blog post at sid: " + post.sid + " at internal id: " + post.id);
234  
-					}
235  
-					
236  
-					res.redirect('/Admin/Post/' + post.sid);
237  
-				});
238  
-				
239  
-			});
240  
-			
241  
-		}
242  
-	}
243  
-	
  40
+        res.redirect('/Admin/Login');
  41
+        return false;
  42
+    }
  43
+    
  44
+    , pageLogin: function(req, res){
  45
+        res.render('admin/login', {
  46
+            title: 'Login',
  47
+            showFullNav: false
  48
+        });
  49
+    } 
  50
+    
  51
+    , pageLogout: function(req, res){
  52
+        delete req.session.loggedIn;
  53
+        res.redirect('/Admin/Login');
  54
+    }
  55
+    
  56
+    , pageLoginPost: function(req, res){
  57
+        if(req.body && req.body.password && req.body.email){
  58
+            var adminuser = this.db.model('adminUser');
  59
+            adminuser.findOne(
  60
+                  {      login:         req.body.email 
  61
+                    , password:     hashString(req.body.password) }
  62
+                , function(err, row){
  63
+                
  64
+                if(err){
  65
+                    res.render('admin/login', {
  66
+                        title: 'Login',
  67
+                        showFullNav: false,
  68
+                        error_text: err
  69
+                    });            
  70
+                }else{
  71
+                    if(row){
  72
+                        req.session.loggedIn = true; // register user is logged in
  73
+                        res.redirect('/Admin');
  74
+                    }else{
  75
+                        res.render('admin/login', {
  76
+                            title: 'Login',
  77
+                            showFullNav: false,
  78
+                            error_text: 'User not found, Please try again',
  79
+                            email: req.body.email
  80
+                        });    
  81
+                    }
  82
+                }
  83
+            });
  84
+        }else{
  85
+            res.render('admin/login', {
  86
+                title: 'Login',
  87
+                showFullNav: false,
  88
+                error_text: 'Error processing login.'
  89
+            });    
  90
+        }
  91
+    }
  92
+    
  93
+    , pageIndex: function(req, res){
  94
+        if( !this._checkLogin(req, res) ) return;
  95
+        
  96
+        res.render('admin/index', {
  97
+            title: 'Admin Index',
  98
+            showFullNav: false
  99
+        });
  100
+    }
  101
+    
  102
+    /* Blog post related */
  103
+    , pagePostList: function(req, res){ // List of blog posts
  104
+        if( !this._checkLogin(req, res) ) return;
  105
+        
  106
+        var blogpost = this.db.model('blogPost');
  107
+        
  108
+        var query = blogpost.find().sort("posted", -1).limit(1000).exec(function(err, docs){
  109
+            res.render('admin/postlist', {
  110
+                title: 'Post Listing',
  111
+                posts: docs,
  112
+                showFullNav: false
  113
+            });
  114
+        });
  115
+    }
  116
+    
  117
+    , pagePost: function(req, res){ // Edit/New Page
  118
+        if( !this._checkLogin(req, res) ) return;
  119
+        
  120
+        if(req.params.id){ // Old Post
  121
+        
  122
+            var blogpost = this.db.model('blogPost');
  123
+            blogpost.findOne({sid: req.params.id}, function(err, row){
  124
+                if(!row){
  125
+                    res.redirect('/Admin/NewPost');
  126
+                    return;
  127
+                }
  128
+                
  129
+                res.render('admin/post', {
  130
+                    title: req.params.id + ' - ' + row.title,
  131
+                    post: row,
  132
+                    showFullNav: false
  133
+                });
  134
+            });
  135
+        
  136
+        }else{ // New Post
  137
+            var newid = 1;
  138
+            var blogpost = this.db.model('blogPost');
  139
+            blogpost.find().sort("sid", -1).limit(1).exec(function(err, doc){
  140
+                if(err)
  141
+                    console.info(err);
  142
+                    
  143
+                if(!doc || doc.length == 0){
  144
+                    newid = 1;
  145
+                }else{
  146
+                    newid = doc[0].sid + 1;
  147
+                }
  148
+        
  149
+                res.render('admin/post', {
  150
+                    title: 'New Blog Post',
  151
+                    post: {    id        : "",
  152
+                            sid        : newid,
  153
+                            author    : "mikevalstar@gmail.com",
  154
+                            title    : "",
  155
+                            img_lg    : "",
  156
+                            img_sm    : "",
  157
+                            content    : "",
  158
+                            short    : "",
  159
+                            group    : "",
  160
+                            ext_link: "",
  161
+                            posted    : "",
  162
+                            edited    : "",
  163
+                        },
  164
+                    showFullNav: false
  165
+                });
  166
+            });
  167
+        }
  168
+    }
  169
+    
  170
+    , pagePostPost: function(req, res){
  171
+        if( !this._checkLogin(req, res) ) return;
  172
+        
  173
+        if(req.body.id && req.body.id != ""){
  174
+            // old page
  175
+            var blogpost = this.db.model('blogPost');
  176
+            
  177
+            blogpost.update(
  178
+                {_id: req.body.id},
  179
+                {
  180
+                    sid        : req.body.sid,
  181
+                    title    : req.body.title,
  182
+                    img_lg    : req.body.img_lg,
  183
+                    img_sm    : req.body.img_sm,
  184
+                    content    : req.body.content,
  185
+                    short    : req.body.short,
  186
+                    group    : req.body.group,
  187
+                    ext_link: req.body.ext_link,
  188
+                },
  189
+                { multi: false },
  190
+                function(err, numrows){
  191
+                    if(err){
  192
+                        console.log(err);
  193
+                    }else{
  194
+                        console.log("Updated ("+numrows+") blog post(s) at internal id: " + req.body.id);
  195
+                    }
  196
+                    
  197
+                    res.redirect('/Admin/Post/' + req.body.sid);
  198
+                });
  199
+            
  200
+        }else{
  201
+            // new page
  202
+            var blogpost = this.db.model('blogPost');
  203
+            
  204
+            // max id + 1
  205
+            var newid = 1;
  206
+            blogpost.find().sort("sid", -1).limit(1).exec(function(err, doc){
  207
+                if(err)
  208
+                    console.info(err);
  209
+                    
  210
+                if(!doc || doc.length == 0){
  211
+                    newid = 1;
  212
+                }else{
  213
+                    newid = doc[0].sid + 1;
  214
+                }
  215
+                
  216
+                // new blog post
  217
+                var post = new blogpost({
  218
+                    sid        : req.body.sid == "" ? parseInt(newid) : req.body.sid,
  219
+                    author    : "mikevalstar@gmail.com",
  220
+                    title    : req.body.title,
  221
+                    img_lg    : req.body.img_lg,
  222
+                    img_sm    : req.body.img_sm,
  223
+                    content    : req.body.content,
  224
+                    short    : req.body.short,
  225
+                    group    : req.body.group,
  226
+                    ext_link: req.body.ext_link,
  227
+                });
  228
+                
  229
+                post.save(function(err){
  230
+                    if(err){
  231
+                        console.log(err);
  232
+                    }else{
  233
+                        console.log("Inserted new blog post at sid: " + post.sid + " at internal id: " + post.id);
  234
+                    }
  235
+                    
  236
+                    res.redirect('/Admin/Post/' + post.sid);
  237
+                });
  238
+                
  239
+            });
  240
+            
  241
+        }
  242
+    }
  243
+    
244 244
 };
88  lib/Database.js
@@ -5,49 +5,49 @@ var Schema = mongoose.Schema
5 5
 var Database = module.exports = function Database(){};
6 6
 
7 7
 Database.prototype = {
8  
-	
9  
-	  _collections: {
10  
-	  	adminUser: {
11  
-			  login		: String
12  
-			, password	: String
13  
-		},
14  
-		blogPost:{
15  
-			sid		: { type: Number, required: true, unique: true, index: true },
16  
-			author	: { type: String },
17  
-			title	: { type: String },
18  
-			img_lg	: { type: String },
19  
-			img_sm	: { type: String },
20  
-			content	: { type: String },
21  
-			short	: { type: String },
22  
-			group	: { type: String },
23  
-			ext_link: { type: String },
24  
-			posted	: { type: Date, index: true, default: Date.now },
25  
-			edited	: { type: Date, default: Date.now },
26  
-		},
27  
-	}
28  
-	
29  
-	, _db: null
30  
-	, _schema: {}
31  
-	, _model: {}
32  
-	
33  
-	, connect: function(url){
34  
-		mongoose.connect(url);
35  
-		
36  
-		this._schema.adminUser = new Schema(this._collections.adminUser);
37  
-		this._model.adminUser = mongoose.model('adminUser', this._schema.adminUser);
38  
-		
39  
-		this._schema.blogPost = new Schema(this._collections.blogPost);
40  
-		this._model.blogPost = mongoose.model('blogPost', this._schema.blogPost);
41  
-		
42  
-	}
43  
-	
44  
-	, model: function(mod){	
45  
-		switch (mod){
46  
-			case 'adminUser':
47  
-				return this._model.adminUser;
48  
-			case 'blogPost':
49  
-				return this._model.blogPost;
50  
-		}
51  
-	}
  8
+    
  9
+      _collections: {
  10
+          adminUser: {
  11
+              login        : String
  12
+            , password    : String
  13
+        },
  14
+        blogPost:{
  15
+            sid        : { type: Number, required: true, unique: true, index: true },
  16
+            author    : { type: String },
  17
+            title    : { type: String },
  18
+            img_lg    : { type: String },
  19
+            img_sm    : { type: String },
  20
+            content    : { type: String },
  21
+            short    : { type: String },
  22
+            group    : { type: String },
  23
+            ext_link: { type: String },
  24
+            posted    : { type: Date, index: true, default: Date.now },
  25
+            edited    : { type: Date, default: Date.now },
  26
+        },
  27
+    }
  28
+    
  29
+    , _db: null
  30
+    , _schema: {}
  31
+    , _model: {}
  32
+    
  33
+    , connect: function(url){
  34
+        mongoose.connect(url);
  35
+        
  36
+        this._schema.adminUser = new Schema(this._collections.adminUser);
  37
+        this._model.adminUser = mongoose.model('adminUser', this._schema.adminUser);
  38
+        
  39
+        this._schema.blogPost = new Schema(this._collections.blogPost);
  40
+        this._model.blogPost = mongoose.model('blogPost', this._schema.blogPost);
  41
+        
  42
+    }
  43
+    
  44
+    , model: function(mod){    
  45
+        switch (mod){
  46
+            case 'adminUser':
  47
+                return this._model.adminUser;
  48
+            case 'blogPost':
  49
+                return this._model.blogPost;
  50
+        }
  51
+    }
52 52
 
53 53
 };
110  lib/ErrorHandler.js
@@ -30,63 +30,63 @@
30 30
 var fs = require('fs');
31 31
 
32 32
 exports = module.exports = function errorHandler(options){
33  
-	options = options || {};
34  
-	// defaults
35  
-	var showStack = options.showStack
36  
-		, showMessage = options.showMessage
37  
-		, dumpExceptions = options.dumpExceptions
38  
-		, logErrors = options.logErrors
39  
-		, logErrorsStream = false;
40  
-	
41  
-	if(options.logErrors)
42  
-		logErrorsStream = fs.createWriteStream(logErrors, {'flags': 'a', encoding: 'utf-8', mode: 0666});
  33
+    options = options || {};
  34
+    // defaults
  35
+    var showStack = options.showStack
  36
+        , showMessage = options.showMessage
  37
+        , dumpExceptions = options.dumpExceptions
  38
+        , logErrors = options.logErrors
  39
+        , logErrorsStream = false;
  40
+    
  41
+    if(options.logErrors)
  42
+        logErrorsStream = fs.createWriteStream(logErrors, {'flags': 'a', encoding: 'utf-8', mode: 0666});
43 43
 
44  
-	return function errorHandler(err, req, res, next){
45  
-	    res.statusCode = 500;
  44
+    return function errorHandler(err, req, res, next){
  45
+        res.statusCode = 500;
46 46
 
47  
-	    if(dumpExceptions) console.error(err.stack);
  47
+        if(dumpExceptions) console.error(err.stack);
48 48
 
49  
-		if(logErrors){
50  
-			var now = new Date();
51  
-			logErrorsStream.write(now.toJSON() + ' - Error Happened: \n' + err.stack + "\n");
52  
-		}
  49
+        if(logErrors){
  50
+            var now = new Date();
  51
+            logErrorsStream.write(now.toJSON() + ' - Error Happened: \n' + err.stack + "\n");
  52
+        }
53 53
 
54  
-		var accept = req.headers.accept || '';
55  
-	    if(showStack) {
56  
-			// html
57  
-			if (~accept.indexOf('html')) {
58  
-				res.render('error.jade', {
59  
-					  layout: false
60  
-					, stack: err.stack || ''
61  
-					, error: err.toString() 
62  
-					});
63  
-			// json
64  
-			} else if (~accept.indexOf('json')) {
65  
-				var json = JSON.stringify({ error: err });
66  
-				res.setHeader('Content-Type', 'application/json');
67  
-				res.end(json);
68  
-			// plain text
69  
-			} else {
70  
-				res.writeHead(500, { 'Content-Type': 'text/plain' });
71  
-				res.end(err.stack);
72  
-			}
73  
-	    }else{
74  
-			// public error page render
75  
-			// html
76  
-		  	if (~accept.indexOf('html')) {
77  
-				res.render('error.jade', {
78  
-						  layout: false
79  
-						});
80  
-			// json
81  
-			} else if (~accept.indexOf('json')) {
82  
-				var json = JSON.stringify({ error: "There was a server error generating the content." });
83  
-				res.setHeader('Content-Type', 'application/json');
84  
-				res.end(json);
85  
-			// plain text
86  
-			} else {
87  
-				res.writeHead(500, { 'Content-Type': 'text/plain' });
88  
-				res.end("500 - Server Error");
89  
-			}
90  
-	    }
91  
-	};
  54
+        var accept = req.headers.accept || '';
  55
+        if(showStack) {
  56
+            // html
  57
+            if (~accept.indexOf('html')) {
  58
+                res.render('error.jade', {
  59
+                      layout: false
  60
+                    , stack: err.stack || ''
  61
+                    , error: err.toString() 
  62
+                    });
  63
+            // json
  64
+            } else if (~accept.indexOf('json')) {
  65
+                var json = JSON.stringify({ error: err });
  66
+                res.setHeader('Content-Type', 'application/json');
  67
+                res.end(json);
  68
+            // plain text
  69
+            } else {
  70
+                res.writeHead(500, { 'Content-Type': 'text/plain' });
  71
+                res.end(err.stack);
  72
+            }
  73
+        }else{
  74
+            // public error page render
  75
+            // html
  76
+              if (~accept.indexOf('html')) {
  77
+                res.render('error.jade', {
  78
+                          layout: false
  79
+                        });
  80
+            // json
  81
+            } else if (~accept.indexOf('json')) {
  82
+                var json = JSON.stringify({ error: "There was a server error generating the content." });
  83
+                res.setHeader('Content-Type', 'application/json');
  84
+                res.end(json);
  85
+            // plain text
  86
+            } else {
  87
+                res.writeHead(500, { 'Content-Type': 'text/plain' });
  88
+                res.end("500 - Server Error");
  89
+            }
  90
+        }
  91
+    };
92 92
 };
274  lib/PublicPages.js
@@ -6,143 +6,143 @@ var PublicPages = module.exports = function PublicPages(){};
6 6
 
7 7
 PublicPages.prototype = {
8 8
 
9  
-	db: null
  9
+    db: null
10 10
 
11  
-	, initPages: function(app, db){
12  
-		this.db = db;
13  
-		var self = this;
14  
-		
15  
-		app.get('/', function(req, res) { self.pageIndex(req, res, true); });
16  
-		app.get('/Blog', function(req, res) { self.pageIndex(req, res, false); });
17  
-		app.get('/Blog/:page([0-9]+)', function(req, res) { self.pageIndex(req, res, {page: req.params.page}); });
18  
-		app.get('/Blog/:year([0-9]+)/:month([0-9]+)', function(req, res) { self.pageIndex(req, res, {year: req.params.year, month: req.params.month}); });
19  
-		//app.get('/Blog/:group', function(req, res) { self.pageIndex(req, res, {group: req.params.group}); });
20  
-		app.get('/Blog/s/:topic', function(req, res) { self.pageIndex(req, res, {search: req.params.topic}); });
21  
-		app.get('/Blog/:id/:title', function(req, res) { self.pageBlogPost(req, res); });
22  
-		
23  
-		app.get('/RSS', function(req, res) { self.RSS(req, res); });
24  
-	}
25  
-	
26  
-	, pageIndex: function(req, res, nav){
27  
-		var perpage = (!nav || nav.page) ? 10 : 100; // show 100 items for month or search, otherwise 10
28  
-		var blogpost = this.db.model('blogPost');
29  
-		var page = (nav && nav.page) ? nav.page - 1 : 0;
30  
-		var query = {};
31  
-		if(nav && nav.search) query = {title: {$regex: new RegExp('.*' + Util.escapeRegEx(nav.search) + '.*', 'i')}};
32  
-		if(nav && nav.group) query = {group: nav.group}; 
33  
-		if(nav && nav.year){
34  
-			var start = new Date(nav.year, nav.month, 1);
35  
-			var end = new Date(nav.year, start.getMonth() + 1, 1);
36  
-			query = {posted: { $gte: start, $lt: end }}; 
37  
-		}
  11
+    , initPages: function(app, db){
  12
+        this.db = db;
  13
+        var self = this;
  14
+        
  15
+        app.get('/', function(req, res) { self.pageIndex(req, res, true); });
  16
+        app.get('/Blog', function(req, res) { self.pageIndex(req, res, false); });
  17
+        app.get('/Blog/:page([0-9]+)', function(req, res) { self.pageIndex(req, res, {page: req.params.page}); });
  18
+        app.get('/Blog/:year([0-9]+)/:month([0-9]+)', function(req, res) { self.pageIndex(req, res, {year: req.params.year, month: req.params.month}); });
  19
+        //app.get('/Blog/:group', function(req, res) { self.pageIndex(req, res, {group: req.params.group}); });
  20
+        app.get('/Blog/s/:topic', function(req, res) { self.pageIndex(req, res, {search: req.params.topic}); });
  21
+        app.get('/Blog/:id/:title', function(req, res) { self.pageBlogPost(req, res); });
  22
+        
  23
+        app.get('/RSS', function(req, res) { self.RSS(req, res); });
  24
+    }
  25
+    
  26
+    , pageIndex: function(req, res, nav){
  27
+        var perpage = (!nav || nav.page) ? 10 : 100; // show 100 items for month or search, otherwise 10
  28
+        var blogpost = this.db.model('blogPost');
  29
+        var page = (nav && nav.page) ? nav.page - 1 : 0;
  30
+        var query = {};
  31
+        if(nav && nav.search) query = {title: {$regex: new RegExp('.*' + Util.escapeRegEx(nav.search) + '.*', 'i')}};
  32
+        if(nav && nav.group) query = {group: nav.group}; 
  33
+        if(nav && nav.year){
  34
+            var start = new Date(nav.year, nav.month, 1);
  35
+            var end = new Date(nav.year, start.getMonth() + 1, 1);
  36
+            query = {posted: { $gte: start, $lt: end }}; 
  37
+        }
38 38
 
39  
-		var query = blogpost.find(query);
40  
-		
41  
-		query.sort("posted", -1).skip(page * perpage).limit(perpage).exec(function(err, docs){
42  
-		
43  
-			for ( var k in docs ){
44  
-				docs[k].link_title = Util.link_title(docs[k].title);
45  
-				var new_short = jade.compile(docs[k].short);
46  
-				docs[k].short = new_short();
47  
-				docs[k].posted_human = Util.human_date(docs[k].posted);
48  
-			}
49  
-			
50  
-			query.count(function(err, postcount){ 
51  
-				var totalpages = Math.ceil(postcount / perpage);
52  
-				var nextpage = totalpages > page ? page + 2 : false;
53  
-				var prevpage = page > 0 ? page : false;
54  
-			
55  
-				var render_page = function(monthlist){
56  
-					res.render('index', {
57  
-							title: 'Blog',
58  
-							posts: docs,
59  
-							nextpage: nextpage,
60  
-							prevpage: prevpage,
61  
-							months: monthlist,
62  
-							month_names: new Array("January","February","March","April","May","June","July","August","September","October","November","December"),
63  
-							showFullNav: nav
64  
-						});
65  
-				}
66  
-				
67  
-				// Production of month groups for Archive
68  
-				var map = function(){
69  
-					emit( this.posted.getFullYear() + '-' + this.posted.getMonth() , { count: 1, year: this.posted.getFullYear(), month: this.posted.getMonth() } );
70  
-				};
71  
-				
72  
-				var reduce = function(key, values){
73  
-					var result = { 
74  
-						count: values.length,
75  
-						month: values[0].month,
76  
-						year: values[0].year
77  
-					};
78  
-				    return result;
79  
-				};
80  
-				
81  
-				blogpost.collection.mapReduce(
82  
-					map.toString()
83  
-					, reduce.toString()
84  
-					, {out: { inline: 1 }}
85  
-					, function(err, monthlist){
86  
-						monthlist.reverse();
87  
-						render_page(monthlist);
88  
-					}
89  
-				);
90  
-			});
91  
-		});
92  
-		
93  
-	} 
94  
-	
95  
-	, pageBlogPost: function(req, res){
96  
-		var blogpost = this.db.model('blogPost');
97  
-		blogpost.findOne({sid: req.params.id}, function(err, row){
98  
-			if(!row){
99  
-				res.redirect('/404');
100  
-				return;
101  
-			}
102  
-			
103  
-			row.link_title = Util.link_title(row.title);
104  
-			var new_short = jade.compile(row.short);
105  
-			row.short = new_short();
106  
-			var new_content = jade.compile(row.content);
107  
-			row.content = new_content();
108  
-			row.posted_human = Util.human_date(row.posted);
109  
-			row.edited_human = Util.human_date(row.edited);
110  
-			
111  
-			res.render('post', {
112  
-				title: row.title,
113  
-				post: row,
114  
-				showFullNav: false
115  
-			});
116  
-		});
117  
-	} 
118  
-	
119  
-	, RSS: function(req, res){
120  
-		var blogpost = this.db.model('blogPost');
121  
-		var query = blogpost.find().sort("posted", -1).limit(30).exec(function(err, docs){
122  
-			
123  
-			for ( var k in docs ){
124  
-				docs[k].title = docs[k].title;
125  
-				var new_short = jade.compile(docs[k].short);
126  
-				docs[k].description = new_short();
127  
-				docs[k].pubDate = docs[k].posted;
128  
-				docs[k].link = (docs[k].ext_link != '') ? 
129  
-					docs[k].ext_link : 
130  
-					'http://mikevalstar.com/Blog/' + docs[k].sid + "/" + Util.link_title(docs[k].title);
131  
-				docs[k].guid = 'http://mikevalstar.com/Blog/' + docs[k].sid + "/" + Util.link_title(docs[k].title);
132  
-				docs[k].isPermaLink = true;
133  
-			}
134  
-			
135  
-			res.header('Content-Type', 'application/xml');
136  
-			res.render('rss2.0.template.jade', {
137  
-				  dateFormat: Util.GetRFC822Date
138  
-				, channel: {
139  
-						  title: "Mike Valstar's Blog"
140  
-						, link: "http://mikevalstar.com"
141  
-						, description: "WEB DEVELOPMENT, PROGRAMMING, RANDOM THOUGHTS"
142  
-					}
143  
-				, items: docs
144  
-				, layout: false
145  
-			});
146  
-		});
147  
-	} 
  39
+        var query = blogpost.find(query);
  40
+        
  41
+        query.sort("-posted").skip(page * perpage).limit(perpage).exec(function(err, docs){
  42
+        
  43
+            for ( var k in docs ){
  44
+                docs[k].link_title = Util.link_title(docs[k].title);
  45
+                var new_short = jade.compile(docs[k].short);
  46
+                docs[k].short = new_short();
  47
+                docs[k].posted_human = Util.human_date(docs[k].posted);
  48
+            }
  49
+            
  50
+            query.count(function(err, postcount){ 
  51
+                var totalpages = Math.ceil(postcount / perpage);
  52
+                var nextpage = totalpages > page ? page + 2 : false;
  53
+                var prevpage = page > 0 ? page : false;
  54
+            
  55
+                var render_page = function(monthlist){
  56
+                    res.render('index', {
  57
+                            title: 'Blog',
  58
+                            posts: docs,
  59
+                            nextpage: nextpage,
  60
+                            prevpage: prevpage,
  61
+                            months: monthlist,
  62
+                            month_names: new Array("January","February","March","April","May","June","July","August","September","October","November","December"),
  63
+                            showFullNav: nav
  64
+                        });
  65
+                }
  66
+                
  67
+                // Production of month groups for Archive
  68
+                var map = function(){
  69
+                    emit( this.posted.getFullYear() + '-' + this.posted.getMonth() , { count: 1, year: this.posted.getFullYear(), month: this.posted.getMonth() } );
  70
+                };
  71
+                
  72
+                var reduce = function(key, values){
  73
+                    var result = { 
  74
+                        count: values.length,
  75
+                        month: values[0].month,
  76
+                        year: values[0].year
  77
+                    };
  78
+                    return result;
  79
+                };
  80
+                
  81
+                blogpost.collection.mapReduce(
  82
+                    map.toString()
  83
+                    , reduce.toString()
  84
+                    , {out: { inline: 1 }}
  85
+                    , function(err, monthlist){
  86
+                        monthlist.reverse();
  87
+                        render_page(monthlist);
  88
+                    }
  89
+                );
  90
+            });
  91
+        });
  92
+        
  93
+    } 
  94
+    
  95
+    , pageBlogPost: function(req, res){
  96
+        var blogpost = this.db.model('blogPost');
  97
+        blogpost.findOne({sid: req.params.id}, function(err, row){
  98
+            if(!row){
  99
+                res.redirect('/404');
  100
+                return;
  101
+            }
  102
+            
  103
+            row.link_title = Util.link_title(row.title);
  104
+            var new_short = jade.compile(row.short);
  105
+            row.short = new_short();
  106
+            var new_content = jade.compile(row.content);
  107
+            row.content = new_content();
  108
+            row.posted_human = Util.human_date(row.posted);
  109
+            row.edited_human = Util.human_date(row.edited);
  110
+            
  111
+            res.render('post', {
  112
+                title: row.title,
  113
+                post: row,
  114
+                showFullNav: false
  115
+            });
  116
+        });
  117
+    } 
  118
+    
  119
+    , RSS: function(req, res){
  120
+        var blogpost = this.db.model('blogPost');
  121
+        var query = blogpost.find().sort("-posted").limit(30).exec(function(err, docs){
  122
+            
  123
+            for ( var k in docs ){
  124
+                docs[k].title = docs[k].title;
  125
+                var new_short = jade.compile(docs[k].short);
  126
+                docs[k].description = new_short();
  127
+                docs[k].pubDate = docs[k].posted;
  128
+                docs[k].link = (docs[k].ext_link != '') ? 
  129
+                    docs[k].ext_link : 
  130
+                    'http://mikevalstar.com/Blog/' + docs[k].sid + "/" + Util.link_title(docs[k].title);
  131
+                docs[k].guid = 'http://mikevalstar.com/Blog/' + docs[k].sid + "/" + Util.link_title(docs[k].title);
  132
+                docs[k].isPermaLink = true;
  133
+            }
  134
+            
  135
+            res.header('Content-Type', 'application/xml');
  136
+            res.render('rss2.0.template.jade', {
  137
+                  dateFormat: Util.GetRFC822Date
  138
+                , channel: {
  139
+                          title: "Mike Valstar's Blog"
  140
+                        , link: "http://mikevalstar.com"
  141
+                        , description: "WEB DEVELOPMENT, PROGRAMMING, RANDOM THOUGHTS"
  142
+                    }
  143
+                , items: docs
  144
+                , layout: false
  145
+            });
  146
+        });
  147
+    } 
148 148
 };
40  lib/StaticPages.js
@@ -2,24 +2,24 @@ var StaticPages = module.exports = function StaticPages(){};
2 2
 
3 3
 StaticPages.prototype = {
4 4
 
5  
-	initPages: function(app){
6  
-	
7  
-		// Routes
8  
-		app.get('/Projects', function(req, res){
9  
-		  res.render('projects', {
10  
-		    title: 'Home',
11  
-		    showFullNav: false
12  
-		  });
13  
-		});
14  
-		
15  
-		app.get('/About', function(req, res){
16  
-		  res.render('about', {
17  
-		    title: 'Home',
18  
-		    showFullNav: false
19  
-		  });
20  
-		});
21  
-	
22  
-	}
23  
-	
24  
-	
  5
+    initPages: function(app){
  6
+    
  7
+        // Routes
  8
+        app.get('/Projects', function(req, res){
  9
+          res.render('projects', {
  10
+            title: 'Home',
  11
+            showFullNav: false
  12
+          });
  13
+        });
  14
+        
  15
+        app.get('/About', function(req, res){
  16
+          res.render('about', {
  17
+            title: 'Home',
  18
+            showFullNav: false
  19
+          });
  20
+        });
  21
+    
  22
+    }
  23
+    
  24
+    
25 25
 };
114  lib/Util.js
... ...
@@ -1,62 +1,62 @@
1 1
 var dateFormat = require('dateformat');
2 2
 
3 3
 var Util = module.exports = {
4  
-	
5  
-	  escapeRegEx: function(str) {
6  
-	  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
7  
-	}
8  
-	
9  
-	, link_title: function(title){
10  
-		return title
11  
-			.replace(/  /gi, " ")
12  
-			.replace(/ /gi, "_")
13  
-			.replace(/'/gi, "")
14  
-			.replace(/;/gi, "")
15  
-			.replace(/:/gi, "")
16  
-			.replace(/\./gi, "")
17  
-			.replace(/__/gi, "_");
18  
-	}
19  
-	
20  
-	, human_date: function(dt){
21  
-		return dateFormat(dt, "mmmm d, yyyy - h:MM TT");
22  
-	}
23  
-	
24  
-	, GetRFC822Date: function(oDate){
25  
-	
26  
-		// allow for empty request
27  
-		if(typeof(oDate) == "undefined" || !oDate) oDate = new Date();
28  
-	
29  
-		//Pads numbers with a preceding 0 if the number is less than 10.
30  
-		var LZ = function(val){ return (parseInt(val) < 10) ? "0" + val : val; }
31  
-		
32  
-		/* accepts the client's time zone offset from GMT in minutes as a parameter. returns the timezone offset in the format [+|-}DDDD */
33  
-		var getTZOString = function(timezoneOffset){
34  
-			var hours = Math.floor(timezoneOffset/60);
35  
-			var modMin = Math.abs(timezoneOffset%60);
36  
-			var s = new String();
37  
-			s += (hours > 0) ? "-" : "+";
38  
-			var absHours = Math.abs(hours)
39  
-			s += (absHours < 10) ? "0" + absHours :absHours;
40  
-			s += ((modMin == 0) ? "00" : modMin);
41  
-			return(s);
42  
-		}
43  
-	
44  
-		var aMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
45  
-		var aDays = new Array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
46  
-		var dtm = new String();
47  
-			
48  
-		dtm = aDays[oDate.getDay()] + ", ";
49  
-		dtm += LZ(oDate.getDate()) + " ";
50  
-		dtm += aMonths[oDate.getMonth()] + " ";
51  
-		dtm += oDate.getFullYear() + " ";
52  
-		dtm += LZ(oDate.getHours()) + ":";
53  
-		dtm += LZ(oDate.getMinutes()) + ":";
54  
-		dtm += LZ(oDate.getSeconds()) + " " ;
55  
-		dtm += getTZOString(oDate.getTimezoneOffset());
56