Skip to content

Commit

Permalink
Add admin router and checkAdmin fun
Browse files Browse the repository at this point in the history
  • Loading branch information
applesstt committed Apr 20, 2014
1 parent d823070 commit af55a46
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions controllers/admin.js
@@ -0,0 +1,9 @@
exports.toUsers = function(req, res) {
res.render('admin/users', {
title: '用户列表',
user: req.session.user,
env: req.session.env,
success: req.flash('success').toString(),
error: req.flash('error').toString()
});
}
8 changes: 8 additions & 0 deletions controllers/auth.js
Expand Up @@ -12,4 +12,12 @@ exports.checkNotLogin = function(req, res, next) {
res.redirect('back');
}
next();
};

exports.checkSupperAdmin = function(req, res, next) {
if(req.session.user.name !== 'applesstt') {
req.flash('error', '您不是管理员!');
res.redirect('back');
}
next();
};
7 changes: 6 additions & 1 deletion routes/index.js
Expand Up @@ -5,7 +5,8 @@ var auth = require('../controllers/auth.js'),
article = require('../controllers/article.js'),
mail = require('../controllers/mail.js'),
user = require('../controllers/user.js'),
person = require('../controllers/person.js');
person = require('../controllers/person.js'),
admin = require('../controllers/admin.js');

module.exports = function(app) {

Expand Down Expand Up @@ -53,6 +54,10 @@ module.exports = function(app) {
app.all('/person*', auth.checkLogin);
app.all('/person', person.toSet);

app.all('/admin*', auth.checkLogin);
app.all('/admin*', auth.checkSupperAdmin);
app.all('/admin', admin.toUsers);

app.all('/logout', auth.checkLogin);
app.get('/logout', login.logout);

Expand Down
1 change: 1 addition & 0 deletions views/admin/users.jade
@@ -0,0 +1 @@
extends ../layout/layout

0 comments on commit af55a46

Please sign in to comment.