Authored by 王水玲

快捷登录修改 添加发送短信图形校验次数

... ... @@ -13,6 +13,17 @@ const helpers = global.yoho.helpers;
*/
const requiredAPI = (req, res, next) => {
let captchaToken = req.body.verifyCode || '';
let count = req.session.captchaCount;
if (count >= 4) {
return res.json({
code: 403,
captchaCount: false,
message: '该验证码已失效'
});
}
req.session.captchaCount = count + 1;
if (captchaToken === req.session.captcha) {
return next();
... ... @@ -47,6 +58,7 @@ const generate = (req, res) => {
let captcha = captchaService.generateCaptcha(width, height, length);
req.session.captcha = captcha.text;
req.session.captchaCount = 0;
res.writeHead(200, {
'Content-Type': 'image/png'
... ... @@ -60,6 +72,17 @@ const generate = (req, res) => {
*/
const requiredPost = (req, res) => {
let captchaToken = req.body.verifyCode || '';
let count = req.session.captchaCount;
if (count >= 4) {
return res.json({
code: 403,
captchaCount: false,
message: '该验证码已失效'
});
}
req.session.captchaCount = count + 1;
if (captchaToken === req.session.captcha) {
return res.json({
... ...
... ... @@ -24,7 +24,7 @@ router.post('/login/user', back.validateInputAPI, back.getUserInfoAPI);
router.get('/logout', login.local.logout);
// 手机短信验证码
router.post('/login/sms/send', login.local.sms.send); // 发短信验证码
router.post('/login/sms/send', captcha.requiredAPI, login.local.sms.send); // 发短信验证码
router.post('/login/sms/auth', login.local.sms.auth); // 验证短信验证码
router.post('/login/sms/checkuser', login.local.sms.checkUser); // 短信检查用户是否注册
... ...
... ... @@ -505,7 +505,15 @@ function sendCaptchaSmsAsync() {
url: '/passport/login/sms/send',
data: {
area: getArea(),
mobile: getMoblie()
mobile: getMoblie(),
verifyCode: $.trim($imgCaptchaInput.val())
}
}).then(function(data) {
if (data.captchaCount === false) {
errTip($imgCaptchaInput, data.message);
ep.emit('captcha', false);
refreshCaptcha();
return false;
}
});
}
... ... @@ -644,6 +652,8 @@ $smsBtn.on('mousedown', function() {
$imgCaptchaInput.off('blur'); // 点发送验证码按钮不需要执行图形验证码的blur事件 因此移除
$imgCaptchaInput.removeClass('focus');
$smsCaptchaInput.off('blur');
$smsCaptchaInput.removeClass('focus');
validateAccount()
.then(function() {
... ... @@ -656,15 +666,16 @@ $smsBtn.on('mousedown', function() {
});
// 短信验证码
$smsCaptchaInput.on('blur', function() {
function smsCaptchaInput() {
$smsCaptchaInput.removeClass('focus');
validateCaptchaSms();
}).on('focus', function() {
}
$smsCaptchaInput.on('focus', function() {
$smsCaptchaInput.addClass('focus');
hideTip($smsCaptchaInput);
$(this).off('blur').on('blur', smsCaptchaInput);
});
/** **************************************************登录事件********************************************/
// 登录
function login() {
... ...