user-service.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Created by TaoHuang on 2017/4/17.
*/
'use strict';
const Context = require('../common/context');
const Api = require('../common/api');
const apiDomain = global.yoho.apiDomain;
const co = global.yoho.co;
class loginModel extends Context {
login(username, password) {
let self = this;
return co(function * () {
let userInfo = yield self.instance(Api).post(
apiDomain.auth.login.url,
JSON.stringify([username, password, 2])
);
if (userInfo.code !== 200 || !userInfo.data.pid) {
return Promise.reject({code: 500, message: '登录服务器错误'});
}
let shopInfo = yield self.profile(userInfo.data.pid)
if (shopInfo.code !== 200) {
return Promise.reject({code: 500, message: '用户获取店铺错误'});
}
let user = Object.assign(userInfo.data, {allowedShops: shopInfo.data});
return {
code: 200,
data: user
};
})();
}
profile(pid) {
return this.instance(Api).get(apiDomain.shop.profile.url, {userId: pid});
}
}
module.exports = loginModel;