Authored by 王水玲

短息验证码修改

... ... @@ -52,8 +52,10 @@ var secondCount = 60;
// 短信验证码只能验证一次
var isSmsCheckedSuccessFlag = false;
var currLoginType = 'PasswordLogin';
var imgIsRight = false;
var userIsRight = false;
var smsIsRight = false;
require('yoho-jquery-placeholder');
... ... @@ -141,6 +143,10 @@ function validateAccountAsync(url) {
// 整合本地和异步验证信息
function validateAccount() {
if (userIsRight) {
return $.Deferred().resolve(true).promise(); // eslint-disable-line
}
return (function() {
var defer = $.Deferred(); // eslint-disable-line
var url = '/passport/login/user';
... ... @@ -165,6 +171,7 @@ function validateAccount() {
}()).then(function() {
hideTip($phoneNumInput);
ep.emit('phone', true);
userIsRight = true;
}).fail(function() {
ep.emit('phone', false);
});
... ... @@ -192,13 +199,13 @@ function validatePasswordLocal() {
}
// 图形验证验证码
function validateCaptchaLocal() {
function validateCaptchaLocal(isSms) {
var captcha = $.trim($imgCaptchaInput.val());
var length = captcha.length;
switch (length) {
case 0:
errTip($imgCaptchaInput, '请输入验证码');
errTip($imgCaptchaInput, isSms ? '请先输入图形验证' : '请输入验证码');
ep.emit('captcha', false);
return false;
case 4:
... ... @@ -212,7 +219,7 @@ function validateCaptchaLocal() {
}
// 异步验证图片验证码
function validateCaptchaImgAsync() {
function validateCaptchaImgAsync(isSms) {
return $.ajax({
url: '/passport/images/check',
type: 'POST',
... ... @@ -223,23 +230,23 @@ function validateCaptchaImgAsync() {
if (result.code === 200) {
return true;
} else {
errTip($imgCaptchaInput, '验证码不正确');
errTip($imgCaptchaInput, isSms ? '图形验证码不正确,请重新输入' : '验证码不正确');
return false;
}
});
}
// 整合本地和异步验证信息
function validateCaptchaImg() {
if ($captchaWrap.hasClass('hide')) {
function validateCaptchaImg(isSms) {
if ($captchaWrap.hasClass('hide') || imgIsRight) {
return true;
}
return (function() {
var defer = $.Deferred(); // eslint-disable-line
if (validateCaptchaLocal()) {
validateCaptchaImgAsync().then(function(result) {
if (validateCaptchaLocal(isSms)) {
validateCaptchaImgAsync(isSms).then(function(result) {
if (result) {
defer.resolve(result);
} else {
... ... @@ -254,9 +261,12 @@ function validateCaptchaImg() {
}()).then(function() {
hideTip($imgCaptchaInput);
ep.emit('captcha', true);
imgIsRight = true;
}).fail(function() {
ep.emit('captcha', false);
refreshCaptcha();
setTimeout(function() {
refreshCaptcha();
}, 180);
});
}
... ... @@ -281,6 +291,10 @@ function throttle() {
// 验证帐号系统
function validate() {
if (userIsRight) {
return true;
}
return validateAccount().then(function(result) {
if (result) {
return throttle();
... ... @@ -317,6 +331,10 @@ $phoneNumInput.on('focus', function() {
validate();
});
$phoneNumInput.on('input', function() {
userIsRight = false;
});
$('[placeholder]').placeholder();
// 改变选择图标
... ... @@ -372,6 +390,10 @@ $imgCaptchaInput.on('blur', function() {
hideTip($imgCaptchaInput);
});
$imgCaptchaInput.on('input', function() {
imgIsRight = false;
});
// 邮箱自动完成列表项点击
$emailAutoComplete.on('click', 'li', function() {
$phoneNumInput.val($(this).text()).focus();
... ... @@ -532,6 +554,10 @@ function validateCaptchaSmsAsync() {
// 整合本地和异步验证信息--短信验证
function validateCaptchaSms() {
if (smsIsRight) {
return true;
}
return (function() {
var defer = $.Deferred(); // eslint-disable-line
... ... @@ -551,6 +577,7 @@ function validateCaptchaSms() {
}()).then(function() {
hideTip($smsCaptchaInput);
ep.emit('smsCode', true);
smsIsRight = true;
}).fail(function() {
ep.emit('smsCode', false);
});
... ... @@ -595,14 +622,16 @@ function changeLoginType() {
$('.login-page .switch > div').off().on('click', changeLoginType);
// 短信验证码发送按钮
$smsBtn.on('click', function() {
$smsBtn.on('mousedown', function() {
// 已在发送短信时间范围内
if ($smsBtn.hasClass('second-progress')) {
return;
}
validateAccount()
.then(validateCaptchaImg)
.then(function() {
return validateCaptchaImg(true);
})
.then(function() {
disable60sSendSmsBtn();
return sendCaptchaSmsAsync();
... ...