Authored by 毕凯

增强代码检查

dist/
gulpfile.js
node_modules
... ... @@ -3,25 +3,23 @@
* @author xuqi<qi.xu@yoho.cn>
* @date: 2016/3/28
*/
var express = require('express'),
path = require('path'),
exphbs = require('express-handlebars'),
bodyParser = require('body-parser');
var morgan = require('morgan'),
bodyParser = require('body-parser'),
morgan = require('morgan'),
favicon = require('serve-favicon'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
connectRedis = require('connect-redis'),
cors = require('cors');
var app = express(),
RedisStore = connectRedis(session);
var config = require('./config');
var sign = require('./library/sign');
var app = express(),
RedisStore = connectRedis(session);
// 向模板注入变量
app.locals.devEnv = app.get('env') === 'development';
app.locals.proEnv = app.get('env') === 'production';
... ...
... ... @@ -49,23 +49,28 @@ function makeSign(argument) {
// 生成API签名,调用后端接口的时候有私钥校验
exports.apiSign = function(params) {
/* eslint-disable */
var sign = packageSort(Object.assign({
'client_type': 'web',
'private_key': privateKey.web,
'app_version': '3.8.2',
'os_version': 'yohobuy:h5',
'screen_size': '720x1280',
'v': '7'
client_type: 'web',
private_key: privateKey.web,
app_version: '3.8.2',
os_version: 'yohobuy:h5',
screen_size: '720x1280',
v: '7'
}, params));
/* eslint-enable */
return Object.assign(sign, {
client_secret: makeSign(sign)
client_secret: makeSign(sign) // eslint-disable-line camelcase
});
};
// 检查签名,APP 访问 H5 页面的时候需要检查
exports.checkSign = function(params) {
var clientSecret = params.client_secret,
var clientSecret = params.client_secret, // eslint-disable-line camelcase
sortedParams;
// 忽略部分参数
... ... @@ -74,7 +79,7 @@ exports.checkSign = function(params) {
delete params.debug_data;
delete params['/api'];
params.private_key = privateKey[params.client_type];
params.private_key = privateKey[params.client_type]; // eslint-disable-line camelcase
sortedParams = packageSort(params);
return clientSecret === makeSign(sortedParams);
... ... @@ -82,7 +87,7 @@ exports.checkSign = function(params) {
// 检查签名,APP 访问 H5 页面的时候需要检查, 有可能不同于上边的签名方式
exports.webSign = function(params) {
var privateKey = 'yohobuyapp';
var webPrivateKey = 'yohobuyapp';
return params.key === md5(md5(privateKey) + params.uid);
return params.key === md5(md5(webPrivateKey) + params.uid);
};
... ...
... ... @@ -12,7 +12,10 @@ module.exports = (req, res, next) => {
if (req.isApp && !req.query.uid) {
referrer = referrer.split('?')[0];
/*eslint-disable */
loginUrl += '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + referrer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
/*eslint-enable */
return res.redirect(loginUrl); // 跳转APP登录页
} else if (!req.isApp && !req.cookies._UID) {
... ...
... ... @@ -11,9 +11,9 @@ exports.sendSingleMessage = (data) => {
var defaultParam = {
method: 'web.inbox.setSingleMessage',
type: 1,
verify_key: '',
send_uid: 0,
callback: ''
verify_key: '', // eslint-disable-line camelcase
send_uid: 0, // eslint-disable-line camelcase
callback: '' // eslint-disable-line camelcase
};
return api.post('/', Object.assign(defaultParam, data)); // 所有数据返回一个 Promise,方便 Promise.all 调用
... ...
... ... @@ -31,8 +31,8 @@ module.exports = {
})
],
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
presets: [ 'es2015' ],
plugins: [ 'transform-runtime' ]
}
};
if (process.env.NODE_ENV === 'production') {
... ...
... ... @@ -31,8 +31,8 @@ module.exports = {
})
],
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
presets: [ 'es2015' ],
plugins: [ 'transform-runtime' ]
}
};
if (process.env.NODE_ENV === 'production') {
... ...
... ... @@ -31,8 +31,8 @@ module.exports = {
})
],
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
presets: [ 'es2015' ],
plugins: [ 'transform-runtime' ]
}
};
if (process.env.NODE_ENV === 'production') {
... ...
... ... @@ -31,8 +31,8 @@ module.exports = {
})
],
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
presets: [ 'es2015' ],
plugins: [ 'transform-runtime' ]
}
};
if (process.env.NODE_ENV === 'production') {
... ...
... ... @@ -2,7 +2,7 @@ var querystring = require('querystring');
var config = require('../config');
function url(uri, param, module) {
function urlFormat(uri, param, module) {
var url = '',
SUB_DOMAIN = '.m.yohobuy.com';
... ... @@ -41,4 +41,4 @@ function url(uri, param, module) {
return url;
}
module.exports = url;
module.exports = urlFormat;
... ...