...
|
...
|
@@ -10,6 +10,7 @@ var options=require('../staticConfig.js').staticDir; |
|
|
|
|
|
var author=require("../stub/service/auth");
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 不需要权限校验配置
|
|
|
*/
|
...
|
...
|
@@ -32,24 +33,6 @@ if(env!=='development') { |
|
|
}
|
|
|
|
|
|
|
|
|
//模块环境适配
|
|
|
// var common = require('../util/common');
|
|
|
// var path = require('path');
|
|
|
// var url = require('url');
|
|
|
|
|
|
// var $routers = { GET: {}, POST: {}, ALL: [] };
|
|
|
// common.readDir(path.join(__dirname, '../interface'), function (module) {
|
|
|
// Array.prototype.push.apply($routers.ALL, module.res);
|
|
|
// });
|
|
|
// //刷选get/post请求
|
|
|
// for (var i in $routers.ALL) {
|
|
|
// var router = $routers.ALL[i];
|
|
|
// var methord = router.method.toUpperCase();
|
|
|
// var url = router.route;
|
|
|
// $routers[methord || "GET"][url] = router;
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 认证中间件
|
|
|
* @param {Object} req 请求对象
|
...
|
...
|
@@ -62,6 +45,32 @@ module.exports = function(req, res, next) { |
|
|
//方法名称
|
|
|
var method = req.method;
|
|
|
|
|
|
function nextRedirect(method,path){
|
|
|
//进行白名单验证和session验证
|
|
|
if(guestAccessList[method+":"+path]||req.session.user) {
|
|
|
//判断是否已存在appendData
|
|
|
if(!res.appendData) {
|
|
|
res.appendData = _.cloneDeep(req.session.user);
|
|
|
} else {
|
|
|
res.appendData = _.merge({},res.appendData,req.session.user);
|
|
|
}
|
|
|
|
|
|
//添加当前菜单激活
|
|
|
addActiveMenu(req,res);
|
|
|
|
|
|
//添加管理员信息到http头
|
|
|
if(req.session.user) {
|
|
|
appendAdminInfo(req,req.session.user.auth);
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
} else {
|
|
|
req.app.logger.log('info',"CurentView:Login");
|
|
|
//如果是登陆界面不加载布局
|
|
|
res.render('pages/login',{layout:false,cssfile:CSS_FILE});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function filterOriginalUrl(path){
|
|
|
if(!/\.\w+/.test(path)){
|
|
|
return path.replace(/\?.+/,'');
|
...
|
...
|
@@ -71,40 +80,27 @@ module.exports = function(req, res, next) { |
|
|
//访问路由路径
|
|
|
var path = req.route?req.route.path:filterOriginalUrl(req.originalUrl);
|
|
|
if(req.session.user) {
|
|
|
if(path&&!req.xhr){
|
|
|
if(guestAccessList[method+":"+path]){
|
|
|
nextRedirect(method,path);
|
|
|
return;
|
|
|
}
|
|
|
/*判断权限*/
|
|
|
if(path&&req.session.user.allRight[path]){
|
|
|
author.validateAuthor(req.session.user.auth.pid,req.session.user.auth.role_id,path,function(data){
|
|
|
console.log(data);
|
|
|
if(data.code!=200){
|
|
|
res.status(403);
|
|
|
res.render('error/error_nolayout',{message:NO_AUTH,layout:false,cssfile:CSS_FILE});
|
|
|
return;
|
|
|
}
|
|
|
nextRedirect(method,path);
|
|
|
});
|
|
|
}else{
|
|
|
nextRedirect(method,path);
|
|
|
}
|
|
|
}else{
|
|
|
nextRedirect(method,path);
|
|
|
}
|
|
|
//进行白名单验证和session验证
|
|
|
if(guestAccessList[method+":"+path]||req.session.user) {
|
|
|
//判断是否已存在appendData
|
|
|
if(!res.appendData) {
|
|
|
res.appendData = _.cloneDeep(req.session.user);
|
|
|
} else {
|
|
|
res.appendData = _.merge({},res.appendData,req.session.user);
|
|
|
}
|
|
|
|
|
|
//添加当前菜单激活
|
|
|
addActiveMenu(req,res);
|
|
|
|
|
|
//添加管理员信息到http头
|
|
|
if(req.session.user) {
|
|
|
appendAdminInfo(req,req.session.user.auth);
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
} else {
|
|
|
req.app.logger.log('info',"CurentView:Login");
|
|
|
//如果是登陆界面不加载布局
|
|
|
res.render('pages/login',{layout:false,cssfile:CSS_FILE});
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|