|
|
/**
|
|
|
* 登录
|
|
|
* @author: xuqi<qi.xu@yoho.cn>
|
|
|
* @date: 2015/12/11
|
|
|
*
|
|
|
* @author: tao.huang<tao.huang@yoho.cn>
|
|
|
* @date: 2016/8/29
|
|
|
*/
|
...
|
...
|
@@ -36,10 +33,16 @@ var $ = require('yoho-jquery'); |
|
|
/* 初始化变量 */
|
|
|
/**************************************************************************/
|
|
|
|
|
|
// 帐号
|
|
|
var $accountInput = $('#account'),
|
|
|
getAccountVal = function() {
|
|
|
return $.trim($accountInput.val());
|
|
|
// 密码输入帐号
|
|
|
var $accountInput1 = $('#account1'),
|
|
|
getAccountVal1 = function() {
|
|
|
return $.trim($accountInput1.val());
|
|
|
},
|
|
|
|
|
|
// 短信输入帐号
|
|
|
$accountInput2 = $('#account2'),
|
|
|
getAccountVal2 = function() {
|
|
|
return $.trim($accountInput2.val());
|
|
|
},
|
|
|
|
|
|
// 密码
|
...
|
...
|
@@ -82,7 +85,8 @@ var $accountInput = $('#account'), |
|
|
};
|
|
|
|
|
|
// 提示
|
|
|
var $accountTip = $accountInput.siblings('.err-tip'),
|
|
|
var $accountTip1 = $accountInput1.siblings('.err-tip'),
|
|
|
$accountTip2 = $accountInput2.siblings('.err-tip'),
|
|
|
$passwordTip = $passwordInput.siblings('.err-tip'),
|
|
|
$captchaImgTip = $captchaImgInput.siblings('.err-tip'),
|
|
|
$captchaSmsTip = $captchaSmsInput.siblings('.err-tip'),
|
...
|
...
|
@@ -120,17 +124,17 @@ var LoginType = { |
|
|
url: '/passport/login/password/checkuser',
|
|
|
type: 'POST',
|
|
|
data: {
|
|
|
phoneNum: getAccountVal(),
|
|
|
phoneNum: getAccountVal1(),
|
|
|
area: getAreaCodeVal()
|
|
|
}
|
|
|
}).then(function(result) {
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
hideAccountTip(); // eslint-disable-line
|
|
|
hideAccountTip1(); // eslint-disable-line
|
|
|
defer.resolve();
|
|
|
} else {
|
|
|
showAccountTip(result.message); // eslint-disable-line
|
|
|
showAccountTip1(result.message); // eslint-disable-line
|
|
|
defer.reject();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -143,7 +147,11 @@ var LoginType = { |
|
|
return 'password';
|
|
|
},
|
|
|
name: 'PasswordLogin',
|
|
|
validate: prePasswordLoginWithValidate // eslint-disable-line
|
|
|
validate: prePasswordLoginWithValidate, // eslint-disable-line
|
|
|
hideEle: '.sms-login',
|
|
|
getAccountVal: getAccountVal1, // eslint-disable-line
|
|
|
showAccountTip: showAccountTip1, // eslint-disable-line
|
|
|
hideAccountTip: hideAccountTip1 // eslint-disable-line
|
|
|
},
|
|
|
SMSLogin: {
|
|
|
ele: '.sms-login',
|
...
|
...
|
@@ -152,17 +160,17 @@ var LoginType = { |
|
|
url: '/passport/login/sms/checkuser',
|
|
|
type: 'POST',
|
|
|
data: {
|
|
|
mobile: getAccountVal(),
|
|
|
mobile: getAccountVal2(),
|
|
|
area: getAreaCodeVal()
|
|
|
}
|
|
|
}).then(function(result) {
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
hideAccountTip(); // eslint-disable-line
|
|
|
hideAccountTip2(); // eslint-disable-line
|
|
|
defer.resolve();
|
|
|
} else {
|
|
|
showAccountTip(result.message); // eslint-disable-line
|
|
|
showAccountTip2(result.message); // eslint-disable-line
|
|
|
defer.reject();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -175,7 +183,11 @@ var LoginType = { |
|
|
return 'sms';
|
|
|
},
|
|
|
name: 'SMSLogin',
|
|
|
validate: preSmsLoginWithValidate // eslint-disable-line
|
|
|
validate: preSmsLoginWithValidate, // eslint-disable-line
|
|
|
hideEle: '.password-login',
|
|
|
getAccountVal: getAccountVal2, // eslint-disable-line
|
|
|
showAccountTip: showAccountTip2, // eslint-disable-line
|
|
|
hideAccountTip: hideAccountTip2 // eslint-disable-line
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -186,7 +198,8 @@ changeLoginTypeEvent.add(function(type) { |
|
|
|
|
|
// 重置状态
|
|
|
changeLoginTypeEvent.add(function() {
|
|
|
hideAccountTip(); // eslint-disable-line
|
|
|
hideAccountTip1(); // eslint-disable-line
|
|
|
hideAccountTip2(); // eslint-disable-line
|
|
|
hideCaptchaImgTip(); // eslint-disable-line
|
|
|
hideCaptchaSmsTip(); // eslint-disable-line
|
|
|
hidePasswordTip(); // eslint-disable-line
|
...
|
...
|
@@ -197,12 +210,11 @@ changeLoginTypeEvent.add(function() { |
|
|
$captchaSmsTokenHideInput.val('');
|
|
|
});
|
|
|
|
|
|
// placeholder 变化
|
|
|
changeLoginTypeEvent.add(function(type) {
|
|
|
if (type === LoginType.SMSLogin.name) {
|
|
|
$accountInput.attr('placeholder', '手机号码');
|
|
|
$accountInput2.val($accountInput1.val());
|
|
|
} else {
|
|
|
$accountInput.attr('placeholder', '邮箱/手机号码');
|
|
|
$accountInput1.val($accountInput2.val());
|
|
|
}
|
|
|
});
|
|
|
|
...
|
...
|
@@ -230,12 +242,20 @@ function errTipHide($tip, $input) { |
|
|
|
|
|
/**************************************************************************/
|
|
|
// 帐号
|
|
|
function showAccountTip(msg) {
|
|
|
return errTipShow($accountTip, $accountInput, msg);
|
|
|
function showAccountTip1(msg) {
|
|
|
return errTipShow($accountTip1, $accountInput1, msg);
|
|
|
}
|
|
|
|
|
|
function hideAccountTip() {
|
|
|
return errTipHide($accountTip, $accountInput);
|
|
|
function hideAccountTip1() {
|
|
|
return errTipHide($accountTip1, $accountInput1);
|
|
|
}
|
|
|
|
|
|
function showAccountTip2(msg) {
|
|
|
return errTipShow($accountTip2, $accountInput2, msg);
|
|
|
}
|
|
|
|
|
|
function hideAccountTip2() {
|
|
|
return errTipHide($accountTip2, $accountInput2);
|
|
|
}
|
|
|
|
|
|
/**************************************************************************/
|
...
|
...
|
@@ -274,7 +294,7 @@ function hideCaptchaSmsTip() { |
|
|
|
|
|
// 本地验证用户输入格式
|
|
|
function validateAccountPasswordLocal() {
|
|
|
var account = getAccountVal(),
|
|
|
var account = currentLogin.getAccountVal(),
|
|
|
err;
|
|
|
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
...
|
...
|
@@ -295,16 +315,16 @@ function validateAccountPasswordLocal() { |
|
|
}
|
|
|
|
|
|
if (defer.state() === 'resolved') {
|
|
|
hideAccountTip();
|
|
|
currentLogin.hideAccountTip();
|
|
|
} else {
|
|
|
showAccountTip(err);
|
|
|
currentLogin.showAccountTip(err);
|
|
|
}
|
|
|
return defer.promise();
|
|
|
}
|
|
|
|
|
|
// 本地验证
|
|
|
// 短信验证用户输入格式
|
|
|
function validateAccountSmsLocal() {
|
|
|
var account = getAccountVal(),
|
|
|
var account = currentLogin.getAccountVal(),
|
|
|
err;
|
|
|
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
...
|
...
|
@@ -321,9 +341,9 @@ function validateAccountSmsLocal() { |
|
|
}
|
|
|
|
|
|
if (defer.state() === 'resolved') {
|
|
|
hideAccountTip();
|
|
|
currentLogin.hideAccountTip();
|
|
|
} else {
|
|
|
showAccountTip(err);
|
|
|
currentLogin.showAccountTip(err);
|
|
|
}
|
|
|
return defer.promise();
|
|
|
}
|
...
|
...
|
@@ -333,7 +353,7 @@ function validateAccountSmsLocal() { |
|
|
function validateAccount() {
|
|
|
return currentLogin.validateAccountLocal()
|
|
|
.then(currentLogin.validateAccountAsync)
|
|
|
.then(hideAccountTip);
|
|
|
.then(currentLogin.hideAccountTip);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -484,7 +504,7 @@ function validateCaptchaSmsAsync() { |
|
|
type: 'POST',
|
|
|
data: {
|
|
|
area: getAreaCodeVal(),
|
|
|
mobile: getAccountVal(),
|
|
|
mobile: currentLogin.getAccountVal(),
|
|
|
code: getCaptchaSmsVal()
|
|
|
}
|
|
|
}).then(function(result) {
|
...
|
...
|
@@ -537,13 +557,13 @@ function validateWithSmsMode() { |
|
|
// password登录之前验证
|
|
|
function prePasswordLoginWithValidate() {
|
|
|
return (function() {
|
|
|
var account = getAccountVal(),
|
|
|
var account = currentLogin.getAccountVal(),
|
|
|
password = getPasswordVal();
|
|
|
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
|
|
|
|
|
if (account === '') {
|
|
|
showAccountTip('请输入账户名');
|
|
|
showAccountTip1('请输入账户名');
|
|
|
defer.reject();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -554,7 +574,7 @@ function prePasswordLoginWithValidate() { |
|
|
|
|
|
if (account === '' && password === '') {
|
|
|
// 账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示
|
|
|
showAccountTip('请输入账户名和密码');
|
|
|
showAccountTip1('请输入账户名和密码');
|
|
|
|
|
|
$passwordTip.addClass('hide');
|
|
|
$passwordInput.addClass('error');
|
...
|
...
|
@@ -568,13 +588,13 @@ function prePasswordLoginWithValidate() { |
|
|
// sms登录之前验证
|
|
|
function preSmsLoginWithValidate() {
|
|
|
return (function() {
|
|
|
var account = getAccountVal(),
|
|
|
var account = currentLogin.getAccountVal(),
|
|
|
password = getCaptchaSmsVal();
|
|
|
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
|
|
|
|
|
if (account === '') {
|
|
|
showAccountTip('请输入手机号');
|
|
|
showAccountTip1('请输入手机号');
|
|
|
defer.reject();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -585,7 +605,7 @@ function preSmsLoginWithValidate() { |
|
|
|
|
|
if (password === '' && account === '') {
|
|
|
// 账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示
|
|
|
showAccountTip('请输入手机号和短信验证码');
|
|
|
showAccountTip1('请输入手机号和短信验证码');
|
|
|
|
|
|
$captchaSmsTip.addClass('hide');
|
|
|
$captchaSmsInput.addClass('error');
|
...
|
...
|
@@ -626,7 +646,7 @@ function sendCaptchaSmsAsync() { |
|
|
url: '/passport/login/sms/send',
|
|
|
data: {
|
|
|
area: getAreaCodeVal(),
|
|
|
mobile: getAccountVal()
|
|
|
mobile: currentLogin.getAccountVal()
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -637,7 +657,7 @@ function checkUserAuthCountAsync() { |
|
|
url: '/passport/login/account',
|
|
|
type: 'GET',
|
|
|
data: {
|
|
|
account: getAccountVal()
|
|
|
account: currentLogin.getAccountVal()
|
|
|
}
|
|
|
}).then(function(res) {
|
|
|
if (res.data && res.data.needCaptcha) {
|
...
|
...
|
@@ -658,7 +678,7 @@ function login() { |
|
|
type: 'POST',
|
|
|
data: {
|
|
|
areaCode: getAreaCodeVal(),
|
|
|
account: getAccountVal(),
|
|
|
account: currentLogin.getAccountVal(),
|
|
|
password: currentLogin.creditableToken(),
|
|
|
captcha: getCaptchaImgVal(),
|
|
|
isRemember: getRememberMeVal(),
|
...
|
...
|
@@ -730,7 +750,14 @@ $(document).on('click', function(e) { |
|
|
/**************************************************************************/
|
|
|
|
|
|
// 邮箱自动完成后失去焦点:1. 本地验证格式;2.服务器检查用户是否注册;3.检查验证用户次数
|
|
|
mailAc($accountInput, function() {
|
|
|
mailAc($accountInput1, function() {
|
|
|
return currentLogin.validateAccountLocal().then(function() {
|
|
|
return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// 短信下手机输入框失去焦点:
|
|
|
$accountInput2.on('blur', function() {
|
|
|
return currentLogin.validateAccountLocal().then(function() {
|
|
|
return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync);
|
|
|
});
|
...
|
...
|
@@ -819,7 +846,8 @@ $switchLoginType.on('click', 'div', function() { |
|
|
$this.addClass('selected');
|
|
|
$this.siblings().removeClass('selected');
|
|
|
|
|
|
$(LoginType[type].ele).removeClass('hide').siblings('.login').addClass('hide');
|
|
|
$(LoginType[type].ele).removeClass('hide');
|
|
|
$(LoginType[type].hideEle).addClass('hide');
|
|
|
});
|
|
|
|
|
|
/**************************************************************************/
|
...
|
...
|
@@ -844,7 +872,7 @@ $('input.va').on('keypress', function(e) { |
|
|
changeLoginTypeEvent.fire('PasswordLogin');
|
|
|
|
|
|
// 只带账户名的页面,密码输入获得焦点
|
|
|
if (($accountInput.val() !== '' || $accountInput.val() === $accountInput.attr('placeholder')) &&
|
|
|
if (($accountInput1.val() !== '' || $accountInput1.val() === $accountInput1.attr('placeholder')) &&
|
|
|
$passwordInput.val() === '') {
|
|
|
$passwordInput.focus();
|
|
|
}
|
...
|
...
|
|