Authored by htoooth

get shopsid

... ... @@ -36,8 +36,8 @@ export default {
this.$refs[name].validate((valid) => {
if (valid) {
this.$Message.success('提交成功!');
this.login(this.formInline.user, this.formInline.password).then((result) => {
if (result.code !== 200) {
this.login(this.formInline.user, this.formInline.password).then((userInfo) => {
if (userInfo.code !== 200) {
this.$Message.error('用户名或密码错误');
}
... ...
... ... @@ -15,6 +15,7 @@
"dependencies": {
"axios": "^0.15.3",
"babel-runtime": "^6.23.0",
"bluebird": "^3.5.0",
"body-parser": "^1.17.1",
"cookie-parser": "^1.4.3",
"express": "^4.15.2",
... ...
... ... @@ -16,11 +16,14 @@ const helpers = require('yoho-node-lib/lib/helpers');
let app = new Express();
global.Promise = require('bluebird');
global.yoho = {
logger,
helpers,
config,
apiDomain: config.apiDomain
apiDomain: config.apiDomain,
co: global.Promise.coroutine
};
app.use(session({
... ...
const Context = require('./context');
const request = require('request');
const qs = require('querystring');
const _ = require('lodash');
const config = global.yoho.config;
const logger = global.yoho.logger;
const API_ERROR = {
code: 0,
... ... @@ -17,23 +21,35 @@ class Api extends Context {
this.domain = domain;
}
get(url, data, headers) {
this.logGet(url, data);
return this.parse(() => {
return request.get({
url,
qs: data,
headers,
headers
});
});
}
logGet(url, data) {
logger.info('api call [GET]', url + '?' + qs.stringify(data));
}
post(url, data, headers) {
this.logPost(url, data);
return this.parse(() => {
return request.post({
url,
form: data,
headers,
headers
});
});
}
logPost(url, data) {
if (_.isString(data)) {
logger.info('api call [POST]', url + '?' + data);
} else {
logger.info('api call [POST]', url + '?' + qs.stringify(data));
}
}
upload() {
}
download() {
... ...
... ... @@ -4,12 +4,16 @@ const _ = require('lodash');
let domainApis = {
auth: {
login: '/service/account/v1/Profile/login'
},
shop: {
profile: '/SellerShopController/queryShopsByAdminPid'
}
};
// 域名列表
const domains = {
auth: 'http://serve.yohobuy.com'
auth: 'http://serve.yohobuy.com',
shop: 'http://192.168.102.210:8088/platform'
};
_.each(domainApis, (apis, domainName) => {
... ...
... ... @@ -6,12 +6,12 @@
'use strict';
const Context = require('../common/context');
const UserModel = require('../service/user-model');
const UserService = require('../service/user-service');
const config = global.yoho.config;
class UserController extends Context {
login(req, res, next) {
this.instance(UserModel).login(req.body.username, req.body.password).then(result => {
this.instance(UserService).login(req.body.username, req.body.password).then(result => {
if (result.code === 200) {
this.syncSession(req, res, result.data);
... ...
... ... @@ -7,10 +7,36 @@
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) {
return this.instance(Api).post(apiDomain.auth.login, JSON.stringify([username, password, 2]));
let self = this;
return co(function * () {
let userInfo = yield self.instance(Api).post(apiDomain.auth.login, JSON.stringify([username, password, 2])).catch(console.log);
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, shopInfo.data);
return {
code: 200,
data: user
};
})();
}
profile(pid) {
return this.instance(Api).get(apiDomain.shop.profile, {userId: pid});
}
}
... ...