Authored by 李奇

Merge remote-tracking branch 'origin/master' into feature/activity-image-upload

/**
*aes加解密
* @author: qi.li@yoho.cn
* @date: 2017/10/10
*/
'use strict';
const crypto = global.yoho.crypto;
/**
* uid加密
**/
const encryptUid = (uid) => {
return crypto.encryption('yoho9646abcdefgh', uid + '');
};
/**
* uid解密
**/
const decryptUid = (uid) => {
return crypto.decrypt('yoho9646abcdefgh', uid + '');
};
module.exports = {
encryptUid,
decryptUid
};
... ...
/**
* 活动【优惠券膨胀H5】
* @author: leo <qi.li@yoho.cn>
* @date: 27/09/2017
*/
const _ = require('lodash');
const aes = require('./aes');
const expModel = require('../models/coupon-expansion');
const couponExp = {
/**
* 优惠券列表
* @param req
* @param res
*/
couponList(req, res, next) {
const activityId = +req.query.activity_id;
const uid = +req.query.uid || +req.session.yh_auth_uid || '';
req.ctx(expModel).couponList(activityId, uid)
.then(result => {
// 初始券数据
req.session._EXP_COUPONS = result.data.activityCouponInfoBoList;
res.json(result);
}).catch(next);
},
/**
* 助力进度
* @param req
* @param res
*/
progress(req, res, next) {
const shareId = req.body.shareId;
let uid = req.body.uid || +req.session.yh_auth_uid;
if (shareId) {
uid = parseInt(aes.decryptUid(shareId), 10);
}
if (!uid) {
return res.json({
code: 401,
message: 'uid不能为空'
});
}
req.ctx(expModel).progress(uid).then(result => {
if (!shareId) {
result.data.shareId = aes.encryptUid(uid); // 分享标识;
}
// 活动结束标志
let endTime = result.data.end_time;
let timestamp = Date.parse(new Date()) / 1000;
result.data.isExpired = timestamp > endTime;
res.json(result);
}).catch(next);
},
/**
* 生成分享标识
* @param req
* @param res
*/
getShareId(req, res) {
req.ctx(expModel).progress(+req.session.yh_auth_uid)
.then(result => {
res.json(result);
});
},
/**
* 领取优惠券
* @param req
* @param res
*/
receiveCoupon(req, res, next) {
let uid = +req.body.uid;
let isApp = req.body.isApp;
let users = req.session._EXP_COUPONS_GET_USERS || [];
// app登录后领券
if (isApp && uid) {
// 已领取
if (users.indexOf(uid) > -1) {
return res.json({
code: 301,
data: {
url: '//huodong.yoho.cn/coupon-expansion/progress.html'
},
message: '重复领券,重定向'
});
}
const coupons = req.session._EXP_COUPONS;
let promises = _.map(_.filter(coupons, cp => !cp.user_send), item => {
return req.ctx(expModel).getCoupon(uid, item.couponId);
});
if (promises.length) {
Promise.all(promises).then(() => {
_.each(coupons, item => {
item.user_send = true;
});
users.push(uid);
req.session._EXP_COUPONS = coupons;
req.session._EXP_COUPONS_GET_USERS = users;
return res.json({
code: 301,
data: {
url: '//huodong.yoho.cn/coupon-expansion/progress.html'
},
message: '领取优惠券成功,重定向'
});
}).catch(next);
} else {
res.json({
code: 301,
data: {
url: '//huodong.yoho.cn/coupon-expansion/progress.html'
},
message: '用户已经领过优惠券,重定向'
});
}
return;
}
// 有货h5授权登录
let yhAuth = req.session.yh_auth_logged;
if (yhAuth) {
res.json({
code: 200,
message: '优惠券授权登录后即已成功领取'
});
} else {
res.json({
code: 401,
message: '请登录'
});
}
},
/**
* 有货登录成功
* @param req
* @param res
*/
yhLoginSuccess(req, res, next) {
const uid = req.query.yh_uid;
const coupons = req.session._EXP_COUPONS;
req.session.yh_auth_uid = uid;
req.session.yh_auth_logged = true;
let promises = _.map(_.filter(coupons, cp => !cp.user_send), item => {
return req.ctx(expModel).getCoupon(uid, item.couponId);
});
Promise.all(promises).then(() => {
// 设置优惠券状态
_.each(coupons, item => {
item.user_send = true;
});
req.session._EXP_COUPONS = coupons;
// 进度页
res.status(301).redirect('//huodong.yoho.cn/coupon-expansion/progress.html');
}).catch(next);
},
/**
* 助力好友
* @param req
* @param res
*/
friendHelp(req, res, next) {
const uid = parseInt(aes.decryptUid(req.body.shareId), 10);
const params = Object.assign({}, req.session._THIRD_LOGIN_INFO);
const logKey = uid + params.openId;
const helpLog = req.session._HELP_LOG || [];
if (helpLog.indexOf(logKey) > -1) {
return res.json({
code: 509,
message: '已经助力过了'
});
}
if (uid && params.openId) {
params.uid = uid;
req.ctx(expModel).friendHelp(params)
.then(result => {
helpLog.push(logKey);
req.session._HELP_LOG = helpLog;
res.json(result);
}).catch(next);
}
if (!uid || !params.openId) {
res.json({
code: 400,
message: '助力参数缺失'
});
}
}
};
module.exports = couponExp;
... ...
/**
* 活动【优惠券膨胀H5】
* @author: leo <qi.li@yoho.cn>
* @date: 27/09/2017
*/
const express = require('express');
const app = express();
app.use(require('./router'));
module.exports = app;
... ...
/**
* 活动【优惠券膨胀H5】
* @author: leo <qi.li@yoho.cn>
* @date: 27/09/2017
*/
class expModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
couponList(activityId, uid) {
return this.get({
data: {
method: 'app.activity.getActivityUserDesc',
activity_id: activityId,
uid
},
api: global.yoho.API,
param: {code: 200}
});
}
getCoupon(uid, couponId) {
return this.get({
data: {
method: 'app.promotion.getCoupon',
uid,
couponId
},
api: global.yoho.API
});
}
friendHelp({ uid, source, openId, nickname, headIcon }) {
return this.get({
data: {
method: 'app.activity.friendhelp',
uid,
source,
open_id: openId,
nick_name: nickname,
head_ico: headIcon
},
api: global.yoho.API
});
}
progress(uid) {
return this.get({
data: {
uid,
method: 'app.activity.friendhelplog'
},
api: global.yoho.API,
param: {code: 200}
});
}
}
module.exports = expModel;
... ...
/**
* 活动【优惠券膨胀H5】
* @author: leo <qi.li@yoho.cn>
* @date: 27/09/2017
*/
const express = require('express');
const router = express.Router(); // eslint-disable-line
const couponExp = require('./controllers/coupon-expansion');
router.get('/couponExp/couponList', couponExp.couponList);
router.post('/couponExp/receiveCoupon', couponExp.receiveCoupon);
router.post('/couponExp/progress', couponExp.progress);
router.get('/couponExp/yhLoginSuccess', couponExp.yhLoginSuccess);
router.post('/couponExp/friendHelp', couponExp.friendHelp);
module.exports = router;
... ...
... ... @@ -8,8 +8,8 @@
<title>YOHO!Activity Admin</title>
{{#if devEnv}}
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/css/{{module}}.{{page}}.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5002/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5002/css/{{module}}.{{page}}.css?t={{startTime}}">
{{^}}
<link rel="stylesheet" media="all" href="/yoho-activity-platform/{{version}}/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="/yoho-activity-platform/{{version}}/css/{{module}}.{{page}}.css?t={{startTime}}">
... ... @@ -46,8 +46,8 @@
</div>
</div>
{{#if devEnv}}
<script src="//{{devHost}}:5001/libs.js"></script>
<script src="//{{devHost}}:5001/js/{{module}}.{{page}}.js"></script>
<script src="//{{devHost}}:5002/libs.js"></script>
<script src="//{{devHost}}:5002/js/{{module}}.{{page}}.js"></script>
{{^}}
<script src="/yoho-activity-platform/{{version}}/libs.js?t={{startTime}}"></script>
<script src="/yoho-activity-platform/{{version}}/js/{{module}}.{{page}}.js?t={{startTime}}"></script>
... ...
/**
* passport 验证策略注册
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/5/31
*/
'use strict';
const passport = require('passport');
const WeixinStrategy = require('passport-weixin');
const SinaStrategy = require('passport-sina').Strategy;
const QQStrategy = require('passport-qq').Strategy;
const config = global.yoho.config;
let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : config.siteUrl;
let weChatUrl = `${siteUrl}/passport/login/wechat/callback`;
let sinaUrl = `${siteUrl}/passport/login/sina/callback`;
// wechat 登录
passport.use('weixin', new WeixinStrategy({
clientID: 'wx75e5a7c0c88e45c2',
clientSecret: 'ce21ae4a3f93852279175a167e54509b',
callbackURL: `//m.yohobuy.com/passport/login/wechat/redirect?redirectUrl=${weChatUrl}`,
requireState: true,
authorizationURL: 'https://open.weixin.qq.com/connect/oauth2/authorize',
scope: 'snsapi_userinfo'
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
// sina 登录
passport.use('sina', new SinaStrategy({
clientID: '3739328910',
clientSecret: '9d44cded26d048e23089e5e975c93df1',
callbackURL: `//m.yohobuy.com/passport/login/sina/redirect?redirectUrl=${sinaUrl}`,
requireState: false
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
// qq 登录
passport.use('qq', new QQStrategy({
clientID: '100229394',
clientSecret: 'c0af9c29e0900813028c2ccb42021792',
callbackURL: `${siteUrl}/passport/login/qq/callback`,
requireState: false
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
... ...
'use strict';
const _ = require('lodash');
const passport = require('passport');
const uuid = require('uuid');
const helpers = global.yoho.helpers;
const log = global.yoho.logger;
const config = global.yoho.config;
const utils = global.yoho.utils;
const AuthHelper = require('../models/auth-helper');
const loginPage = `${config.siteUrl}/signin.html`;
function doPassportCallback(openId, nickname, headIcon, source, req, res) { // eslint-disable-line
if (openId && nickname && source) {
req.session._THIRD_LOGIN_INFO = {
openId,
nickname,
headIcon,
source
};
// 第三方登录
req.session._THIRD_LOGIN = true;
req.session._THIRD_LOGIN_SOURCE = source;
res.status(301).redirect(`${req.session.cbUrl}&auth_cb=true`);
} else {
return Promise.reject('missing third party login openId or nickname');
}
}
const common = {
beforeLogin: (req, res, next) => {
if (req.session.passwordWeak) {
return res.redirect('/passport/password/resetpage');
}
let refer = req.query.refer;
if (!refer) {
refer = req.get('Referer') || req.cookies.refer;
}
refer = utils.yoho.refererLimit(refer);
refer && !/signin|login|passport/.test(refer) && res.cookie('refer', encodeURI(refer), {
domain: 'yohobuy.com'
});
let from = req.query.from;
if (from) {
res.cookie('from', from, {
domain: 'yohobuy.com',
expires: new Date(Date.now() + 10 * 60 * 1000)
});
}
if (req.yoho.isApp) {
return next({
code: 401,
message: 'weblogin',
refer
});
}
next();
},
weixinCheck: (req, res, next) => {
let passLogin = _.get(req, 'cookies._WX_PASS_LOGIN', false);
if (req.yoho.isWechat && !passLogin) {
return res.redirect(helpers.urlFormat('/passport/login/wechat', {
refer: req.query.refer || req.get('Referer') || '/'
}));
}
next();
},
clearCookie: (req, res, next) => {
res.clearCookie('_SESSION_KEY', {
domain: 'yohobuy.com'
});
res.clearCookie('_UID', {
domain: 'yohobuy.com'
});
res.clearCookie('_TOKEN', {
domain: 'yohobuy.com'
});
if (req.session2 && req.session2.reset) {
req.session2.reset();
}
if (req.session && req.session.regenerate) {
return req.session.regenerate(() => {
return next();
});
}
},
isLoginUser: (req, res, next) => {
// 微信里边已经登录的时候,不再跳转登录
if (req.user.uid) {
AuthHelper.profile(req.user.uid).then(function(result) {
if (result.code !== 200) {
return next();
}
let refer = req.query.refer || decodeURI(req.cookies.refer) || config.siteUrl;
if (/sign|login/.test(refer)) {
refer = `${config.siteUrl}/home`;
}
refer = utils.yoho.refererLimit(refer);
return res.redirect(refer);
}).catch(() => {
return next();
});
} else {
return next();
}
},
check: (req, res) => {
let refer = req.query.refer;
// 短信推广的链接强制检查登录
if (req.user.uid) {
AuthHelper.profile(req.user.uid).then(function(result) {
if (result && result.code === 200) {
return res.redirect(refer);
}
return res.redirect(helpers.urlFormat('/signin.html', {
refer: refer
}));
}).catch(() => {
return res.redirect(helpers.urlFormat('/signin.html', {
refer: refer
}));
});
} else {
return res.redirect(helpers.urlFormat('/signin.html', {
refer: refer
}));
}
}
};
const wechat = {
login: (req, res, next) => {
req.session.originalUrl = 'true';
req.session.authState = uuid.v4();
req.session.cbUrl = req.query.cbUrl;
return passport.authenticate('weixin', {
state: req.session.authState
})(req, res, next);
},
callback: (req, res) => {
const openId = req.query.openId;
const nickname = req.query.nickname;
const headIcon = req.query.headImg;
doPassportCallback(openId, nickname, headIcon, 'wechat', req, res);
}
};
const sina = {
login: (req, res, next) => {
req.session.originalUrl = 'true';
req.session.authState = uuid.v4();
req.session.cbUrl = req.query.cbUrl;
return passport.authenticate('sina', {
state: req.session.authState
})(req, res, next);
},
callback: (req, res) => {
const openId = req.query.openId;
const nickname = req.query.nickname;
const headIcon = req.query.headImg;
doPassportCallback(openId, nickname, headIcon, 'sina', req, res);
}
};
const qq = {
login: (req, res, next) => {
req.session.originalUrl = 'true';
req.session.authState = uuid.v4();
req.session.cbUrl = req.query.cbUrl;
return passport.authenticate('qq', {
state: req.session.authState
})(req, res, next);
},
callback: (req, res, next) => {
if (req.session && req.session.authState && req.session.authState === req.query.state) {
passport.authenticate('qq', (err, user) => {
if (err) {
log.error(`qq authenticate error : ${JSON.stringify(err)}`);
return res.json({
code: 500,
message: 'authenticate error'
});
}
let nickname = user.nickname;
let openId = user.id;
let headIcon = user._json.figureurl_qq_2 || user._json.figureurl_2;
doPassportCallback(openId, nickname, headIcon, 'qq', req, res);
})(req, res, next);
} else {
log.error('Auth State Mismatch:' + req.originalUrl);
return res.redirect(loginPage);
}
}
};
exports.common = common;
exports.wechat = wechat;
exports.sina = sina;
exports.qq = qq;
... ...
... ... @@ -5,7 +5,13 @@
*/
const express = require('express');
const app = express();
var passport = require('passport');
app.use(require('./router'));
require('./auth');
app.use(passport.initialize());
app.use(passport.session());
module.exports = app;
... ...
... ... @@ -7,10 +7,25 @@
const express = require('express');
const sms = require('./controllers/sms');
const user = require('./controllers/user');
const login = require('./controllers/login');
const router = express.Router(); // eslint-disable-line
// SMS 短信
router.post('/sms/sendCode', sms.beforeSend, sms.sendCode);
router.post('/sms/checkCode', sms.checkCode, user.userInfo);
// 第三方登录
// wechat
router.get('/login/wechat', login.wechat.login);
router.get('/login/wechat/callback', login.wechat.callback);
// sina
router.get('/login/sina', login.sina.login);
router.get('/login/sina/callback', login.sina.callback);
// qq
// router.get('/login/qq', login.common.beforeLogin, login.qq.login);
router.get('/login/qq', login.qq.login);
router.get('/login/qq/callback', login.qq.callback);
module.exports = router;
... ...
/**
*aes加解密
* @author: qi.li@yoho.cn
* @date: 2017/10/10
*/
'use strict';
const crypto = global.yoho.crypto;
/**
* uid加密
**/
const encryptUid = (uid) => {
return crypto.encryption('yoho9646abcdefgh', uid + '');
};
/**
* uid解密
**/
const decryptUid = (uid) => {
return crypto.decrypt('yoho9646abcdefgh', uid + '');
};
module.exports = {
encryptUid,
decryptUid
};
... ...
const moment = require('moment');
const _ = require('lodash');
const aes = require('./aes');
const {yoho} = global.yoho.utils;
const {yohoSecret} = global.yoho.config;
const UserModel = require('../models/user');
const isProd = process.env.NODE_ENV === 'production';
const user = {
getLoginUrl(req, res) {
... ... @@ -27,7 +29,7 @@ const user = {
return res.json({
code: 200,
loginUrl: `https://m.yohobuy.com/signin.html?${queryStr}`
loginUrl: `http${isProd ? 's' : ''}://m.yohobuy.com/signin.html?${queryStr}`
});
},
loginLog(req, res, next) {
... ... @@ -63,6 +65,26 @@ const user = {
return res.json({code: 200});
}).catch(next);
},
/**
* 有货用户基础信息
* @param req
* @param res
* @param next
*/
userBaseInfo(req, res, next) {
let uid = req.body.uid;
let encryptUid = req.body.encryptUid;
if (encryptUid) {
uid = parseInt(aes.decryptUid(encryptUid), 10);
}
return req.ctx(UserModel).userBaseInfo(uid)
.then(result => {
return res.json(result);
}).catch(next);
}
};
... ...
... ... @@ -18,6 +18,15 @@ class UserModel extends global.yoho.BaseModel {
}
);
}
userBaseInfo(uid) {
return this.get({
data: {
uid,
method: 'app.passport.getUserBase'
},
api: global.yoho.API
});
}
}
module.exports = UserModel;
... ...
... ... @@ -9,5 +9,6 @@ const user = require('./controllers/user');
router.get('/getLoginUrl', user.getLoginUrl);
router.post('/loginLog', user.loginLog);
router.post('/getUserBaseInfo', user.userBaseInfo);
module.exports = router;
... ...
... ... @@ -3,8 +3,8 @@ const path = require('path');
const info = {
host: '127.0.0.1',
port: 5001,
publicPath: 'http://127.0.0.1:5001/'
port: 5002,
publicPath: 'http://127.0.0.1:5002/'
};
try {
... ...
... ... @@ -14,6 +14,7 @@ module.exports = {
app: 'h5',
appVersion: '5.8.0', // 调用api的版本
port: 6006,
siteUrl: '//action.yoho.cn',
assetUrl: `/yoho-activity-platform/${pkg.version}/`,
domains: {
api: 'http://api-test3.yohops.com:9999/',
... ... @@ -22,7 +23,8 @@ module.exports = {
},
corsAllowOrigin: [
'http://localhost:8081',
'http://localhost:63342'
'http://localhost:63342',
'http://huodong.yoho.cn'
],
useCache: false,
memcache: {
... ... @@ -76,6 +78,7 @@ module.exports = {
if (isProduction) {
Object.assign(module.exports, {
appName: 'm.yohobuy.com',
siteUrl: 'https://action.yoho.cn',
assetUrl: `/yoho-activity-platform/${pkg.version}/`,
domains: {
api: 'http://api.yoho.yohoops.org/',
... ... @@ -90,6 +93,7 @@ if (isProduction) {
'https://ad.yoho.cn',
'http://feature.yoho.cn',
'https://feature.yoho.cn',
'http://huodong.yoho.cn',
'https://huodong.yoho.cn'
],
memcache: {
... ... @@ -115,6 +119,7 @@ if (isProduction) {
} else if (isTest) {
Object.assign(module.exports, {
appName: 'm.yohobuy.com for test',
siteUrl: '//action.yoho.cn',
assetUrl: `/yoho-activity-platform/${pkg.version}/`,
domains: {
api: process.env.TEST_API || 'http://api-test1.yohops.com:9999/',
... ...
... ... @@ -8,6 +8,7 @@ const admin = require('./apps/admin');
const article = require('./apps/article');
const user = require('./apps/user');
const passport = require('./apps/passport');
const activity = require('./apps/activity');
const authAdmin = require('./doraemon/middleware/authAdmin');
module.exports = app => {
... ... @@ -25,4 +26,7 @@ module.exports = app => {
// 用户相关
app.use('/user', user);
// 活动服务
app.use('/activity', activity);
};
... ...
... ... @@ -8,7 +8,7 @@
<title>YOHO!活动平台</title>
{{#if devEnv}}
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5002/css/common.css?t={{startTime}}">
{{^}}
<link rel="stylesheet" media="all"
href="/yoho-activity-platform/{{version}}/css/common.css?t={{startTime}}">
... ...
... ... @@ -8,7 +8,7 @@
<title>YOHO!活动平台</title>
{{#if devEnv}}
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5002/css/common.css?t={{startTime}}">
{{^}}
<link rel="stylesheet" media="all"
href="/yoho-activity-platform/{{version}}/css/common.css?t={{startTime}}">
... ...
... ... @@ -8,7 +8,7 @@
<title>YOHO!活动平台</title>
{{#if devEnv}}
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5002/css/common.css?t={{startTime}}">
{{^}}
<link rel="stylesheet" media="all"
href="/yoho-activity-platform/{{version}}/css/common.css?t={{startTime}}">
... ...
... ... @@ -8,8 +8,8 @@
<title>YOHO!活动平台</title>
{{#if devEnv}}
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/css/{{module}}.{{page}}.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5002/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all" href="//{{devHost}}:5002/css/{{module}}.{{page}}.css?t={{startTime}}">
{{^}}
<link rel="stylesheet" media="all" href="/yoho-activity-platform/{{version}}/css/common.css?t={{startTime}}">
<link rel="stylesheet" media="all"
... ... @@ -109,8 +109,8 @@
</div>
</div>
{{#if devEnv}}
<script src="//{{devHost}}:5001/libs.js"></script>
<script src="//{{devHost}}:5001/js/{{module}}.{{page}}.js"></script>
<script src="//{{devHost}}:5002/libs.js"></script>
<script src="//{{devHost}}:5002/js/{{module}}.{{page}}.js"></script>
{{^}}
<script src="/yoho-activity-platform/{{version}}/libs.js?t={{startTime}}"></script>
<script src="/yoho-activity-platform/{{version}}/js/{{module}}.{{page}}.js?t={{startTime}}"></script>
... ...
... ... @@ -70,7 +70,8 @@
"semver": "^5.3.0",
"serve-favicon": "^2.4.3",
"sitemap": "^1.12.0",
"uuid": "^3.0.1",
"url": "^0.11.0",
"uuid": "^3.1.0",
"whatwg-fetch": "^2.0.3",
"yoho-md5": "^2.0.0",
"yoho-node-lib": "=0.2.28",
... ...
... ... @@ -37,4 +37,4 @@ function bind_button_event() {
(() => {
bind_date_picker();
bind_button_event();
})();
\ No newline at end of file
})();
... ...
/**
*aes加解密
* @author: qi.li@yoho.cn
* @date: 2017/10/10
*/
'use strict';
const crypto = global.yoho.crypto;
/**
* uid加密
**/
const encryptUid = (uid) => {
return crypto.encryption('yoho9646abcdefgh', uid + '');
};
/**
* uid解密
**/
const decryptUid = (uid) => {
return crypto.decrypt('yoho9646abcdefgh', uid + '');
};
module.exports = {
encryptUid,
decryptUid
};
... ...
const url = require('url');
const _ = require('lodash');
const md5 = require('yoho-md5');
... ... @@ -16,6 +17,30 @@ const yoho = {
return `${k}=${v}`;
}), '&');
return md5(secretStr + clientSecret);
},
/**
* refer限制
* @param referer string
* 1. array: ['/login', '/signin'] 如果referer 在array中,将返回 /home
* 2. function: 如果返回true, 返回/home
* @return referer
*/
refererLimit(referer) { // eslint-disable-line
let result;
try {
result = decodeURIComponent(referer || '/home');
} catch (e) {
result = referer || '/home';
}
let urlObj = url.parse(result, false, true);
if (urlObj.hostname && !/(?:yohobuy\.com$)|(?:yoho\.cn$)/.test(urlObj.hostname)) {
result = '/home';
}
return result;
}
};
... ...
... ... @@ -8699,7 +8699,7 @@ uuid@^2.0.1, uuid@^2.0.2:
version "2.0.3"
resolved "http://npm.yoho.cn/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
uuid@^3.0.0, uuid@^3.0.1:
uuid@^3.0.0, uuid@^3.0.1, uuid@^3.1.0:
version "3.1.0"
resolved "http://npm.yoho.cn/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
... ...