...
|
...
|
@@ -26,9 +26,8 @@ class UserController extends Context { |
|
|
let currentShop = _.first(result.data);
|
|
|
|
|
|
this.syncSession({req, res}, Object.assign(user, {
|
|
|
shops: result.data,
|
|
|
currentShop: currentShop
|
|
|
}), sess);
|
|
|
shops: result.data
|
|
|
}), sess, currentShop);
|
|
|
|
|
|
return res.json({
|
|
|
code: 200,
|
...
|
...
|
@@ -68,26 +67,62 @@ class UserController extends Context { |
|
|
data: '登出成功'
|
|
|
});
|
|
|
}
|
|
|
switchShop(req, res) {
|
|
|
let shopId = req.body.shopId;
|
|
|
|
|
|
syncSession(context, user, sess) {
|
|
|
if (!shopId) {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: '参数错误'
|
|
|
});
|
|
|
}
|
|
|
let shop = _.find(req.session.USER.shops, s => s.shopsId === shopId);
|
|
|
|
|
|
if (!shop) {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: '不存在的店铺'
|
|
|
});
|
|
|
}
|
|
|
this.userService.switchShop({
|
|
|
shopId,
|
|
|
cookies: {
|
|
|
PHPSESSID: encodeURIComponent(req.cookies.PHPSESSID),
|
|
|
'connect.sid': encodeURIComponent(req.cookies['connect.sid'])
|
|
|
}
|
|
|
}).then(response => {
|
|
|
this.syncShopSession({
|
|
|
req,
|
|
|
res
|
|
|
}, response);
|
|
|
return res.json({
|
|
|
code: 200
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
syncSession(context, user, sess, currentShop) {
|
|
|
context.req.session.USER = user;
|
|
|
context.req.session.LOGIN_UID = user.pid; // pid 为用户名
|
|
|
|
|
|
this.syncShopSession(context, sess);
|
|
|
context.res.cookie('_isLogin', true, {
|
|
|
path: '/'
|
|
|
});
|
|
|
context.res.cookie('_sign', currentShop.shopsId, {
|
|
|
path: '/'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
syncShopSession(context, sess) {
|
|
|
_.each(sess, (v, k) => {
|
|
|
context.res.cookie(k, v, {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
httpOnly: true,
|
|
|
overwrite: false,
|
|
|
encode: val => val
|
|
|
});
|
|
|
});
|
|
|
context.res.cookie('_isLogin', true, {
|
|
|
path: '/'
|
|
|
});
|
|
|
context.res.cookie('_sign', user.currentShop.shopsId, {
|
|
|
path: '/'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|