|
@@ -60,7 +60,7 @@ var $accountInput = $('#account'), |
|
@@ -60,7 +60,7 @@ var $accountInput = $('#account'), |
60
|
return $.trim($captchaSmsInput.val());
|
60
|
return $.trim($captchaSmsInput.val());
|
61
|
},
|
61
|
},
|
62
|
$captchaSmsBtn = $('.change-captcha-sms'),
|
62
|
$captchaSmsBtn = $('.change-captcha-sms'),
|
63
|
- $captchaSMSToken = $('#captcha-sms-token-hide'),
|
63
|
+ $captchaSmsTokenHideInput = $('#captcha-sms-token-hide'),
|
64
|
|
64
|
|
65
|
// 区域选择
|
65
|
// 区域选择
|
66
|
$countryCodeInput = $('#country-code-hide'),
|
66
|
$countryCodeInput = $('#country-code-hide'),
|
|
@@ -126,12 +126,14 @@ var LoginType = { |
|
@@ -126,12 +126,14 @@ var LoginType = { |
126
|
return defer.promise();
|
126
|
return defer.promise();
|
127
|
});
|
127
|
});
|
128
|
},
|
128
|
},
|
|
|
129
|
+ validateAccountLocal: validateAccountPasswordLocal, // eslint-disable-line
|
129
|
creditableToken: function() {
|
130
|
creditableToken: function() {
|
130
|
return getPasswordVal();
|
131
|
return getPasswordVal();
|
131
|
},
|
132
|
},
|
132
|
type: function() {
|
133
|
type: function() {
|
133
|
return 'password';
|
134
|
return 'password';
|
134
|
},
|
135
|
},
|
|
|
136
|
+ name: 'PasswordLogin',
|
135
|
validate: prePasswordLoginWithValidate // eslint-disable-line
|
137
|
validate: prePasswordLoginWithValidate // eslint-disable-line
|
136
|
},
|
138
|
},
|
137
|
SMSLogin: {
|
139
|
SMSLogin: {
|
|
@@ -158,12 +160,14 @@ var LoginType = { |
|
@@ -158,12 +160,14 @@ var LoginType = { |
158
|
return defer.promise();
|
160
|
return defer.promise();
|
159
|
});
|
161
|
});
|
160
|
},
|
162
|
},
|
|
|
163
|
+ validateAccountLocal: validateAccountSmsLocal, // eslint-disable-line
|
161
|
creditableToken: function() {
|
164
|
creditableToken: function() {
|
162
|
- return getCaptchaSmsVal();
|
165
|
+ return $captchaSmsTokenHideInput.val();
|
163
|
},
|
166
|
},
|
164
|
type: function() {
|
167
|
type: function() {
|
165
|
return 'sms';
|
168
|
return 'sms';
|
166
|
},
|
169
|
},
|
|
|
170
|
+ name: 'SMSLogin',
|
167
|
validate: preSmsLoginWithValidate // eslint-disable-line
|
171
|
validate: preSmsLoginWithValidate // eslint-disable-line
|
168
|
}
|
172
|
}
|
169
|
};
|
173
|
};
|
|
@@ -173,18 +177,27 @@ changeLoginTypeEvent.add(function(type) { |
|
@@ -173,18 +177,27 @@ changeLoginTypeEvent.add(function(type) { |
173
|
currentLogin = LoginType[type];
|
177
|
currentLogin = LoginType[type];
|
174
|
});
|
178
|
});
|
175
|
|
179
|
|
176
|
-// 清除输入状态
|
180
|
+// 重置状态
|
177
|
changeLoginTypeEvent.add(function() {
|
181
|
changeLoginTypeEvent.add(function() {
|
178
|
hideAccountTip(); // eslint-disable-line
|
182
|
hideAccountTip(); // eslint-disable-line
|
179
|
hideCaptchaImgTip(); // eslint-disable-line
|
183
|
hideCaptchaImgTip(); // eslint-disable-line
|
180
|
hideCaptchaSmsTip(); // eslint-disable-line
|
184
|
hideCaptchaSmsTip(); // eslint-disable-line
|
181
|
hidePasswordTip(); // eslint-disable-line
|
185
|
hidePasswordTip(); // eslint-disable-line
|
182
|
|
186
|
|
183
|
- // clear input state
|
|
|
184
|
$accountInput.val('');
|
187
|
$accountInput.val('');
|
185
|
$passwordInput.val('');
|
188
|
$passwordInput.val('');
|
186
|
$captchaImgInput.val('');
|
189
|
$captchaImgInput.val('');
|
187
|
$captchaSmsInput.val('');
|
190
|
$captchaSmsInput.val('');
|
|
|
191
|
+ $captchaSmsTokenHideInput.val('');
|
|
|
192
|
+});
|
|
|
193
|
+
|
|
|
194
|
+// placeholder 变化
|
|
|
195
|
+changeLoginTypeEvent.add(function(type) {
|
|
|
196
|
+ if (type === LoginType.SMSLogin.name) {
|
|
|
197
|
+ $accountInput.attr('placeholder', '手机号码');
|
|
|
198
|
+ } else {
|
|
|
199
|
+ $accountInput.attr('placeholder', '邮箱/手机号码');
|
|
|
200
|
+ }
|
188
|
});
|
201
|
});
|
189
|
|
202
|
|
190
|
/**************************************************************************/
|
203
|
/**************************************************************************/
|
|
@@ -254,7 +267,7 @@ function hideCaptchaSmsTip() { |
|
@@ -254,7 +267,7 @@ function hideCaptchaSmsTip() { |
254
|
/**************************************************************************/
|
267
|
/**************************************************************************/
|
255
|
|
268
|
|
256
|
// 本地验证用户输入格式
|
269
|
// 本地验证用户输入格式
|
257
|
-function validateAccountLocal() {
|
270
|
+function validateAccountPasswordLocal() {
|
258
|
var account = getAccountVal(),
|
271
|
var account = getAccountVal(),
|
259
|
countryCode = getAreaCodeVal(),
|
272
|
countryCode = getAreaCodeVal(),
|
260
|
err;
|
273
|
err;
|
|
@@ -292,9 +305,35 @@ function validateAccountLocal() { |
|
@@ -292,9 +305,35 @@ function validateAccountLocal() { |
292
|
return defer.promise();
|
305
|
return defer.promise();
|
293
|
}
|
306
|
}
|
294
|
|
307
|
|
|
|
308
|
+function validateAccountSmsLocal() {
|
|
|
309
|
+ var account = getAccountVal(),
|
|
|
310
|
+ err;
|
|
|
311
|
+
|
|
|
312
|
+ var defer = $.Deferred(); // eslint-disable-line
|
|
|
313
|
+
|
|
|
314
|
+ if (account !== '') {
|
|
|
315
|
+ if (/^[0-9]+$/.test(account)) {
|
|
|
316
|
+ defer.resolve();
|
|
|
317
|
+ } else {
|
|
|
318
|
+ defer.reject();
|
|
|
319
|
+ err = '手机号码不正确,请重新输入';
|
|
|
320
|
+ }
|
|
|
321
|
+ } else {
|
|
|
322
|
+ err = '请输入手机号';
|
|
|
323
|
+ }
|
|
|
324
|
+
|
|
|
325
|
+ if (defer.state() === 'resolved') {
|
|
|
326
|
+ hideAccountTip();
|
|
|
327
|
+ } else {
|
|
|
328
|
+ showAccountTip(err);
|
|
|
329
|
+ }
|
|
|
330
|
+ return defer.promise();
|
|
|
331
|
+}
|
|
|
332
|
+
|
|
|
333
|
+
|
295
|
// 本地验证和网络验证
|
334
|
// 本地验证和网络验证
|
296
|
function validateAccount() {
|
335
|
function validateAccount() {
|
297
|
- return validateAccountLocal()
|
336
|
+ return currentLogin.validateAccountLocal()
|
298
|
.then(currentLogin.validateAccountAsync)
|
337
|
.then(currentLogin.validateAccountAsync)
|
299
|
.then(hideAccountTip);
|
338
|
.then(hideAccountTip);
|
300
|
}
|
339
|
}
|
|
@@ -434,7 +473,14 @@ function validateCaptchaSmsLocal() { |
|
@@ -434,7 +473,14 @@ function validateCaptchaSmsLocal() { |
434
|
}
|
473
|
}
|
435
|
|
474
|
|
436
|
// 网络验证短信验证码
|
475
|
// 网络验证短信验证码
|
|
|
476
|
+// Note: 这里的验证码只能成功验证一次,十分钟内有效
|
437
|
function validateCaptchaSmsAsync() {
|
477
|
function validateCaptchaSmsAsync() {
|
|
|
478
|
+ var smsToken = $.trim($captchaSmsTokenHideInput.val());
|
|
|
479
|
+
|
|
|
480
|
+ if (!smsToken) {
|
|
|
481
|
+ return $.Deferred().resolve().promise; // eslint-disable-line
|
|
|
482
|
+ }
|
|
|
483
|
+
|
438
|
return $.ajax({
|
484
|
return $.ajax({
|
439
|
url: '/passport/login/sms/auth',
|
485
|
url: '/passport/login/sms/auth',
|
440
|
type: 'POST',
|
486
|
type: 'POST',
|
|
@@ -448,10 +494,11 @@ function validateCaptchaSmsAsync() { |
|
@@ -448,10 +494,11 @@ function validateCaptchaSmsAsync() { |
448
|
|
494
|
|
449
|
if (result.code === 200) {
|
495
|
if (result.code === 200) {
|
450
|
hideCaptchaSmsTip();
|
496
|
hideCaptchaSmsTip();
|
451
|
- $captchaSMSToken.val(result.token);
|
497
|
+ $captchaSmsTokenHideInput.val(result.token);
|
452
|
defer.resolve();
|
498
|
defer.resolve();
|
453
|
} else {
|
499
|
} else {
|
454
|
showCaptchaSmsTip('验证码不正确');
|
500
|
showCaptchaSmsTip('验证码不正确');
|
|
|
501
|
+ $captchaSmsTokenHideInput.val('');
|
455
|
defer.reject();
|
502
|
defer.reject();
|
456
|
}
|
503
|
}
|
457
|
|
504
|
|
|
@@ -609,10 +656,9 @@ function login() { |
|
@@ -609,10 +656,9 @@ function login() { |
609
|
}
|
656
|
}
|
610
|
});
|
657
|
});
|
611
|
}).then(function(res) {
|
658
|
}).then(function(res) {
|
|
|
659
|
+ console.log(res);
|
612
|
if (res.code === 200) {
|
660
|
if (res.code === 200) {
|
613
|
if (res.data) {
|
661
|
if (res.data) {
|
614
|
-
|
|
|
615
|
- // 防止data.data为undefined时下行语句执行出错而导致脚本不能走到complete去处理authing
|
|
|
616
|
location.href = res.data.session;
|
662
|
location.href = res.data.session;
|
617
|
}
|
663
|
}
|
618
|
} else {
|
664
|
} else {
|
|
@@ -670,7 +716,7 @@ $(document).on('click', function(e) { |
|
@@ -670,7 +716,7 @@ $(document).on('click', function(e) { |
670
|
|
716
|
|
671
|
// 邮箱自动完成后失去焦点:1. 本地验证格式;2.服务器检查用户是否注册;3.检查验证用户次数
|
717
|
// 邮箱自动完成后失去焦点:1. 本地验证格式;2.服务器检查用户是否注册;3.检查验证用户次数
|
672
|
mailAc($accountInput, function() {
|
718
|
mailAc($accountInput, function() {
|
673
|
- return validateAccountLocal().then(function() {
|
719
|
+ return validateAccountPasswordLocal().then(function() {
|
674
|
return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync);
|
720
|
return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync);
|
675
|
});
|
721
|
});
|
676
|
});
|
722
|
});
|
|
@@ -710,7 +756,7 @@ $captchaSmsBtn.on('click', function() { |
|
@@ -710,7 +756,7 @@ $captchaSmsBtn.on('click', function() { |
710
|
var val = getAccountVal();
|
756
|
var val = getAccountVal();
|
711
|
|
757
|
|
712
|
if (val === '') {
|
758
|
if (val === '') {
|
713
|
- showAccountTip('请输入账户名');
|
759
|
+ showAccountTip('请输入手机号');
|
714
|
return;
|
760
|
return;
|
715
|
}
|
761
|
}
|
716
|
|
762
|
|