Authored by 陈轩

fix 图形验证码 5次

... ... @@ -139,6 +139,12 @@ const setNewPasswordByEmailAPI = (req, res) => {
* 找回密码页面-通过手机号
*/
const indexMobilePage = (req, res, next) => {
_.set(req.session, 'backupCaptch.verifyResult', false);
if (req.session.captchaValidCount == null) { // eslint-disable-line
req.session.captchaValidCount = 5;
}
service.getAreaDataAsync()
.then(result => {
res.render('back/mobile', Object.assign({
... ... @@ -204,21 +210,12 @@ const sendCodeToMobileAPI = (req, res, next) => {
}
}
/* 如果设置了验证次数,验证是否合法,验证次数减 1;没有,设置验证次数 */
if (_.has(req.session, 'backupCaptch.useTime')) {
if (parseInt(req.session.backupCaptch.useTime, 10) <= 0) {
let errorCount = _.get(req.session, 'captchaValidCount', 4); // 初始1次 + 后续4次, 同一个验证码 共5次
/* 如果超过验证次数,冻结 5 分钟,更新验证次数 */
req.session.backupCaptch.timeout = Date.now() + 5 * 60 * 1000;
req.session.backupCaptch.useTime = 5;
return res.json({
code: 401,
message: '请5分钟后尝试!'
});
}
req.session.backupCaptch.useTime = req.session.backupCaptch.useTime - 1;
if (!errorCount) {
_.set(req.session, 'captchaValidCount', 4);
} else {
_.set(req.session, 'backupCaptch.useTime', 5);
--req.session.captchaValidCount;
}
if (verifyCode) {
... ... @@ -227,10 +224,17 @@ const sendCodeToMobileAPI = (req, res, next) => {
if (captcha && verifyCode.toString() === captcha) {
req.session.backupCaptch.verifyResult = true;
} else {
return res.json({
let jsonData = {
code: 400,
message: '验证码输入错误'
});
message: '请将图片旋转到正确位置'
};
if (req.session.captchaValidCount === 0) {
req.session.captcha = void 0; // 验证码 用过就扔
jsonData.changeCaptcha = true;
}
return res.json(jsonData);
}
} else if (!req.session.backupCaptch.verifyResult) {
... ...
... ... @@ -81,6 +81,10 @@ const common = {
const local = {
loginPage: (req, res) => {
if (req.session.captchaValidCount == null) { // eslint-disable-line
req.session.captchaValidCount = 5;
}
// 先清除cookie
// res.clearCookie('LE' + md5('_LOGIN_EXPIRE'), {
// domain: 'yohobuy.com'
... ... @@ -161,14 +165,28 @@ const local = {
let captchaInput = req.body.captcha;
let captchaCode = _.get(req.session, 'captcha');
delete req.session.captcha; // 用过就丢弃
let errorCount = _.get(req.session, 'captchaValidCount', 4); // 初始1次 + 后续4次, 同一个验证码 共5次
if (!errorCount) {
_.set(req.session, 'captchaValidCount', 4);
} else {
--req.session.captchaValidCount;
}
if (!captchaInput || !captchaCode || captchaInput !== captchaCode) {
res.json({
let jsonData = {
code: 400,
message: '请将图片旋转到正确方向',
captchaShow: true
});
};
if (req.session.captchaValidCount === 0) {
req.session.captcha = void 0; // 验证码 用过就扔
jsonData.changeCaptcha = true;
}
res.json(jsonData);
return;
}
... ...
... ... @@ -38,8 +38,8 @@ exports.beforeIn = (req, res, next) => {
const _step1 = (req, res, next) => {
_.set(req.session, 'smsLogin.step', 1);
if (req.session.smsLogin.count == null) { // eslint-disable-line
req.session.smsLogin.count = 5;
if (req.session.captchaValidCount == null) { // eslint-disable-line
req.session.captchaValidCount = 5;
}
let template = 'sms/login';
... ... @@ -135,6 +135,15 @@ exports.indexCheck = (req, res, next) => {
let em = new EventEmitter();
let errorCount = _.get(req.session, 'captchaValidCount', 4 - 1); // 初始1次 + 后续4次, 同一个验证码 共5次
if (!errorCount) {
_.set(req.session, 'captchaValidCount', 3);
} else {
--req.session.captchaValidCount;
}
// 校验 成功
em.on('resolve', () => {
// 1. 将信息放入 session
... ... @@ -144,14 +153,6 @@ exports.indexCheck = (req, res, next) => {
PhoneService.sendSMS(mobile, area, 1);
--req.session.smsLogin.count;
if (!req.session.smsLogin.count) {
_.set(req.session, 'smsLogin.interval', Date.now() + 5 * 60 * 1000);
} else {
_.set(req.session, 'smsLogin.interval', Date.now() + 60 * 1000);
}
res.json({
code: 200,
redirect: '/passport/sms_login?step=2'
... ... @@ -160,14 +161,18 @@ exports.indexCheck = (req, res, next) => {
// 校验 失败
em.on('reject', error => {
if (req.session.captchaValidCount === 0) {
req.session.captcha = void 0; // 验证码 用过就扔
error.changeCaptcha = true;
}
_.set(req.session, 'smsLogin.step', 1);
res.json(error);
});
req.session.captcha = void 0; // 验证码 用过就扔
// 验证
if ([area, mobile].some(val => val === '')) {
return em.emit('reject', {code: 400, message: '请填写手机号'});
... ...
... ... @@ -84,13 +84,11 @@ $btnNext.on('touchstart', function() {
showErrTip(data.message);
}
imgCheck.refresh();
data.changeCaptcha && imgCheck.refresh();
}
});
} else if (!area) {
showErrTip('出错了,请重新刷新页面');
} else if (verify === '0000') {
showErrTip('请将图片旋转到正确位置');
} else {
showErrTip('手机号格式不正确,请重新输入');
}
... ...
... ... @@ -97,13 +97,13 @@ $loginBtn.on('touchstart', function() {
return;
}
if (imgCheck.atWorking) {
captcha = imgCheck.getResults();
// if (imgCheck.atWorking) {
// captcha = imgCheck.getResults();
if (captcha === '0000') {
return tip.show(' 请将图片旋转到正确方向');
}
}
// if (captcha === '0000') {
// return tip.show(' 请将图片旋转到正确方向');
// }
// }
$loginBtn.text('正在登录...').addClass('disable');
... ... @@ -133,7 +133,7 @@ $loginBtn.on('touchstart', function() {
$loginBtn.text('登录成功').off();
} else {
if (data.captchaShow) {
imgCheck.atWorking ? imgCheck.refresh() : imgCheck.init();
imgCheck.atWorking ? (data.changeCaptcha && imgCheck.refresh()) : imgCheck.init();
}
showErrTip(data.message);
... ...
... ... @@ -94,10 +94,10 @@ page = {
return;
}
if (captcha === '0000') {
tip.show('请将图片旋转到正确位置');
return;
}
// if (captcha === '0000') {
// tip.show('请将图片旋转到正确位置');
// return;
// }
$nextBtn.prop('disabled', true);
$.post('/passport/sms_login/step1_check', {
... ... @@ -111,7 +111,7 @@ page = {
$nextBtn.off();
location.href = data.redirect;
} else {
imgCheck.refresh();
data.changeCaptcha && imgCheck.refresh();
tip.show(data.message);
}
})
... ...