authAdmin.js 533 Bytes
/**
 * 管理员判断
 * @author: leo <qi.li@yoho.cn>
 * @date: 2017/7/6
 */
'use strict';

const _ = require('lodash');

module.exports = (req, res, next) => {
    const path = req.path;
    const isAdmin = _.get(req.session, 'user.isAdmin');

    // 无需验证的路径
    const excludedPath = [
        '/login',
        '/api/login'
    ];

    if (excludedPath.indexOf(path) > -1) {
        return next();
    }

    if (!isAdmin) {
        return res.redirect('/admin/login');
    }

    req.isAdmin = true;
    next();
};