Authored by htoooth

Merge remote-tracking branch 'origin/release/1.0' into release/1.0

... ... @@ -30,8 +30,12 @@ const plugin = {
// return Promise.reject();
},
initPurview(Vue, user) {
Vue.$cookie.set('_isLogin', true);
Vue.$cookie.set('shopsId', user.currentShop.id);
Vue.$cookie.set('_isLogin', true, {
path: '/'
});
Vue.$cookie.set('shopsId', user.currentShop.id, {
path: '/'
});
return userService.purviews().then((purviews) => {
this.updateUser(Vue, user, purviews);
});
... ...
... ... @@ -27,13 +27,17 @@ let domainApis = {
updateSellerPrice: '/SellerPriceController/updateSellerPrice',
updateProduct: '/SellerProductController/updateProduct',
getProduct: '/SellerProductController/getProduct'
},
shop: {
loginInter: '/loginInter'
}
};
// 域名列表
const domains = {
erp: 'http://192.168.13.249',
platform: 'http://192.168.102.210:8088/platform'
platform: 'http://192.168.102.210:8088/platform',
shop: 'http://192.168.102.211:30016'
};
_.each(domainApis, (apis, domainName) => {
... ...
... ... @@ -67,7 +67,6 @@ class Api extends Context {
resolveWithFullResponse: true
});
return rp[options.method || 'get'](options).then(response => {
console.log(response.rawHeaders)
let jsonBody = JSON.parse(response.body);
let req = response.request;
... ...
... ... @@ -15,39 +15,44 @@ class UserController extends Context {
this.userService = this.instance(UserService);
}
login(req, res, next) {
this.userService.login(req.body.username, req.body.password).then(user => {
this.userService.getShops(user.pid).then(result => {
if (result.code === 200) {
this.syncSession(req, Object.assign(user, {
shops: result.data
}));
let currentShop = _.first(result.data);
Promise.all([
this.userService.login(req.body.username, req.body.password),
this.userService.shopLogin(req.body.username, req.body.password)]).then(allResult => {
let user = allResult[0];
let sess = allResult[1];
return res.json({
code: 200,
data: {
name: user.account,
email: user.email,
createDate: user.create_date,
shops: _.map(result.data, shop => {
return {
id: shop.id,
shopName: shop.shopName
};
}),
currentShop: {
shopName: currentShop.shopName,
id: currentShop.id
this.userService.getShops(user.pid).then(result => {
if (result.code === 200) {
this.syncSession({req, res}, Object.assign(user, {
shops: result.data
}), sess);
let currentShop = _.first(result.data);
return res.json({
code: 200,
data: {
name: user.account,
email: user.email,
createDate: user.create_date,
shops: _.map(result.data, shop => {
return {
id: shop.id,
shopName: shop.shopName
};
}),
currentShop: {
shopName: currentShop.shopName,
id: currentShop.id
}
}
}
});
} else {
return res.json(result);
}
});
}, err => {
return res.json(err);
}).catch(next);
});
} else {
return res.json(result);
}
});
}, err => {
return res.json(err);
}).catch(next);
}
logout(req, res) {
... ... @@ -60,9 +65,15 @@ class UserController extends Context {
});
}
syncSession(req, user) {
req.session.USER = user;
req.session.LOGIN_UID = user.pid; // pid 为用户名
syncSession(context, user, sess) {
console.log(sess)
context.req.session.USER = user;
context.req.session.LOGIN_UID = user.pid; // pid 为用户名
_.each(sess, (v, k) => {
context.res.cookie(k, v, {
path: '/'
});
});
}
}
... ...
... ... @@ -7,10 +7,13 @@
const _ = require('lodash');
const md5 = require('yoho-md5');
const Context = require('../common/context');
const rp = require('request-promise');
const Api = require('../common/api');
const apiDomain = global.yoho.apiDomain;
const config = global.yoho.config;
const regSession = '${0}=([^;]+);';
class UserService extends Context {
constructor() {
super();
... ... @@ -22,9 +25,6 @@ class UserService extends Context {
password,
platform: config.platform
}).then(userInfo => {
this.api.get(`http://192.168.102.211:30016/loginInter?user=${account}&password=${password}`).then(res => {
console.log(res);
});
if (userInfo.code !== 200 || !userInfo.data.pid) {
return Promise.reject({code: 500, message: '用户名密码错误'});
}
... ... @@ -32,6 +32,35 @@ class UserService extends Context {
});
}
shopLogin(account, password) {
return rp.get({
url: apiDomain.shop.loginInter,
resolveWithFullResponse: true,
qs: {
user: account,
password: password
}
}).then(response => {
let sessId = '', sid = '';
_.each(response.rawHeaders, header => {
let sessIdMatched = header.match(new RegExp(regSession.replace('${0}', 'PHPSESSID')));
let sidMatched = header.match(new RegExp(regSession.replace('${0}', 'connect\.sid')));
if (sessIdMatched) {
sessId = sessIdMatched[1];
}
if (sidMatched) {
sid = sidMatched[1];
}
});
return {
PHPSESSID: sessId,
'connect.sid': sid
};
});
}
getShops(pid) {
return this.api.get(apiDomain.platform.queryShopsByAdminPid, {
userId: pid
... ...