Showing
7 changed files
with
59 additions
and
9 deletions
@@ -36,8 +36,8 @@ export default { | @@ -36,8 +36,8 @@ export default { | ||
36 | this.$refs[name].validate((valid) => { | 36 | this.$refs[name].validate((valid) => { |
37 | if (valid) { | 37 | if (valid) { |
38 | this.$Message.success('提交成功!'); | 38 | this.$Message.success('提交成功!'); |
39 | - this.login(this.formInline.user, this.formInline.password).then((result) => { | ||
40 | - if (result.code !== 200) { | 39 | + this.login(this.formInline.user, this.formInline.password).then((userInfo) => { |
40 | + if (userInfo.code !== 200) { | ||
41 | this.$Message.error('用户名或密码错误'); | 41 | this.$Message.error('用户名或密码错误'); |
42 | } | 42 | } |
43 | 43 |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | "dependencies": { | 15 | "dependencies": { |
16 | "axios": "^0.15.3", | 16 | "axios": "^0.15.3", |
17 | "babel-runtime": "^6.23.0", | 17 | "babel-runtime": "^6.23.0", |
18 | + "bluebird": "^3.5.0", | ||
18 | "body-parser": "^1.17.1", | 19 | "body-parser": "^1.17.1", |
19 | "cookie-parser": "^1.4.3", | 20 | "cookie-parser": "^1.4.3", |
20 | "express": "^4.15.2", | 21 | "express": "^4.15.2", |
@@ -16,11 +16,14 @@ const helpers = require('yoho-node-lib/lib/helpers'); | @@ -16,11 +16,14 @@ const helpers = require('yoho-node-lib/lib/helpers'); | ||
16 | 16 | ||
17 | let app = new Express(); | 17 | let app = new Express(); |
18 | 18 | ||
19 | +global.Promise = require('bluebird'); | ||
20 | + | ||
19 | global.yoho = { | 21 | global.yoho = { |
20 | logger, | 22 | logger, |
21 | helpers, | 23 | helpers, |
22 | config, | 24 | config, |
23 | - apiDomain: config.apiDomain | 25 | + apiDomain: config.apiDomain, |
26 | + co: global.Promise.coroutine | ||
24 | }; | 27 | }; |
25 | 28 | ||
26 | app.use(session({ | 29 | app.use(session({ |
1 | const Context = require('./context'); | 1 | const Context = require('./context'); |
2 | const request = require('request'); | 2 | const request = require('request'); |
3 | +const qs = require('querystring'); | ||
4 | +const _ = require('lodash'); | ||
5 | + | ||
3 | const config = global.yoho.config; | 6 | const config = global.yoho.config; |
7 | +const logger = global.yoho.logger; | ||
4 | 8 | ||
5 | const API_ERROR = { | 9 | const API_ERROR = { |
6 | code: 0, | 10 | code: 0, |
@@ -17,23 +21,35 @@ class Api extends Context { | @@ -17,23 +21,35 @@ class Api extends Context { | ||
17 | this.domain = domain; | 21 | this.domain = domain; |
18 | } | 22 | } |
19 | get(url, data, headers) { | 23 | get(url, data, headers) { |
24 | + this.logGet(url, data); | ||
20 | return this.parse(() => { | 25 | return this.parse(() => { |
21 | return request.get({ | 26 | return request.get({ |
22 | url, | 27 | url, |
23 | qs: data, | 28 | qs: data, |
24 | - headers, | 29 | + headers |
25 | }); | 30 | }); |
26 | }); | 31 | }); |
27 | } | 32 | } |
33 | + logGet(url, data) { | ||
34 | + logger.info('api call [GET]', url + '?' + qs.stringify(data)); | ||
35 | + } | ||
28 | post(url, data, headers) { | 36 | post(url, data, headers) { |
37 | + this.logPost(url, data); | ||
29 | return this.parse(() => { | 38 | return this.parse(() => { |
30 | return request.post({ | 39 | return request.post({ |
31 | url, | 40 | url, |
32 | form: data, | 41 | form: data, |
33 | - headers, | 42 | + headers |
34 | }); | 43 | }); |
35 | }); | 44 | }); |
36 | } | 45 | } |
46 | + logPost(url, data) { | ||
47 | + if (_.isString(data)) { | ||
48 | + logger.info('api call [POST]', url + '?' + data); | ||
49 | + } else { | ||
50 | + logger.info('api call [POST]', url + '?' + qs.stringify(data)); | ||
51 | + } | ||
52 | + } | ||
37 | upload() { | 53 | upload() { |
38 | } | 54 | } |
39 | download() { | 55 | download() { |
@@ -4,12 +4,16 @@ const _ = require('lodash'); | @@ -4,12 +4,16 @@ const _ = require('lodash'); | ||
4 | let domainApis = { | 4 | let domainApis = { |
5 | auth: { | 5 | auth: { |
6 | login: '/service/account/v1/Profile/login' | 6 | login: '/service/account/v1/Profile/login' |
7 | + }, | ||
8 | + shop: { | ||
9 | + profile: '/SellerShopController/queryShopsByAdminPid' | ||
7 | } | 10 | } |
8 | }; | 11 | }; |
9 | 12 | ||
10 | // 域名列表 | 13 | // 域名列表 |
11 | const domains = { | 14 | const domains = { |
12 | - auth: 'http://serve.yohobuy.com' | 15 | + auth: 'http://serve.yohobuy.com', |
16 | + shop: 'http://192.168.102.210:8088/platform' | ||
13 | }; | 17 | }; |
14 | 18 | ||
15 | _.each(domainApis, (apis, domainName) => { | 19 | _.each(domainApis, (apis, domainName) => { |
@@ -6,12 +6,12 @@ | @@ -6,12 +6,12 @@ | ||
6 | 'use strict'; | 6 | 'use strict'; |
7 | 7 | ||
8 | const Context = require('../common/context'); | 8 | const Context = require('../common/context'); |
9 | -const UserModel = require('../service/user-model'); | 9 | +const UserService = require('../service/user-service'); |
10 | const config = global.yoho.config; | 10 | const config = global.yoho.config; |
11 | 11 | ||
12 | class UserController extends Context { | 12 | class UserController extends Context { |
13 | login(req, res, next) { | 13 | login(req, res, next) { |
14 | - this.instance(UserModel).login(req.body.username, req.body.password).then(result => { | 14 | + this.instance(UserService).login(req.body.username, req.body.password).then(result => { |
15 | if (result.code === 200) { | 15 | if (result.code === 200) { |
16 | this.syncSession(req, res, result.data); | 16 | this.syncSession(req, res, result.data); |
17 | 17 |
@@ -7,10 +7,36 @@ | @@ -7,10 +7,36 @@ | ||
7 | const Context = require('../common/context'); | 7 | const Context = require('../common/context'); |
8 | const Api = require('../common/api'); | 8 | const Api = require('../common/api'); |
9 | const apiDomain = global.yoho.apiDomain; | 9 | const apiDomain = global.yoho.apiDomain; |
10 | +const co = global.yoho.co; | ||
10 | 11 | ||
11 | class loginModel extends Context { | 12 | class loginModel extends Context { |
12 | login(username, password) { | 13 | login(username, password) { |
13 | - return this.instance(Api).post(apiDomain.auth.login, JSON.stringify([username, password, 2])); | 14 | + let self = this; |
15 | + | ||
16 | + return co(function * () { | ||
17 | + let userInfo = yield self.instance(Api).post(apiDomain.auth.login, JSON.stringify([username, password, 2])).catch(console.log); | ||
18 | + | ||
19 | + if (userInfo.code !== 200 || !userInfo.data.pid) { | ||
20 | + return Promise.reject({code: 500, message: '登录服务器错误'}); | ||
21 | + } | ||
22 | + | ||
23 | + let shopInfo = yield self.profile(userInfo.data.pid); | ||
24 | + | ||
25 | + if (shopInfo.code !== 200) { | ||
26 | + return Promise.reject({code: 500, message: '用户获取店铺错误'}); | ||
27 | + } | ||
28 | + | ||
29 | + let user = Object.assign(userInfo.data, shopInfo.data); | ||
30 | + | ||
31 | + return { | ||
32 | + code: 200, | ||
33 | + data: user | ||
34 | + }; | ||
35 | + })(); | ||
36 | + } | ||
37 | + | ||
38 | + profile(pid) { | ||
39 | + return this.instance(Api).get(apiDomain.shop.profile, {userId: pid}); | ||
14 | } | 40 | } |
15 | } | 41 | } |
16 | 42 |
-
Please register or login to post a comment