...
|
...
|
@@ -60,7 +60,7 @@ var $accountInput = $('#account'), |
|
|
return $.trim($captchaSmsInput.val());
|
|
|
},
|
|
|
$captchaSmsBtn = $('.change-captcha-sms'),
|
|
|
$captchaSMSToken = $('#captcha-sms-token-hide'),
|
|
|
$captchaSmsTokenHideInput = $('#captcha-sms-token-hide'),
|
|
|
|
|
|
// 区域选择
|
|
|
$countryCodeInput = $('#country-code-hide'),
|
...
|
...
|
@@ -126,12 +126,14 @@ var LoginType = { |
|
|
return defer.promise();
|
|
|
});
|
|
|
},
|
|
|
validateAccountLocal: validateAccountPasswordLocal, // eslint-disable-line
|
|
|
creditableToken: function() {
|
|
|
return getPasswordVal();
|
|
|
},
|
|
|
type: function() {
|
|
|
return 'password';
|
|
|
},
|
|
|
name: 'PasswordLogin',
|
|
|
validate: prePasswordLoginWithValidate // eslint-disable-line
|
|
|
},
|
|
|
SMSLogin: {
|
...
|
...
|
@@ -158,12 +160,14 @@ var LoginType = { |
|
|
return defer.promise();
|
|
|
});
|
|
|
},
|
|
|
validateAccountLocal: validateAccountSmsLocal, // eslint-disable-line
|
|
|
creditableToken: function() {
|
|
|
return getCaptchaSmsVal();
|
|
|
return $captchaSmsTokenHideInput.val();
|
|
|
},
|
|
|
type: function() {
|
|
|
return 'sms';
|
|
|
},
|
|
|
name: 'SMSLogin',
|
|
|
validate: preSmsLoginWithValidate // eslint-disable-line
|
|
|
}
|
|
|
};
|
...
|
...
|
@@ -173,18 +177,27 @@ changeLoginTypeEvent.add(function(type) { |
|
|
currentLogin = LoginType[type];
|
|
|
});
|
|
|
|
|
|
// 清除输入状态
|
|
|
// 重置状态
|
|
|
changeLoginTypeEvent.add(function() {
|
|
|
hideAccountTip(); // eslint-disable-line
|
|
|
hideCaptchaImgTip(); // eslint-disable-line
|
|
|
hideCaptchaSmsTip(); // eslint-disable-line
|
|
|
hidePasswordTip(); // eslint-disable-line
|
|
|
|
|
|
// clear input state
|
|
|
$accountInput.val('');
|
|
|
$passwordInput.val('');
|
|
|
$captchaImgInput.val('');
|
|
|
$captchaSmsInput.val('');
|
|
|
$captchaSmsTokenHideInput.val('');
|
|
|
});
|
|
|
|
|
|
// placeholder 变化
|
|
|
changeLoginTypeEvent.add(function(type) {
|
|
|
if (type === LoginType.SMSLogin.name) {
|
|
|
$accountInput.attr('placeholder', '手机号码');
|
|
|
} else {
|
|
|
$accountInput.attr('placeholder', '邮箱/手机号码');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/**************************************************************************/
|
...
|
...
|
@@ -254,7 +267,7 @@ function hideCaptchaSmsTip() { |
|
|
/**************************************************************************/
|
|
|
|
|
|
// 本地验证用户输入格式
|
|
|
function validateAccountLocal() {
|
|
|
function validateAccountPasswordLocal() {
|
|
|
var account = getAccountVal(),
|
|
|
countryCode = getAreaCodeVal(),
|
|
|
err;
|
...
|
...
|
@@ -292,9 +305,35 @@ function validateAccountLocal() { |
|
|
return defer.promise();
|
|
|
}
|
|
|
|
|
|
function validateAccountSmsLocal() {
|
|
|
var account = getAccountVal(),
|
|
|
err;
|
|
|
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
|
|
|
|
|
if (account !== '') {
|
|
|
if (/^[0-9]+$/.test(account)) {
|
|
|
defer.resolve();
|
|
|
} else {
|
|
|
defer.reject();
|
|
|
err = '手机号码不正确,请重新输入';
|
|
|
}
|
|
|
} else {
|
|
|
err = '请输入手机号';
|
|
|
}
|
|
|
|
|
|
if (defer.state() === 'resolved') {
|
|
|
hideAccountTip();
|
|
|
} else {
|
|
|
showAccountTip(err);
|
|
|
}
|
|
|
return defer.promise();
|
|
|
}
|
|
|
|
|
|
|
|
|
// 本地验证和网络验证
|
|
|
function validateAccount() {
|
|
|
return validateAccountLocal()
|
|
|
return currentLogin.validateAccountLocal()
|
|
|
.then(currentLogin.validateAccountAsync)
|
|
|
.then(hideAccountTip);
|
|
|
}
|
...
|
...
|
@@ -434,7 +473,14 @@ function validateCaptchaSmsLocal() { |
|
|
}
|
|
|
|
|
|
// 网络验证短信验证码
|
|
|
// Note: 这里的验证码只能成功验证一次,十分钟内有效
|
|
|
function validateCaptchaSmsAsync() {
|
|
|
var smsToken = $.trim($captchaSmsTokenHideInput.val());
|
|
|
|
|
|
if (!smsToken) {
|
|
|
return $.Deferred().resolve().promise; // eslint-disable-line
|
|
|
}
|
|
|
|
|
|
return $.ajax({
|
|
|
url: '/passport/login/sms/auth',
|
|
|
type: 'POST',
|
...
|
...
|
@@ -448,10 +494,11 @@ function validateCaptchaSmsAsync() { |
|
|
|
|
|
if (result.code === 200) {
|
|
|
hideCaptchaSmsTip();
|
|
|
$captchaSMSToken.val(result.token);
|
|
|
$captchaSmsTokenHideInput.val(result.token);
|
|
|
defer.resolve();
|
|
|
} else {
|
|
|
showCaptchaSmsTip('验证码不正确');
|
|
|
$captchaSmsTokenHideInput.val('');
|
|
|
defer.reject();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -609,10 +656,9 @@ function login() { |
|
|
}
|
|
|
});
|
|
|
}).then(function(res) {
|
|
|
console.log(res);
|
|
|
if (res.code === 200) {
|
|
|
if (res.data) {
|
|
|
|
|
|
// 防止data.data为undefined时下行语句执行出错而导致脚本不能走到complete去处理authing
|
|
|
location.href = res.data.session;
|
|
|
}
|
|
|
} else {
|
...
|
...
|
@@ -670,7 +716,7 @@ $(document).on('click', function(e) { |
|
|
|
|
|
// 邮箱自动完成后失去焦点:1. 本地验证格式;2.服务器检查用户是否注册;3.检查验证用户次数
|
|
|
mailAc($accountInput, function() {
|
|
|
return validateAccountLocal().then(function() {
|
|
|
return validateAccountPasswordLocal().then(function() {
|
|
|
return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync);
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -710,7 +756,7 @@ $captchaSmsBtn.on('click', function() { |
|
|
var val = getAccountVal();
|
|
|
|
|
|
if (val === '') {
|
|
|
showAccountTip('请输入账户名');
|
|
|
showAccountTip('请输入手机号');
|
|
|
return;
|
|
|
}
|
|
|
|
...
|
...
|
|