Merge remote-tracking branch 'origin/release/1.0' into release/1.0
Showing
5 changed files
with
60 additions
and
13 deletions
@@ -30,8 +30,12 @@ const plugin = { | @@ -30,8 +30,12 @@ const plugin = { | ||
30 | // return Promise.reject(); | 30 | // return Promise.reject(); |
31 | }, | 31 | }, |
32 | initPurview(Vue, user) { | 32 | initPurview(Vue, user) { |
33 | - Vue.$cookie.set('_isLogin', true); | ||
34 | - Vue.$cookie.set('shopsId', user.currentShop.id); | 33 | + Vue.$cookie.set('_isLogin', true, { |
34 | + path: '/' | ||
35 | + }); | ||
36 | + Vue.$cookie.set('shopsId', user.currentShop.id, { | ||
37 | + path: '/' | ||
38 | + }); | ||
35 | return userService.purviews().then((purviews) => { | 39 | return userService.purviews().then((purviews) => { |
36 | this.updateUser(Vue, user, purviews); | 40 | this.updateUser(Vue, user, purviews); |
37 | }); | 41 | }); |
@@ -27,13 +27,17 @@ let domainApis = { | @@ -27,13 +27,17 @@ let domainApis = { | ||
27 | updateSellerPrice: '/SellerPriceController/updateSellerPrice', | 27 | updateSellerPrice: '/SellerPriceController/updateSellerPrice', |
28 | updateProduct: '/SellerProductController/updateProduct', | 28 | updateProduct: '/SellerProductController/updateProduct', |
29 | getProduct: '/SellerProductController/getProduct' | 29 | getProduct: '/SellerProductController/getProduct' |
30 | + }, | ||
31 | + shop: { | ||
32 | + loginInter: '/loginInter' | ||
30 | } | 33 | } |
31 | }; | 34 | }; |
32 | 35 | ||
33 | // 域名列表 | 36 | // 域名列表 |
34 | const domains = { | 37 | const domains = { |
35 | erp: 'http://192.168.13.249', | 38 | erp: 'http://192.168.13.249', |
36 | - platform: 'http://192.168.102.210:8088/platform' | 39 | + platform: 'http://192.168.102.210:8088/platform', |
40 | + shop: 'http://192.168.102.211:30016' | ||
37 | }; | 41 | }; |
38 | 42 | ||
39 | _.each(domainApis, (apis, domainName) => { | 43 | _.each(domainApis, (apis, domainName) => { |
@@ -67,7 +67,6 @@ class Api extends Context { | @@ -67,7 +67,6 @@ class Api extends Context { | ||
67 | resolveWithFullResponse: true | 67 | resolveWithFullResponse: true |
68 | }); | 68 | }); |
69 | return rp[options.method || 'get'](options).then(response => { | 69 | return rp[options.method || 'get'](options).then(response => { |
70 | - console.log(response.rawHeaders) | ||
71 | let jsonBody = JSON.parse(response.body); | 70 | let jsonBody = JSON.parse(response.body); |
72 | let req = response.request; | 71 | let req = response.request; |
73 | 72 |
@@ -15,12 +15,17 @@ class UserController extends Context { | @@ -15,12 +15,17 @@ class UserController extends Context { | ||
15 | this.userService = this.instance(UserService); | 15 | this.userService = this.instance(UserService); |
16 | } | 16 | } |
17 | login(req, res, next) { | 17 | login(req, res, next) { |
18 | - this.userService.login(req.body.username, req.body.password).then(user => { | 18 | + Promise.all([ |
19 | + this.userService.login(req.body.username, req.body.password), | ||
20 | + this.userService.shopLogin(req.body.username, req.body.password)]).then(allResult => { | ||
21 | + let user = allResult[0]; | ||
22 | + let sess = allResult[1]; | ||
23 | + | ||
19 | this.userService.getShops(user.pid).then(result => { | 24 | this.userService.getShops(user.pid).then(result => { |
20 | if (result.code === 200) { | 25 | if (result.code === 200) { |
21 | - this.syncSession(req, Object.assign(user, { | 26 | + this.syncSession({req, res}, Object.assign(user, { |
22 | shops: result.data | 27 | shops: result.data |
23 | - })); | 28 | + }), sess); |
24 | let currentShop = _.first(result.data); | 29 | let currentShop = _.first(result.data); |
25 | 30 | ||
26 | return res.json({ | 31 | return res.json({ |
@@ -60,9 +65,15 @@ class UserController extends Context { | @@ -60,9 +65,15 @@ class UserController extends Context { | ||
60 | }); | 65 | }); |
61 | } | 66 | } |
62 | 67 | ||
63 | - syncSession(req, user) { | ||
64 | - req.session.USER = user; | ||
65 | - req.session.LOGIN_UID = user.pid; // pid 为用户名 | 68 | + syncSession(context, user, sess) { |
69 | + console.log(sess) | ||
70 | + context.req.session.USER = user; | ||
71 | + context.req.session.LOGIN_UID = user.pid; // pid 为用户名 | ||
72 | + _.each(sess, (v, k) => { | ||
73 | + context.res.cookie(k, v, { | ||
74 | + path: '/' | ||
75 | + }); | ||
76 | + }); | ||
66 | } | 77 | } |
67 | } | 78 | } |
68 | 79 |
@@ -7,10 +7,13 @@ | @@ -7,10 +7,13 @@ | ||
7 | const _ = require('lodash'); | 7 | const _ = require('lodash'); |
8 | const md5 = require('yoho-md5'); | 8 | const md5 = require('yoho-md5'); |
9 | const Context = require('../common/context'); | 9 | const Context = require('../common/context'); |
10 | +const rp = require('request-promise'); | ||
10 | const Api = require('../common/api'); | 11 | const Api = require('../common/api'); |
11 | const apiDomain = global.yoho.apiDomain; | 12 | const apiDomain = global.yoho.apiDomain; |
12 | const config = global.yoho.config; | 13 | const config = global.yoho.config; |
13 | 14 | ||
15 | +const regSession = '${0}=([^;]+);'; | ||
16 | + | ||
14 | class UserService extends Context { | 17 | class UserService extends Context { |
15 | constructor() { | 18 | constructor() { |
16 | super(); | 19 | super(); |
@@ -22,9 +25,6 @@ class UserService extends Context { | @@ -22,9 +25,6 @@ class UserService extends Context { | ||
22 | password, | 25 | password, |
23 | platform: config.platform | 26 | platform: config.platform |
24 | }).then(userInfo => { | 27 | }).then(userInfo => { |
25 | - this.api.get(`http://192.168.102.211:30016/loginInter?user=${account}&password=${password}`).then(res => { | ||
26 | - console.log(res); | ||
27 | - }); | ||
28 | if (userInfo.code !== 200 || !userInfo.data.pid) { | 28 | if (userInfo.code !== 200 || !userInfo.data.pid) { |
29 | return Promise.reject({code: 500, message: '用户名密码错误'}); | 29 | return Promise.reject({code: 500, message: '用户名密码错误'}); |
30 | } | 30 | } |
@@ -32,6 +32,35 @@ class UserService extends Context { | @@ -32,6 +32,35 @@ class UserService extends Context { | ||
32 | }); | 32 | }); |
33 | } | 33 | } |
34 | 34 | ||
35 | + shopLogin(account, password) { | ||
36 | + return rp.get({ | ||
37 | + url: apiDomain.shop.loginInter, | ||
38 | + resolveWithFullResponse: true, | ||
39 | + qs: { | ||
40 | + user: account, | ||
41 | + password: password | ||
42 | + } | ||
43 | + }).then(response => { | ||
44 | + let sessId = '', sid = ''; | ||
45 | + | ||
46 | + _.each(response.rawHeaders, header => { | ||
47 | + let sessIdMatched = header.match(new RegExp(regSession.replace('${0}', 'PHPSESSID'))); | ||
48 | + let sidMatched = header.match(new RegExp(regSession.replace('${0}', 'connect\.sid'))); | ||
49 | + | ||
50 | + if (sessIdMatched) { | ||
51 | + sessId = sessIdMatched[1]; | ||
52 | + } | ||
53 | + if (sidMatched) { | ||
54 | + sid = sidMatched[1]; | ||
55 | + } | ||
56 | + }); | ||
57 | + return { | ||
58 | + PHPSESSID: sessId, | ||
59 | + 'connect.sid': sid | ||
60 | + }; | ||
61 | + }); | ||
62 | + } | ||
63 | + | ||
35 | getShops(pid) { | 64 | getShops(pid) { |
36 | return this.api.get(apiDomain.platform.queryShopsByAdminPid, { | 65 | return this.api.get(apiDomain.platform.queryShopsByAdminPid, { |
37 | userId: pid | 66 | userId: pid |
-
Please register or login to post a comment