Authored by 陈峰

Merge branch 'feature/weiBinding' into 'gray'

Feature/wei binding



See merge request !234
... ... @@ -12,6 +12,8 @@ const RegService = require('../models/reg-service');
const BindService = require('../models/bind-service');
const AuthHelper = require('../models/auth-helper');
const _ = require('lodash');
const config = global.yoho.config;
const moment = require('moment');
const Sources = {
qq: 'QQ',
... ... @@ -87,8 +89,14 @@ const bind = {
let openId = req.body.openId;
let areaCode = req.body.areaCode || '86';
let sourceType = req.body.sourceType;
let verify = req.body.verify || '';
let testCode = req.body.yohobuy;
if (_.isNumber(parseInt(phoneNum, 0)) && openId && areaCode && sourceType) {
if (verify) {
let captcha = _.get(req, 'session.captcha');
if ((captcha && verify.toString() === captcha) || (testCode === config.testCode)) {
BindService.bindCheck(phoneNum, openId, sourceType, areaCode).then(result => {
let data = {
code: result.code,
... ... @@ -107,6 +115,9 @@ const bind = {
data.data.isReg = result.data.is_register;
data.data.next = nextUrl;
_.set(req.session, 'bind.area', areaCode);
_.set(req.session, 'bind.phoneNum', phoneNum);
} else {
data.data = result.data;
}
... ... @@ -114,6 +125,22 @@ const bind = {
res.json(data);
}).catch(next);
} else {
let jsonData = {
code: 400,
message: '请将图片旋转到正确位置'
};
if (req.session.captchaValidCount === 0) {
req.session.captcha = null; // 验证码 用过就扔
jsonData.changeCaptcha = true;
}
return res.json(jsonData);
}
_.set(req.session, 'captcha', null);
}
} else {
res.json({
code: 400,
message: '',
... ... @@ -122,13 +149,62 @@ const bind = {
}
},
// 防刷
sendBefore: (req, res, next) => {
let count = _.get(req.session, 'bind.count');
let interval = _.get(req.session, 'bind.interval');
let now = Date.now();
// // 重发次数用完了, 会冻结5min
// // 1. 过了冻结期, count 重设为 5次
// // 2. 没过冻结期, end
// // 没有用完, 判断是否请求太频繁
let during = moment.duration(interval - now, 'ms').minutes();
let message = `请${during}分钟后再试`;
if (!count) {
if (interval > now) {
return res.json({
code: 400,
message: message,
during: Math.ceil((interval - now) / 1000)
});
} else {
_.set(req.session, 'bind.count', 5);
}
} else if (interval > now) {
return res.json({
code: 429,
message: message
});
}
next();
},
sendBindMsg: (req, res, next) => {
let phoneNum = req.body.phoneNum;
let areaCode = req.body.areaCode;
let phoneNum = _.get(req.session, 'bind.phoneNum');
let areaCode = _.get(req.session, 'bind.area');
if (req.xhr && _.isNumber(parseInt(phoneNum, 0)) && areaCode) {
BindService.sendBindMsg(areaCode, phoneNum).then(result => {
if (result && result.code) {
if (result.code === 200) {
_.set(req.session, 'bind.area', areaCode);
_.set(req.session, 'bind.phoneNum', phoneNum);
--req.session.bind.count;
if (!req.session.bind.count) {
_.set(req.session, 'bind.interval', Date.now() + 5 * 60 * 1000);
} else {
_.set(req.session, 'bind.interval', Date.now() + 60 * 1000);
}
}
res.json(result);
} else {
res.json({ code: 400, message: '', data: '' });
... ...
... ... @@ -77,7 +77,9 @@ router.get('/login/alipay/callback', login.alipay.callback);
router.get('/passport/bind/index', bind.indexPage);
router.post('/passport/bind/bindCheck', bind.bindCheck);
router.get('/passport/bind/code', bind.codePage);
router.post('/passport/bind/sendBindMsg', bind.sendBindMsg);
router.post('/passport/bind/sendBindMsg',
bind.sendBefore,
bind.sendBindMsg);
router.post('/passport/bind/bindMobile', bind.bindMobile);
router.post('/passport/bind/relateMobile', bind.relateMobile);
... ...
... ... @@ -14,6 +14,13 @@
<span id="area-code" class="area-code">{{areaCode}}</span>
<input id="phone-num" class="input phone-num" type="text" placeholder="手机号">
</div>
{{!--图片验证 start--}}
<div id="js-img-check">
<input type="hidden" name="captsrc" value="{{captsrc}}">
</div>
{{!--图片验证 end--}}
<span id="btn-next" class="btn btn-next disable row">发送验证码</span>
{{#if isWechatLogin}}
... ...
{
"name": "m-yohobuy-node",
"version": "93.4.10",
"version": "93.4.11",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ...
... ... @@ -24,6 +24,17 @@ var requested = false;
require('../../common');
var ImgCheck = require('plugin/img-check');
var imgCheck = new ImgCheck('#js-img-check', {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
imgCheck.init();
function nextStep(url, mobileNo, areaCode) {
if (requested) {
return false;
... ... @@ -31,7 +42,6 @@ function nextStep(url, mobileNo, areaCode) {
requested = true;
$btnNext.addClass('disable').html('绑定中...');
$.ajax({
type: 'POST',
url: '/passport/bind/sendBindMsg',
... ... @@ -85,7 +95,8 @@ $btnNext.on('touchstart', function() {
openId = trim($openId.val()),
nickname = trim($nickname.val()),
sourceType = trim($sourceType.val()),
areaCode = $countrySelect.val();
areaCode = $countrySelect.val(),
verify = trim(imgCheck.getResults());
if ($btnNext.hasClass('disable')) {
return;
... ... @@ -100,12 +111,11 @@ $btnNext.on('touchstart', function() {
phoneNum: pn,
openId: openId,
sourceType: sourceType,
nickname: nickname
nickname: nickname,
verify: verify
},
success: function(res) {
// console.log(res);
// res : {
// code: 'xxx',
// data: {
... ...
... ... @@ -5,6 +5,8 @@
*/
var $ = require('yoho-jquery');
require('js/common');
module.exports = function(useInRegister, useForBind, useForRelate) {
var $captcha = $('#captcha'),
$btnNext = $('#btn-next'),
... ... @@ -79,8 +81,8 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
});
}
function countDown() {
var count = 59,
function countDown(during) {
var count = during || 59,
itime;
itime = setInterval(function() {
... ... @@ -89,6 +91,11 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
clearInterval(itime);
} else {
$captchaTip.text('重新发送 (' + count-- + '秒)');
window.setCookie('count', count);
if (during && parseInt(during) !== 0) {
$captchaTip.addClass('disable');
}
}
}, 1000);
}
... ... @@ -121,6 +128,7 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
$captchaTip.text('重发验证码 (60秒)').addClass('disable');
countDown();
} else {
data.during && countDown(data.during);
// 验证码不正确,显示提示
showErrTip(data.message);
... ... @@ -148,5 +156,10 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
}
});
if (window.cookie('count') && parseInt(window.cookie('count')) > 0) {
countDown(window.cookie('count'));
} else {
countDown();
}
};
... ...