Authored by htoooth

add fix

... ... @@ -68,11 +68,11 @@ var $accountInput1 = $('#account1'),
},
$captchaSmsBtn = $('.change-captcha-sms'),
$captchaSmsTokenHideInput = $('#captcha-sms-token-hide'),
newCaptchaImg = new BrandIcoCaptcha('.sms-captcha-img-wrap').init(),
getCaptchaSmsTokenVal = function() { // 短信登录凭证
return $.trim($captchaSmsTokenHideInput.val());
},
$smsCaptchaImgWrapper = $('.sms-captcha-img-wrap'),
newCaptchaImg = new BrandIcoCaptcha('.sms-captcha-img-wrap').init(),
$smsCaptchaImgInput = $smsCaptchaImgWrapper.find('#sms-captcha-input'),
getSmsCaptchaImgVal = function() { // 短信登录图形验证码
return newCaptchaImg.getResults();
... ... @@ -109,7 +109,6 @@ var $accountTip1 = $accountInput1.siblings('.err-tip'),
$passwordTip = $passwordInput.siblings('.err-tip'),
$captchaImgTip = $captchaImgInput.siblings('.err-tip'),
$captchaSmsTip = $captchaSmsInput.siblings('.err-tip'),
$smsCaptchaImgTip = $smsCaptchaImgInput.siblings('.err-tip'),
$capsLock = $('#caps-lock');
var mailPhoneRegx = require('../common/mail-phone-regx'), // 邮箱格式验证
... ... @@ -276,7 +275,6 @@ accountChangeEvent.add(function(type) {
$captchaImgInput.val('');
$captchaSmsInput.val('');
$smsCaptchaImgInput.val('');
$captchaSmsTokenHideInput.val('');
if (type === AccountLoginData.QRCodeLogin.name) {
... ... @@ -318,7 +316,6 @@ mobileTipShowOnce.add(function() {
refreshSmsImgCallBack.add(function() {
refreshSmsCaptchaImg();
$smsCaptchaImgInput.val('');
});
/** ************************************************************************/
... ... @@ -396,13 +393,13 @@ function hideCaptchaSmsTip() {
/** ************************************************************************/
function showSmsCaptchaImgTip(msg) {
function showSmsCaptchaImgTip() {
refreshSmsImgCallBack.fire();
return errTipShow($smsCaptchaImgTip, $smsCaptchaImgInput, msg);
newCaptchaImg.showTip();
}
function hideSmsCaptchaImgTip() {
return errTipHide($smsCaptchaImgTip, $smsCaptchaImgInput);
newCaptchaImg.hideTip();
}
/** ************************************************************************/
... ... @@ -709,64 +706,8 @@ function sendCaptchaSmsAsync() {
/* 短信验证图形验证 */
/** ************************************************************************/
function smsCaptchaImgLocal() {
var captcha = getSmsCaptchaImgVal(),
err;
var defer = $.Deferred(); // eslint-disable-line
if (captcha !== '') {
if (captcha.length !== 4) {
err = '请输入长度为4字符的验证码';
defer.reject();
} else {
defer.resolve();
}
} else {
err = '请输入验证码';
defer.reject();
}
if (defer.state() === 'resolved') {
hideSmsCaptchaImgTip();
} else {
showSmsCaptchaImgTip(err);
}
return defer.promise();
}
function smsCaptchaImgAsync() {
return $.ajax({
url: '/passport/captcha/img',
type: 'POST',
data: {
verifyCode: getSmsCaptchaImgVal()
}
}).then(function(result) {
var defer = $.Deferred(); // eslint-disable-line
if (result.code === 200) {
hideSmsCaptchaImgTip();
defer.resolve();
} else {
showSmsCaptchaImgTip('验证码不正确');
defer.reject();
}
return defer.promise();
});
}
function validateSmsCaptchaImg() {
return smsCaptchaImgLocal()
.then(smsCaptchaImgAsync)
.then(hideSmsCaptchaImgTip);
return newCaptchaImg.check();
}
function refreshSmsCaptchaImg() {
... ... @@ -1141,11 +1082,6 @@ $captchaImgWrapper.on('click', '.change-captcha, .captcha-img', function() {
$captchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
});
// 刷新短信图形验证码
$smsCaptchaImgWrapper.on('click', '.change-captcha, .captcha-img', function() {
refreshSmsCaptchaImg();
});
// 切换登录模式:密码登录和短信登录
$PhoneLoginSwitcher.on('click', 'div', function() {
var $this = $(this),
... ...
... ... @@ -16,7 +16,7 @@ var Captcha = function(container, options) {
this.$container = $(container);
this.$imgPics = null;
this.picWidth = null;
this.$tip = this.$container.find('.img-check-tip');
this.$tip = null;
return this;
};
... ... @@ -55,6 +55,7 @@ Captcha.prototype = {
this.$container.html(this.template(data));
this.$imgPics = this.$container.find('.img-check-pic');
this.$tip = this.$container.find('.img-check-tip');
this.picWidth = this.$imgPics.width();
this.$imgPics.each(function(index, elem) {
... ... @@ -94,8 +95,6 @@ Captcha.prototype = {
var self = this;
var uri = this.refreshURI;
this.hideTip();
return $.get(uri)
.done(function(result) {
var src = result.data.images;
... ... @@ -103,17 +102,24 @@ Captcha.prototype = {
self.render({
images: src
});
self.hideTip();
})
.fail($.noop);
},
/**
* 检查二维码是否正确
* 检查是否正确
*/
check: function() {
var self = this;
var uri = this.checkURI;
if (self.getResults() === '0000') {
self.showTip();
return $.Deferred().reject().promise(); // eslint-disable-line
}
return $.post(uri, {
verifyCode: self.getResults()
}).then(function(result) {
... ... @@ -139,6 +145,7 @@ Captcha.prototype = {
$pic.css({
backgroundPosition: this.calcPosition($pic)
});
},
/**
... ... @@ -161,12 +168,24 @@ Captcha.prototype = {
return result.join('');
},
/**
* 显示错误
*/
showTip: function() {
this.$tip.removeClass('hide');
if (this.$tip) {
this.$tip.removeClass('hide');
}
return this;
},
/**
* 隐藏错误
*/
hideTip: function() {
this.$tip.addClass('hide');
if (this.$tip) {
this.$tip.addClass('hide');
}
return this;
}
};
... ...