Authored by htoooth

增加用户权限的控制。

@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 8
9 const router = require('express').Router(); // eslint-disable-line 9 const router = require('express').Router(); // eslint-disable-line
10 const cRoot = './controllers'; 10 const cRoot = './controllers';
  11 +const auth = require(`${global.middleware}/auth`);
11 12
12 // 商品详情controller 13 // 商品详情controller
13 const detail = require(`${cRoot}/detail`); 14 const detail = require(`${cRoot}/detail`);
@@ -45,7 +46,7 @@ router.get('/list', list.index); // 商品列表页 @@ -45,7 +46,7 @@ router.get('/list', list.index); // 商品列表页
45 router.get(/\/pro_([\d]+)_([\d]+)\/(.*)/, detail.showMain); // 商品详情routers 46 router.get(/\/pro_([\d]+)_([\d]+)\/(.*)/, detail.showMain); // 商品详情routers
46 router.get('/detail/comment', detail.indexComment);// 商品评论 47 router.get('/detail/comment', detail.indexComment);// 商品评论
47 router.get('/detail/consult', detail.indexConsult);// 商品咨询 48 router.get('/detail/consult', detail.indexConsult);// 商品咨询
48 -router.post('/detail/consult', detail.createConsult);// 创建咨询 49 +router.post('/detail/consult', auth, detail.createConsult);// 创建咨询
49 router.get('/detail/hotarea', detail.indexHotArea);// 商品热区 50 router.get('/detail/hotarea', detail.indexHotArea);// 商品热区
50 router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收藏品牌 51 router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收藏品牌
51 router.post('/item/togglecollect', favorite.collectProduct); // 收藏商品 52 router.post('/item/togglecollect', favorite.collectProduct); // 收藏商品
@@ -6,6 +6,24 @@ @@ -6,6 +6,24 @@
6 6
7 'use strict'; 7 'use strict';
8 8
  9 +const _ = require('lodash');
  10 +const helpers = global.yoho.helpers;
  11 +
9 module.exports = (req, res, next) => { 12 module.exports = (req, res, next) => {
  13 + let refer = req.method === 'GET'? req.get('Referer'):'';
  14 +
  15 + let loginUrl = helpers.urlFormat('/passport/login', {refer: refer});
  16 +
  17 + if (_.isEmpty(req.user) || !req.user.uid) {
  18 + if (req.xhr) {
  19 + return res.json({
  20 + code: 400,
  21 + message: '抱歉,您暂未登录!',
  22 + data: {refer: loginUrl}
  23 + });
  24 + }
  25 +
  26 + return res.redirect(loginUrl);
  27 + }
10 next(); 28 next();
11 }; 29 };