Authored by htoooth

add login

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