Authored by htoooth

Merge branch 'hotfix/gee-captcha-check' into gray

... ... @@ -149,6 +149,14 @@ app.use((req, res, next) => {
req.session = {};
}
req.app.locals = _.merge(req.app.locals, {
pc: {
geetest: {
validation: false
}
}
});
next();
});
... ...
... ... @@ -52,12 +52,15 @@
<a href="javascript:void(0);" class="button-icon button-sliver" id="send-mobile-code"><span><i id="sendButton">发送验证码</i></span></a>
<div class="check-info"></div>
</div>
{{^}}
</li>
{{/if}}
{{#if ischeckEmail}}
<li class="user-form-li captcha-li">
<div class="safe-form-l">图形验证码:</div>
<div class="captcha-safe-form-r"></div>
</li>
{{/if}}
</li>
<li class="user-form-li">
<div class="safe-form-l">&nbsp;</div>
<div class="safe-form-r">
... ...
... ... @@ -68,14 +68,19 @@ const validateInputPage = (req, res, next) => {
req.inputInfo = result;
next();
})
.catch(()=> {
res.redirect(helpers.urlFormat('/passport/back/index'));
.catch((err) => {
res.json({
code: 400,
message: err
});
});
};
const getUserInfoAPI = (req, res, next) => {
let inputInfo = req.inputInfo;
req.session.type = 'back-step1';
service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
.then(result => {
res.json(result);
... ... @@ -93,7 +98,13 @@ const sendCodePage = (req, res, next) => {
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
.then(result => {
if (!(result.code && result.code === 200)) {
return res.redirect(helpers.urlFormat('/passport/back/index'));
return res.json({
code: 400,
message: '发送验证码错误',
data: {
refer: helpers.urlFormat('/passport/back/index')
}
});
}
return next();
... ... @@ -102,19 +113,45 @@ const sendCodePage = (req, res, next) => {
};
const saveInSession = (req, res) => {
if (req.session.type !== 'back-step1') {
return res.json({
code: 400,
message: '未验证',
data: {
refer: helpers.urlFormat('/passport/back/index')
}
});
}
req.session.type = 'back-step2';
switch (req.inputInfo.type) {
case 'email':
req.session.email = req.inputInfo.phone;
res.redirect(helpers.urlFormat('/passport/back/sendEmail'));
break;
return res.json({
code: 200,
data: {
refer: helpers.urlFormat('/passport/back/sendemail')
}
});
case 'mobile':
req.session.mobile = req.inputInfo.phone;
req.session.area = req.inputInfo.area;
req.session.captcha = req.body.verifyCode;
res.redirect(helpers.urlFormat('/passport/back/verification'));
break;
return res.json({
code: 200,
data: {
refer: helpers.urlFormat('/passport/back/verification')
}
});
default:
res.redirect(helpers.urlFormat('/passport/back/index'));
return res.json({
code: 500,
data: {
refer: helpers.urlFormat('/passport/back/index')
}
});
}
};
... ... @@ -133,6 +170,10 @@ const validateMobileAPI = (req, res, next) => {
let mobile = req.body.mobile || '';
const ERR = {code: 400, message: '验证失败'};
if (req.session.type !== 'back-step3') {
return res.json(ERR);
}
if (!passportHelper.validator.isMobile(mobile)) {
return res.json(ERR);
}
... ... @@ -157,6 +198,12 @@ const validateEmailInSession = (req, res, next) => {
};
const sendEmailPage = (req, res, next) => {
if (req.session.type !== 'back-step2') {
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
req.session.type = 'back-step3';
passportHelper.getLeftBannerAsync()
.then(result => {
res.render('back/send-email', Object.assign({
... ... @@ -215,7 +262,11 @@ const resetPasswordPage = (req, res, next) => {
};
const verifyCodeByMobilePage = (req, res, next) => {
req.session.type = 'back-step2';
if (req.session.type !== 'back-step2') {
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
req.session.type = 'back-step3';
passportHelper.getLeftBannerAsync()
.then(result => {
... ... @@ -282,7 +333,7 @@ const verifyCodeByMobileAPI = (req, res) => {
return res.json(ERR);
}
if (session.type !== 'back-step2') {
if (session.type !== 'back-step3') {
return res.json(ERR);
}
... ... @@ -359,10 +410,9 @@ const updatePwdAPI = (req, res, next) => {
const validateMobileInSession = (req, res, next) => {
req.body.mobile = req.session.mobile || '';
req.body.verifyCode = req.session.captcha || '';
req.body.area = req.session.area || '';
if (!(req.body.mobile && req.body.verifyCode)) {
if (!req.body.mobile) {
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
... ...
... ... @@ -48,7 +48,7 @@ const requiredAPI = (req, res, next) => {
if (!verifyCode) {
return res.send({
code: 405,
message: '参数失效'
message: '未输入图形验证码,请输入图形验证码'
});
}
... ... @@ -65,12 +65,12 @@ const requiredAPI = (req, res, next) => {
if (err) {
res.send({
message: '网络失败',
message: '网络失败,请刷新图形验证码',
code: 405
});
} else if (!success) {
res.send({
message: '图形验证失败',
message: '图形验证失败, 请刷新图形验证码',
code: 405
});
} else {
... ...
... ... @@ -119,7 +119,7 @@ router.get('/passport/reg/success', reg.success);
// 找回密码首页
router.get('/passport/back/index', back.index);
// 实时验证输入是否正确
// 验证输入是否正确
router.post('/passport/back/authcode',
captcha.requiredAPI,
back.validateInputAPI,
... ... @@ -127,14 +127,12 @@ router.post('/passport/back/authcode',
// 提交按钮邮件API
router.post('/passport/back/email',
captcha.requiredPage,
back.validateInputPage,
back.sendCodePage,
back.saveInSession);
// 提交按钮手机API
// 提交按钮手机AP
router.post('/passport/back/mobile',
captcha.requiredPage,
back.validateInputPage,
back.sendCodePage,
back.saveInSession);
... ...
... ... @@ -17,14 +17,14 @@ module.exports = {
cookieDomain: '.yohobuy.com',
domains: {
// test3
// singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
// prod
singleApi: 'http://single.yoho.cn/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
//singleApi: 'http://single.yoho.cn/',
//api: 'http://api.yoho.cn/',
//service: 'http://service.yoho.cn/',
// gray
// singleApi: 'http://single.gray.yohops.com/',
... ...
... ... @@ -193,12 +193,6 @@ function checkAllForm() {
arr[key] = checkForm($(item));
});
if (captcha.getResults() !== '') {
arr.push(true);
} else {
arr.push(false);
}
if (arr.indexOf(false) >= 0) {
return false;
} else {
... ...
... ... @@ -29,6 +29,33 @@ var $cr = $('#country-code-hide'),
require('../../simple-header');
require('yoho-jquery-placeholder');
require('../../common/promise');
require('../../common');
function authcode() {
return $.ajax({
type: 'POST',
url: '/passport/back/authcode',
data: {
verifyCode: captcha.getResults(),
phoneNum: $phoneNum.val(),
area: $cr.val()
}
}).then(function(data) {
if (data.code === 200) {
$('#captcha-value').val(captcha.getResults());
return $.Deferred().resolve().promise(); //eslint-disable-line
} else if (data.code === 402) {
$accErr.removeClass('hide').find('em').text('该账号不存在');
$phoneNum.addClass('error');
captcha.refresh();
return $.Deferred().reject().promise();//eslint-disable-line
} else if (data.code === 405) {
captcha.showTip(data.message);
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
function vaPn(v) {
var pass = true,
... ... @@ -151,7 +178,27 @@ $btn.click(function(e) {
$('#captcha-value').val(captcha.getResults());
if (hasPh) {
$('#back-form').submit();
authcode().then(function() {
$.post($('#back-form').attr('action'), {
phoneNum: $('#phone-num').val(),
area: $('#country-code-hide').val()
}).then(function(result) {
if (result.code === 200) {
window.jumpUrl(result.data.refer);
return;
}
if (result.code === 405) {
captcha.showTip(result.message);
$accErr.addClass('hide');
$phoneNum.removeClass('error');
return;
}
$accErr.removeClass('hide').find('em').text(result.message);
$phoneNum.addClass('error');
});
});
}
e.preventDefault();
... ...
... ... @@ -377,7 +377,6 @@ function hidePasswordTip() {
/** ************************************************************************/
function showCaptchaSmsTip(msg) {
refreshSmsCaptchaEvent.fire();
return errTipShow($captchaSmsTip, $captchaSmsInput, msg);
}
... ... @@ -388,7 +387,6 @@ function hideCaptchaSmsTip() {
/** ************************************************************************/
function showSmsCaptchaImgTip() {
refreshSmsCaptchaEvent.fire();
smsCaptchaImg.showTip();
}
... ... @@ -599,8 +597,6 @@ function validateCaptchaSmsAsync() {
}
return defer.promise();
}).always(function() {
refreshSmsCaptchaEvent.fire();
});
}
... ... @@ -995,7 +991,7 @@ $captchaSmsBtn.on('click', function() {
.then(function() {
return sendCaptchaSmsAsync().then(function(res) {
if (res.code === 200) {
smsCaptchaImg.refresh();
smsCaptchaImg.hideTip();
return $.Deferred().resolve().promise(); // eslint-disable-line
}
... ...
... ... @@ -13,7 +13,7 @@ var $registerPage = $('.register-page'),
$pwdTip1 = $pwdTips.find('#pwd-tip1'),
$errTip = $('#err-tip'),
$registerBtn = $('#register-btn'),
captchaImage = new Captcha('#captcha-img').init();
captchaImage = new Captcha('#captcha-img', {checkURI: ''}).init();
var $sendCaptcha = $('#send-captcha'),
validateResult = [];
... ... @@ -160,10 +160,13 @@ function phoneAjaxFn(page, callback) {
// 图形验证码ajax校验
function picCaptchaAjaxFn(callback) {
validateResult[1].message = '';
validateResult[1].status = true;
$.Deferred().resolve().promise().always(callback); // eslint-disable-line
return captchaImage.check().then(function() {
validateResult[1].message = '';
validateResult[1].status = true;
}).fail(function() {
validateResult[1].message = 'err';
validateResult[1].status = false;
}).always(callback);
}
// 短信验证码ajax校验
... ... @@ -537,11 +540,21 @@ exports.init = function(page) {
verifyCode: getCaptchaImageVal()
}
}).then(function(result) {
if (result.code === 405) {
validateResult[1].message = 'err';
validateResult[1].status = false;
captchaImage.showTip(result.message);
showErrTip();
return;
}
if (result.code !== 200) {
validateResult[0].message = result.message;
validateResult[0].status = false;
showErrTip();
captchaImage.refresh();
return;
}
... ... @@ -558,7 +571,11 @@ exports.init = function(page) {
}
$sendCaptcha.val(timeSecond-- + '秒可重新发送');
}, 1000);
captchaImage.hideTip();
});
}).fail(function() {
captchaImage.refresh();
});
});
... ... @@ -569,6 +586,10 @@ exports.init = function(page) {
};
}
captchaImage.onSuccess(function() {
$sendCaptcha.trigger('click');
});
var isRegRequesting = false; // eslint-disable-line
// ajax表单提交
... ...
... ... @@ -137,7 +137,7 @@ GeeCaptcha.prototype = {
if (msg) {
this.$tip.find('em').html(msg);
} else {
this.$tip.find('em').html('请将图形验证码输入正确');
this.$tip.find('em').html('请输入正确的图形验证码');
}
if (this.$tip) {
... ...