Skip to content

Commit

Permalink
Require authentication for admin and profile pages
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarkus committed Dec 31, 2013
1 parent 709e917 commit 595989c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions controllers/admin.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict';


var AdminModel = require('../models/admin');
var AdminModel = require('../models/admin'),
auth = require('../lib/auth');


module.exports = function (app) {

var model = new AdminModel();


app.get('/admin', function (req, res) {
app.get('/admin', auth.isAuthenticated('admin'), function (req, res) {

res.render('admin', model);

});

};
9 changes: 5 additions & 4 deletions controllers/profile.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict';


var ProfileModel = require('../models/profile');
var ProfileModel = require('../models/profile'),
auth = require('../lib/auth');


module.exports = function (app) {

var model = new ProfileModel();


app.get('/profile', function (req, res) {
app.get('/profile', auth.isAuthenticated(), function (req, res) {

res.render('profile', model);

});

};
1 change: 1 addition & 0 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ exports.isAuthenticated = function (role) {
if (role && req.user.role !== role) {
res.status(401);
res.render('errors/401');
return;
}

next();
Expand Down

0 comments on commit 595989c

Please sign in to comment.