login.js 1.6 KB
var authService = require('../service/auth');
var _ = require('lodash');

var uploader = require('../service/upload');



module.exports = {
    '/auth': function(req, res) {
        var user = req.body.user || '';
        var password = req.body.password || '';
        authService.callLogin(user, password, res);
    },
    '/index/ajaxshop': function(req, res) {
        var shopId = Number(req.query.shops_id);
        var cookie = req.session.gray;

        //设置当前的店铺信息
        if (req.session.user && req.session.user.auth) {
            _.forEach(req.session.user.shopList, function(v, k) {
                if (v.id === shopId) {
                    req.session.user.auth.shopName = v.name;
                    req.session.user.auth.shopId = shopId;
                };
            });
        }
        //调用老系统的切换店铺的接口
        authService.change(shopId, cookie, function(err, data) {
            if (err) {
                res.json({
                    'code': 500,
                    'message': 'something wrong!'
                })
            } else {
                res.json({
                    'code': 200
                });
            }
        });
    },
    '/ajax/upload': function(req, res) {
        uploader.uploadFile(req, res);
    },
    '/ajax/down': function(req, res) {
        uploader.downFile(req, res);
    },
    '/ajax/ueditor': function(req, res) {
        uploader.ueditor(req, res);
    },
    '/ajax/link/:name': function(req, res) {
        uploader.linkFile(req, res);
    },
    '/proxy':function (req,res) {
        uploader.proxy(req,res);
    }
}