Authored by htoooth

add login

1 .DS_Store 1 .DS_Store
2 app/build/bundle 2 app/build/bundle
3 -node_modules/  
  3 +node_modules/
  4 +
  5 +.idea
  6 +.log
@@ -45,6 +45,9 @@ module.exports = { @@ -45,6 +45,9 @@ module.exports = {
45 }, 45 },
46 headers: { 46 headers: {
47 'Access-Control-Allow-Origin': '*' 47 'Access-Control-Allow-Origin': '*'
  48 + },
  49 + proxy: {
  50 + '**': 'http://localhost:6007'
48 } 51 }
49 }, 52 },
50 module: { 53 module: {
@@ -27,6 +27,8 @@ @@ -27,6 +27,8 @@
27 27
28 <script> 28 <script>
29 29
  30 +const request = require('axios');
  31 +
30 export default { 32 export default {
31 name: 'login', 33 name: 'login',
32 beforeCreate() { 34 beforeCreate() {
@@ -41,6 +43,10 @@ export default { @@ -41,6 +43,10 @@ export default {
41 this.$Message.error('表单验证失败!'); 43 this.$Message.error('表单验证失败!');
42 } 44 }
43 }); 45 });
  46 +
  47 + request.post('/login', {username: this.formInline.user, password: this.formInline.password}).then((result) => {
  48 + console.log(result);
  49 + });
44 } 50 }
45 }, 51 },
46 data() { 52 data() {
@@ -12,13 +12,16 @@ @@ -12,13 +12,16 @@
12 "dependencies": { 12 "dependencies": {
13 "axios": "^0.15.3", 13 "axios": "^0.15.3",
14 "babel-runtime": "^6.23.0", 14 "babel-runtime": "^6.23.0",
15 - "echarts": "^3.5.1", 15 + "bluebird": "^3.5.0",
  16 + "body-parser": "^1.17.1",
  17 + "cookie-parser": "^1.4.3",
16 "express": "^4.15.2", 18 "express": "^4.15.2",
17 "express-session": "^1.15.2", 19 "express-session": "^1.15.2",
18 "iview": "^2.0.0-rc.8", 20 "iview": "^2.0.0-rc.8",
19 "lodash": "^4.17.4", 21 "lodash": "^4.17.4",
20 "moment": "^2.18.1", 22 "moment": "^2.18.1",
21 "request": "^2.81.0", 23 "request": "^2.81.0",
  24 + "request-promise": "^4.2.0",
22 "uuid": "^3.0.1", 25 "uuid": "^3.0.1",
23 "vue": "^2.2.2", 26 "vue": "^2.2.2",
24 "vue-cookie": "^1.1.4", 27 "vue-cookie": "^1.1.4",
@@ -3,10 +3,14 @@ @@ -3,10 +3,14 @@
3 * @author: feng.chen<feng.chen@yoho.cn> 3 * @author: feng.chen<feng.chen@yoho.cn>
4 * @date: 2017/04/13 4 * @date: 2017/04/13
5 */ 5 */
  6 +'use strict';
  7 +
  8 +const bodyParser = require('body-parser');
  9 +const cookieParser = require('cookie-parser');
6 const Express = require('express'); 10 const Express = require('express');
7 -const session = require('express-session') 11 +const session = require('express-session');
8 const config = require('./common/config'); 12 const config = require('./common/config');
9 -const logger = require('yoho-node-lib/lib/logger'); 13 +const logger = require('yoho-node-lib/lib/logger').init(config);
10 const helpers = require('yoho-node-lib/lib/helpers'); 14 const helpers = require('yoho-node-lib/lib/helpers');
11 const middleware = require('./middleware'); 15 const middleware = require('./middleware');
12 const controllers = require('./controllers'); 16 const controllers = require('./controllers');
@@ -23,19 +27,23 @@ app.use(session({ @@ -23,19 +27,23 @@ app.use(session({
23 secret: 'yoho!shop@manage' 27 secret: 'yoho!shop@manage'
24 })); 28 }));
25 29
  30 +app.use(bodyParser.json());
  31 +app.use(bodyParser.urlencoded({extended: false}));
  32 +app.use(cookieParser());
  33 +
26 try { 34 try {
27 // 前置中间件 35 // 前置中间件
28 - app.use(middleware.before); 36 + //app.use(middleware.before);
29 37
30 // controller 38 // controller
31 app.use(controllers); 39 app.use(controllers);
32 40
33 // // 后置中间件 41 // // 后置中间件
34 - app.use(middleware.auth);  
35 - app.use(middleware.proxy); 42 + //app.use(middleware.auth);
  43 + //app.use(middleware.proxy);
36 44
37 // // 异常捕获中间件 45 // // 异常捕获中间件
38 - app.use(middleware.error); 46 + //app.use(middleware.error);
39 } catch (err) { 47 } catch (err) {
40 logger.error(err); 48 logger.error(err);
41 } 49 }
  1 +'use strict';
  2 +
1 const Context = require('./context'); 3 const Context = require('./context');
  4 +const request = require('request-promise');
2 5
3 class Api extends Context { 6 class Api extends Context {
4 get(url, data) { 7 get(url, data) {
@@ -3,12 +3,31 @@ @@ -3,12 +3,31 @@
3 * @author: feng.chen<feng.chen@yoho.cn> 3 * @author: feng.chen<feng.chen@yoho.cn>
4 * @date: 2017/04/13 4 * @date: 2017/04/13
5 */ 5 */
  6 +
  7 +'use strict';
  8 +const _ = require('lodash');
  9 +
  10 +const isProd = process.env.NODE_ENV === 'production';
  11 +const isTest = process.env.NODE_ENV === 'test';
  12 +
  13 +//
6 const config = { 14 const config = {
7 app: 'shop-manage', 15 app: 'shop-manage',
8 - appVersion: '5.5.2', // 调用api的版本  
9 - port: 6006,  
10 - siteUrl: '//m.yohobuy.com', 16 + appVersion: '0.0.1', // 调用api的版本
  17 + port: 6007,
  18 + siteUrl: '//shop.yohobuy.com',
11 assetUrl: '//127.0.0.1:5001', 19 assetUrl: '//127.0.0.1:5001',
  20 + cookieDomain: '.yohobuy.com',
  21 + apiDomain: {
  22 + // dev
  23 + auth : 'http://serve.yohobuy.com'
  24 +
  25 + // test
  26 + //platform: 'http://10.66.100.6:8088/platform'
  27 +
  28 + // prod
  29 + //platform: 'http://172.31.23.161:8088/platform'
  30 + },
12 loggers: { 31 loggers: {
13 infoFile: { 32 infoFile: {
14 close: true, 33 close: true,
@@ -30,6 +49,25 @@ const config = { @@ -30,6 +49,25 @@ const config = {
30 prettyPrint: true 49 prettyPrint: true
31 } 50 }
32 }, 51 },
  52 + memcache: {
  53 + session: ''
  54 + }
33 }; 55 };
34 56
  57 +if (isTest) {
  58 + _.merge(config, {
  59 + apiDomain: {
  60 + platform: 'http://10.66.100.6:8088/platform'
  61 + }
  62 + })
  63 +}
  64 +
  65 +if (isProd) {
  66 + _.merge(config, {
  67 + apiDomain: {
  68 + platform: 'http://172.31.23.161:8088/platform'
  69 + }
  70 + })
  71 +}
  72 +
35 module.exports = config; 73 module.exports = config;
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 * @author: feng.chen<feng.chen@yoho.cn> 3 * @author: feng.chen<feng.chen@yoho.cn>
4 * @date: 2017/04/13 4 * @date: 2017/04/13
5 */ 5 */
  6 +'use strict'
  7 +
6 const Context = require('./context'); 8 const Context = require('./context');
7 9
8 module.exports = (Type, action) => { 10 module.exports = (Type, action) => {
  1 +'use strict';
1 2
2 const _ = require('lodash'); 3 const _ = require('lodash');
3 const getClientIp = req => { 4 const getClientIp = req => {
  1 +/**
  2 + * Created by TaoHuang on 2017/4/17.
  3 + */
  4 +
  5 +const request = require('request-promise');
  6 +const _ = require('lodash');
  7 +const qs = require('querystring');
  8 +
  9 +//const logger = global.yoho.logger;
  10 +
  11 +const _getRequest = (url, data, options = {}) => {
  12 + let opts = {
  13 + method: 'GET',
  14 + uri: url,
  15 + qs: data,
  16 + json: true
  17 + };
  18 +
  19 + opts = _.merge(opts, options);
  20 +
  21 + //let fullUrl = `${opts.uri}?${qs.stringify(opts.qs)}`;
  22 +
  23 + return request(opts)
  24 + .then((result) => {
  25 +
  26 + //logger.info('api successful [GET]', fullUrl);
  27 + return result;
  28 + })
  29 + .catch((err) => {
  30 +
  31 + //logger.warn('api error [GET]', fullUrl, err);
  32 + return {
  33 + code: 501,
  34 + message: '服务器错误'
  35 + }
  36 + });
  37 +};
  38 +
  39 +const _postRequest = (url, data, options = {}) => {
  40 + let opts = {
  41 + method: 'POST',
  42 + uri: url,
  43 + form: data,
  44 + json: true
  45 + };
  46 +
  47 + opts = _.merge(opts, options);
  48 +
  49 + //let fullUrl = `${opts.uri}?${qs.stringify(opts.form)}`;
  50 +
  51 + return request(opts)
  52 + .then((result) => {
  53 +
  54 + //logger.info('api successful [POST]', fullUrl);
  55 + return result;
  56 + })
  57 + .catch((err) => {
  58 + //logger.warn('api error [POST]', fullUrl, err);
  59 + console.log(err);
  60 + return {
  61 + code: 501,
  62 + message: '服务器错误'
  63 + }
  64 + })
  65 +};
  66 +
  67 +module.exports = {
  68 + get: _getRequest,
  69 + post: _postRequest
  70 +};
@@ -3,6 +3,9 @@ @@ -3,6 +3,9 @@
3 * @author: feng.chen<feng.chen@yoho.cn> 3 * @author: feng.chen<feng.chen@yoho.cn>
4 * @date: 2017/04/13 4 * @date: 2017/04/13
5 */ 5 */
  6 +
  7 +'use strict';
  8 +
6 const Express = require('express'); 9 const Express = require('express');
7 const UserController = require('./user'); 10 const UserController = require('./user');
8 const middleware = require('../common/middleware'); 11 const middleware = require('../common/middleware');
  1 +/**
  2 + * Created by TaoHuang on 2017/4/17.
  3 + */
  4 +
  5 +'use strict';
  6 +
  7 +const request = require('./http-utils');
  8 +const config = require('../common/config');
  9 +
  10 +module.exports.login = (ctx, username, password) => {
  11 + return request.post(
  12 + config.apiDomain.auth + '/service/account/v1/Profile/login',
  13 + JSON.stringify([username, password, 1])
  14 + );
  15 +};
@@ -3,29 +3,26 @@ @@ -3,29 +3,26 @@
3 * @author: feng.chen<feng.chen@yoho.cn> 3 * @author: feng.chen<feng.chen@yoho.cn>
4 * @date: 2017/04/13 4 * @date: 2017/04/13
5 */ 5 */
  6 +'use strict';
  7 +
6 const Context = require('../common/context'); 8 const Context = require('../common/context');
7 9
8 -// const Api = require('../common/api'); 10 +const userModel = require('./user-model');
9 11
10 class UserController extends Context { 12 class UserController extends Context {
11 - login(req, res) {  
12 - if (req.body.username === 'admin' && req.body.password === '111') {  
13 - res.session.LOGIN_UID = 1; 13 +
  14 + login(req, res, next) {
  15 + userModel.login(this.ctx, req.body.username, req.body.password).then((result) => {
14 return res.json({ 16 return res.json({
15 code: 200, 17 code: 200,
16 - message: '登录成功' 18 + data: result
17 }); 19 });
18 - }  
19 - return res.json({  
20 - code: 400,  
21 - message: '用户名密码错误'  
22 - }); 20 + }).catch(next);
23 } 21 }
24 logout(req, res) { 22 logout(req, res) {
25 - delete res.session.LOGIN_UID;  
26 return res.json({ 23 return res.json({
27 code: 200, 24 code: 200,
28 - message: '操作成功' 25 + data: '登出成功'
29 }); 26 });
30 } 27 }
31 } 28 }