Showing
3 changed files
with
39 additions
and
5 deletions
@@ -13,6 +13,17 @@ const helpers = global.yoho.helpers; | @@ -13,6 +13,17 @@ const helpers = global.yoho.helpers; | ||
13 | */ | 13 | */ |
14 | const requiredAPI = (req, res, next) => { | 14 | const requiredAPI = (req, res, next) => { |
15 | let captchaToken = req.body.verifyCode || ''; | 15 | let captchaToken = req.body.verifyCode || ''; |
16 | + let count = req.session.captchaCount; | ||
17 | + | ||
18 | + if (count >= 4) { | ||
19 | + return res.json({ | ||
20 | + code: 403, | ||
21 | + captchaCount: false, | ||
22 | + message: '该验证码已失效' | ||
23 | + }); | ||
24 | + } | ||
25 | + | ||
26 | + req.session.captchaCount = count + 1; | ||
16 | 27 | ||
17 | if (captchaToken === req.session.captcha) { | 28 | if (captchaToken === req.session.captcha) { |
18 | return next(); | 29 | return next(); |
@@ -47,6 +58,7 @@ const generate = (req, res) => { | @@ -47,6 +58,7 @@ const generate = (req, res) => { | ||
47 | let captcha = captchaService.generateCaptcha(width, height, length); | 58 | let captcha = captchaService.generateCaptcha(width, height, length); |
48 | 59 | ||
49 | req.session.captcha = captcha.text; | 60 | req.session.captcha = captcha.text; |
61 | + req.session.captchaCount = 0; | ||
50 | 62 | ||
51 | res.writeHead(200, { | 63 | res.writeHead(200, { |
52 | 'Content-Type': 'image/png' | 64 | 'Content-Type': 'image/png' |
@@ -60,6 +72,17 @@ const generate = (req, res) => { | @@ -60,6 +72,17 @@ const generate = (req, res) => { | ||
60 | */ | 72 | */ |
61 | const requiredPost = (req, res) => { | 73 | const requiredPost = (req, res) => { |
62 | let captchaToken = req.body.verifyCode || ''; | 74 | let captchaToken = req.body.verifyCode || ''; |
75 | + let count = req.session.captchaCount; | ||
76 | + | ||
77 | + if (count >= 4) { | ||
78 | + return res.json({ | ||
79 | + code: 403, | ||
80 | + captchaCount: false, | ||
81 | + message: '该验证码已失效' | ||
82 | + }); | ||
83 | + } | ||
84 | + | ||
85 | + req.session.captchaCount = count + 1; | ||
63 | 86 | ||
64 | if (captchaToken === req.session.captcha) { | 87 | if (captchaToken === req.session.captcha) { |
65 | return res.json({ | 88 | return res.json({ |
@@ -24,7 +24,7 @@ router.post('/login/user', back.validateInputAPI, back.getUserInfoAPI); | @@ -24,7 +24,7 @@ router.post('/login/user', back.validateInputAPI, back.getUserInfoAPI); | ||
24 | router.get('/logout', login.local.logout); | 24 | router.get('/logout', login.local.logout); |
25 | 25 | ||
26 | // 手机短信验证码 | 26 | // 手机短信验证码 |
27 | -router.post('/login/sms/send', login.local.sms.send); // 发短信验证码 | 27 | +router.post('/login/sms/send', captcha.requiredAPI, login.local.sms.send); // 发短信验证码 |
28 | router.post('/login/sms/auth', login.local.sms.auth); // 验证短信验证码 | 28 | router.post('/login/sms/auth', login.local.sms.auth); // 验证短信验证码 |
29 | router.post('/login/sms/checkuser', login.local.sms.checkUser); // 短信检查用户是否注册 | 29 | router.post('/login/sms/checkuser', login.local.sms.checkUser); // 短信检查用户是否注册 |
30 | 30 |
@@ -505,7 +505,15 @@ function sendCaptchaSmsAsync() { | @@ -505,7 +505,15 @@ function sendCaptchaSmsAsync() { | ||
505 | url: '/passport/login/sms/send', | 505 | url: '/passport/login/sms/send', |
506 | data: { | 506 | data: { |
507 | area: getArea(), | 507 | area: getArea(), |
508 | - mobile: getMoblie() | 508 | + mobile: getMoblie(), |
509 | + verifyCode: $.trim($imgCaptchaInput.val()) | ||
510 | + } | ||
511 | + }).then(function(data) { | ||
512 | + if (data.captchaCount === false) { | ||
513 | + errTip($imgCaptchaInput, data.message); | ||
514 | + ep.emit('captcha', false); | ||
515 | + refreshCaptcha(); | ||
516 | + return false; | ||
509 | } | 517 | } |
510 | }); | 518 | }); |
511 | } | 519 | } |
@@ -644,6 +652,8 @@ $smsBtn.on('mousedown', function() { | @@ -644,6 +652,8 @@ $smsBtn.on('mousedown', function() { | ||
644 | 652 | ||
645 | $imgCaptchaInput.off('blur'); // 点发送验证码按钮不需要执行图形验证码的blur事件 因此移除 | 653 | $imgCaptchaInput.off('blur'); // 点发送验证码按钮不需要执行图形验证码的blur事件 因此移除 |
646 | $imgCaptchaInput.removeClass('focus'); | 654 | $imgCaptchaInput.removeClass('focus'); |
655 | + $smsCaptchaInput.off('blur'); | ||
656 | + $smsCaptchaInput.removeClass('focus'); | ||
647 | 657 | ||
648 | validateAccount() | 658 | validateAccount() |
649 | .then(function() { | 659 | .then(function() { |
@@ -656,15 +666,16 @@ $smsBtn.on('mousedown', function() { | @@ -656,15 +666,16 @@ $smsBtn.on('mousedown', function() { | ||
656 | }); | 666 | }); |
657 | 667 | ||
658 | // 短信验证码 | 668 | // 短信验证码 |
659 | -$smsCaptchaInput.on('blur', function() { | 669 | +function smsCaptchaInput() { |
660 | $smsCaptchaInput.removeClass('focus'); | 670 | $smsCaptchaInput.removeClass('focus'); |
661 | validateCaptchaSms(); | 671 | validateCaptchaSms(); |
662 | -}).on('focus', function() { | 672 | +} |
673 | +$smsCaptchaInput.on('focus', function() { | ||
663 | $smsCaptchaInput.addClass('focus'); | 674 | $smsCaptchaInput.addClass('focus'); |
664 | hideTip($smsCaptchaInput); | 675 | hideTip($smsCaptchaInput); |
676 | + $(this).off('blur').on('blur', smsCaptchaInput); | ||
665 | }); | 677 | }); |
666 | 678 | ||
667 | - | ||
668 | /** **************************************************登录事件********************************************/ | 679 | /** **************************************************登录事件********************************************/ |
669 | // 登录 | 680 | // 登录 |
670 | function login() { | 681 | function login() { |
-
Please register or login to post a comment