Authored by htoooth

add sms

@@ -24,10 +24,9 @@ router.get('/logout.html', login.local.logout); @@ -24,10 +24,9 @@ router.get('/logout.html', login.local.logout);
24 24
25 // 本地登录 25 // 本地登录
26 // 短信验证码 26 // 短信验证码
27 -// router.post('/passport/login/sms/send', login.local.sms.send); // 发短信验证码  
28 -// router.post('/passport/login/sms/auth', login.local.sms.auth); // 验证短信验证码  
29 -// router.post('/passport/login/sms/checkuser', login.local.sms.checkUser); // 短信检查用户是否注册  
30 -router.post('/passport/login/password/checkuser', back.fakeGetUserInfoAPI);// 假的,密码登录检查用户是否注册 27 +router.post('/passport/login/sms/send', login.local.sms.send); // 发短信验证码
  28 +router.post('/passport/login/sms/auth', login.local.sms.auth); // 验证短信验证码
  29 +router.post('/passport/login/sms/checkuser', login.local.sms.checkUser); // 短信检查用户是否注册
31 30
32 // 二维码登录 31 // 二维码登录
33 router.post('/passport/login/qrcode/refresh', login.local.qrcode.refresh); // 刷新二维码 32 router.post('/passport/login/qrcode/refresh', login.local.qrcode.refresh); // 刷新二维码
@@ -27,12 +27,10 @@ @@ -27,12 +27,10 @@
27 </span> 27 </span>
28 </li> 28 </li>
29 29
30 - <li class="relative hide"> 30 + <li class="relative">
31 <div class="switch"> 31 <div class="switch">
32 <div class="left selected" data-type="PasswordLogin">普通登录</div> 32 <div class="left selected" data-type="PasswordLogin">普通登录</div>
33 - {{#if smsLogin}}  
34 <div class="right" data-type="SMSLogin">手机验证码登录</div> 33 <div class="right" data-type="SMSLogin">手机验证码登录</div>
35 - {{/if}}  
36 </div> 34 </div>
37 </li> 35 </li>
38 36
@@ -57,7 +55,6 @@ @@ -57,7 +55,6 @@
57 </span> 55 </span>
58 </li> 56 </li>
59 57
60 - {{#if smsLogin}}  
61 <li class="relative clearfix sms-login hide"> 58 <li class="relative clearfix sms-login hide">
62 <input id="account2" class="account input va" name="account2" value="{{bindMobile}}" 59 <input id="account2" class="account input va" name="account2" value="{{bindMobile}}"
63 type="text" 60 type="text"
@@ -68,6 +65,17 @@ @@ -68,6 +65,17 @@
68 </span> 65 </span>
69 </li> 66 </li>
70 67
  68 + <li class="clearfix sms-captcha-img-wrap captcha-wrap sms-login hide">
  69 + <input id="sms-captcha-input" class="input va captcha" type="text" name="captcha" placeholder="图形验证码"
  70 + autocomplete="off" maxlength="4">
  71 + <img id="sms-captcha-img" class="captcha-img" alt="">
  72 + <a class="link change-captcha">换一张</a>
  73 + <span class="err-tip hide">
  74 + <i></i>
  75 + <em></em>
  76 + </span>
  77 + </li>
  78 +
71 <li class="relative clearfix sms-login hide"> 79 <li class="relative clearfix sms-login hide">
72 <input id="captcha-sms" class="input va captcha-sms-input" type="text" name="captcha" 80 <input id="captcha-sms" class="input va captcha-sms-input" type="text" name="captcha"
73 placeholder="短信验证码" 81 placeholder="短信验证码"
@@ -78,7 +86,6 @@ @@ -78,7 +86,6 @@
78 <em></em> 86 <em></em>
79 </span> 87 </span>
80 </li> 88 </li>
81 - {{/if}}  
82 89
83 <li class="clearfix captcha-wrap hide"> 90 <li class="clearfix captcha-wrap hide">
84 <input id="captcha" class="input va captcha" type="text" name="captcha" placeholder="图形验证码" 91 <input id="captcha" class="input va captcha" type="text" name="captcha" placeholder="图形验证码"
@@ -65,7 +65,7 @@ module.exports = { @@ -65,7 +65,7 @@ module.exports = {
65 port: '4444' // influxdb port 65 port: '4444' // influxdb port
66 }, 66 },
67 console: { 67 console: {
68 - level: 'error', 68 + level: 'info',
69 colorize: 'all', 69 colorize: 'all',
70 prettyPrint: true 70 prettyPrint: true
71 } 71 }
@@ -69,6 +69,12 @@ var $accountInput1 = $('#account1'), @@ -69,6 +69,12 @@ var $accountInput1 = $('#account1'),
69 getCaptchaSmsTokenVal = function() { // 短信登录凭证 69 getCaptchaSmsTokenVal = function() { // 短信登录凭证
70 return $.trim($captchaSmsTokenHideInput.val()); 70 return $.trim($captchaSmsTokenHideInput.val());
71 }, 71 },
  72 + $smsCaptchaImgWrapper = $('.sms-captcha-img-wrap'),
  73 + $smsCaptchaImgInput = $smsCaptchaImgWrapper.find('#sms-captcha-input'),
  74 + $smsCaptchaImgPic = $smsCaptchaImgWrapper.find('#sms-captcha-img'),
  75 + getSmsCaptchaImgVal = function() { // 短信登录图形验证码
  76 + return $.trim($smsCaptchaImgInput.val());
  77 + },
72 78
73 // 区域选择 79 // 区域选择
74 $countryCodeInput = $('#country-code-hide'), 80 $countryCodeInput = $('#country-code-hide'),
@@ -101,6 +107,7 @@ var $accountTip1 = $accountInput1.siblings('.err-tip'), @@ -101,6 +107,7 @@ var $accountTip1 = $accountInput1.siblings('.err-tip'),
101 $passwordTip = $passwordInput.siblings('.err-tip'), 107 $passwordTip = $passwordInput.siblings('.err-tip'),
102 $captchaImgTip = $captchaImgInput.siblings('.err-tip'), 108 $captchaImgTip = $captchaImgInput.siblings('.err-tip'),
103 $captchaSmsTip = $captchaSmsInput.siblings('.err-tip'), 109 $captchaSmsTip = $captchaSmsInput.siblings('.err-tip'),
  110 + $smsCaptchaImgTip = $smsCaptchaImgInput.siblings('.err-tip'),
104 $capsLock = $('#caps-lock'); 111 $capsLock = $('#caps-lock');
105 112
106 var mailPhoneRegx = require('../common/mail-phone-regx'), // 邮箱格式验证 113 var mailPhoneRegx = require('../common/mail-phone-regx'), // 邮箱格式验证
@@ -109,6 +116,9 @@ var mailPhoneRegx = require('../common/mail-phone-regx'), // 邮箱格式验证 @@ -109,6 +116,9 @@ var mailPhoneRegx = require('../common/mail-phone-regx'), // 邮箱格式验证
109 // 图像验证码URL 116 // 图像验证码URL
110 var CAPTCHA_IMG_URL = '/passport/imagesNode?t='; 117 var CAPTCHA_IMG_URL = '/passport/imagesNode?t=';
111 118
  119 +// 刷新手机短信图形验证码
  120 +var refreshSmsImgCallBack = $.Callbacks(); // eslint-disable-line
  121 +
112 // 记住我符号 122 // 记住我符号
113 var checkboxSymbol = { 123 var checkboxSymbol = {
114 checked: '&#xe612;', 124 checked: '&#xe612;',
@@ -258,10 +268,13 @@ accountChangeEvent.add(function(type) { @@ -258,10 +268,13 @@ accountChangeEvent.add(function(type) {
258 hideCaptchaImgTip(); // eslint-disable-line 268 hideCaptchaImgTip(); // eslint-disable-line
259 hideCaptchaSmsTip(); // eslint-disable-line 269 hideCaptchaSmsTip(); // eslint-disable-line
260 hidePasswordTip(); // eslint-disable-line 270 hidePasswordTip(); // eslint-disable-line
  271 + hideSmsCaptchaImgTip(); // eslint-disable-line
261 272
262 $passwordInput.val(''); 273 $passwordInput.val('');
263 $captchaImgInput.val(''); 274 $captchaImgInput.val('');
  275 +
264 $captchaSmsInput.val(''); 276 $captchaSmsInput.val('');
  277 + $smsCaptchaImgInput.val('');
265 $captchaSmsTokenHideInput.val(''); 278 $captchaSmsTokenHideInput.val('');
266 279
267 if (type === AccountLoginData.QRCodeLogin.name) { 280 if (type === AccountLoginData.QRCodeLogin.name) {
@@ -274,6 +287,7 @@ accountChangeEvent.add(function(type) { @@ -274,6 +287,7 @@ accountChangeEvent.add(function(type) {
274 accountChangeEvent.add(function(type) { 287 accountChangeEvent.add(function(type) {
275 if (type === AccountLoginData.SMSLogin.name) { 288 if (type === AccountLoginData.SMSLogin.name) {
276 $accountInput2.val($accountInput1.val()); 289 $accountInput2.val($accountInput1.val());
  290 + $smsCaptchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
277 } else { 291 } else {
278 $accountInput1.val($accountInput2.val()); 292 $accountInput1.val($accountInput2.val());
279 } 293 }
@@ -287,6 +301,10 @@ mobileTipShowOnce.add(function() { @@ -287,6 +301,10 @@ mobileTipShowOnce.add(function() {
287 $deviceTips.removeClass('hide'); 301 $deviceTips.removeClass('hide');
288 }); 302 });
289 303
  304 +refreshSmsImgCallBack.add(function() {
  305 + $smsCaptchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
  306 +});
  307 +
290 /** ************************************************************************/ 308 /** ************************************************************************/
291 /* 加载自定义库 */ 309 /* 加载自定义库 */
292 /** ************************************************************************/ 310 /** ************************************************************************/
@@ -321,6 +339,7 @@ function hideAccountTip1() { @@ -321,6 +339,7 @@ function hideAccountTip1() {
321 } 339 }
322 340
323 function showAccountTip2(msg) { 341 function showAccountTip2(msg) {
  342 + refreshSmsImgCallBack.fire();
324 return errTipShow($accountTip2, $accountInput2, msg); 343 return errTipShow($accountTip2, $accountInput2, msg);
325 } 344 }
326 345
@@ -351,6 +370,7 @@ function hideCaptchaImgTip() { @@ -351,6 +370,7 @@ function hideCaptchaImgTip() {
351 /** ************************************************************************/ 370 /** ************************************************************************/
352 371
353 function showCaptchaSmsTip(msg) { 372 function showCaptchaSmsTip(msg) {
  373 + refreshSmsImgCallBack.fire();
354 return errTipShow($captchaSmsTip, $captchaSmsInput, msg); 374 return errTipShow($captchaSmsTip, $captchaSmsInput, msg);
355 } 375 }
356 376
@@ -360,6 +380,17 @@ function hideCaptchaSmsTip() { @@ -360,6 +380,17 @@ function hideCaptchaSmsTip() {
360 380
361 /** ************************************************************************/ 381 /** ************************************************************************/
362 382
  383 +function showSmsCaptchaImgTip(msg) {
  384 + refreshSmsImgCallBack.fire();
  385 + return errTipShow($smsCaptchaImgTip, $smsCaptchaImgInput, msg);
  386 +}
  387 +
  388 +function hideSmsCaptchaImgTip() {
  389 + return errTipHide($smsCaptchaImgTip, $smsCaptchaImgInput);
  390 +}
  391 +
  392 +/** ************************************************************************/
  393 +
363 function showQrCodeFailTip(msg) { 394 function showQrCodeFailTip(msg) {
364 hideQrCodeTip(); // eslint-disable-line 395 hideQrCodeTip(); // eslint-disable-line
365 $qrCodeOverLayer.addClass('qrcode-overlay-fail'); 396 $qrCodeOverLayer.addClass('qrcode-overlay-fail');
@@ -654,6 +685,70 @@ function sendCaptchaSmsAsync() { @@ -654,6 +685,70 @@ function sendCaptchaSmsAsync() {
654 } 685 }
655 686
656 /** ************************************************************************/ 687 /** ************************************************************************/
  688 +/* 短信验证图形验证 */
  689 +/** ************************************************************************/
  690 +
  691 +function smsCaptchaImgLocal() {
  692 + var captcha = getSmsCaptchaImgVal(),
  693 + err;
  694 +
  695 + var defer = $.Deferred(); // eslint-disable-line
  696 +
  697 + if (captcha !== '') {
  698 + if (captcha.length !== 4) {
  699 + err = '请输入长度为4字符的验证码';
  700 +
  701 + defer.reject();
  702 + } else {
  703 +
  704 + defer.resolve();
  705 + }
  706 + } else {
  707 + err = '请输入验证码';
  708 +
  709 + defer.reject();
  710 + }
  711 +
  712 + if (defer.state() === 'resolved') {
  713 + hideSmsCaptchaImgTip();
  714 + } else {
  715 + showSmsCaptchaImgTip(err);
  716 + }
  717 +
  718 + return defer.promise();
  719 +}
  720 +
  721 +function smsCaptchaImgAsync() {
  722 + return $.ajax({
  723 + url: '/passport/captcha/img',
  724 + type: 'POST',
  725 + data: {
  726 + verifyCode: getSmsCaptchaImgVal()
  727 + }
  728 + }).then(function(result) {
  729 + var defer = $.Deferred(); // eslint-disable-line
  730 +
  731 + if (result.code === 200) {
  732 + hideSmsCaptchaImgTip();
  733 +
  734 + defer.resolve();
  735 + } else {
  736 + showSmsCaptchaImgTip('验证码不正确');
  737 +
  738 + defer.reject();
  739 + }
  740 +
  741 + return defer.promise();
  742 + });
  743 +}
  744 +
  745 +function validateSmsCaptchaImg() {
  746 + smsCaptchaImgLocal()
  747 + .then(smsCaptchaImgAsync)
  748 + .then(hideSmsCaptchaImgTip);
  749 +}
  750 +
  751 +/** ************************************************************************/
657 /* 二维码验证 */ 752 /* 二维码验证 */
658 /** ************************************************************************/ 753 /** ************************************************************************/
659 754
@@ -753,8 +848,8 @@ function validateWithPasswordMode() { @@ -753,8 +848,8 @@ function validateWithPasswordMode() {
753 // 短信验证过程 848 // 短信验证过程
754 function validateWithSmsMode() { 849 function validateWithSmsMode() {
755 return validateAccount() 850 return validateAccount()
756 - .then(validateCaptchaSms)  
757 - .then(validateCaptchaImg); 851 + .then(validateSmsCaptchaImg)
  852 + .then(validateCaptchaSms);
758 } 853 }
759 854
760 /** ************************************************************************/ 855 /** ************************************************************************/
@@ -800,7 +895,8 @@ function prePasswordLoginWithValidate() { @@ -800,7 +895,8 @@ function prePasswordLoginWithValidate() {
800 function preSmsLoginWithValidate() { 895 function preSmsLoginWithValidate() {
801 return (function() { 896 return (function() {
802 var account = currentLogin.getAccountVal(), 897 var account = currentLogin.getAccountVal(),
803 - password = getCaptchaSmsVal(); 898 + password = getCaptchaSmsVal(),
  899 + smsImg = getSmsCaptchaImgVal();
804 900
805 var defer = $.Deferred(); // eslint-disable-line 901 var defer = $.Deferred(); // eslint-disable-line
806 902
@@ -810,6 +906,12 @@ function preSmsLoginWithValidate() { @@ -810,6 +906,12 @@ function preSmsLoginWithValidate() {
810 defer.reject(); 906 defer.reject();
811 } 907 }
812 908
  909 + if (smsImg === '') {
  910 + showSmsCaptchaImgTip('请输入图形证码');
  911 +
  912 + defer.reject();
  913 + }
  914 +
813 if (password === '') { 915 if (password === '') {
814 showCaptchaSmsTip('请输入短信验证码'); 916 showCaptchaSmsTip('请输入短信验证码');
815 917
@@ -844,7 +946,7 @@ function loginAsync() { @@ -844,7 +946,7 @@ function loginAsync() {
844 areaCode: getAreaCodeVal(), 946 areaCode: getAreaCodeVal(),
845 account: currentLogin.getAccountVal(), 947 account: currentLogin.getAccountVal(),
846 password: currentLogin.creditableToken(), 948 password: currentLogin.creditableToken(),
847 - captcha: getCaptchaImgVal(), 949 + captcha: currentLogin.type() === 'password' ? getCaptchaImgVal() : getSmsCaptchaImgVal(),
848 isRemember: getRememberMeVal(), 950 isRemember: getRememberMeVal(),
849 loginType: currentLogin.type() 951 loginType: currentLogin.type()
850 } 952 }
@@ -871,7 +973,6 @@ function loginAsync() { @@ -871,7 +973,6 @@ function loginAsync() {
871 } else if (currentLogin.type() === 'sms') { 973 } else if (currentLogin.type() === 'sms') {
872 showCaptchaSmsTip('短信验证码错误'); 974 showCaptchaSmsTip('短信验证码错误');
873 $captchaSmsInput.addClass('error').val(''); 975 $captchaSmsInput.addClass('error').val('');
874 -  
875 } else if (currentLogin.type() === 'qrcode') { 976 } else if (currentLogin.type() === 'qrcode') {
876 showQrCodeFailTip(QR_CODE_ERR.fail); 977 showQrCodeFailTip(QR_CODE_ERR.fail);
877 } 978 }
@@ -891,27 +992,6 @@ function showCaptchaImgPic() { @@ -891,27 +992,6 @@ function showCaptchaImgPic() {
891 $captchaImgWrapper.removeClass('hide'); 992 $captchaImgWrapper.removeClass('hide');
892 } 993 }
893 994
894 -// 检查有效用户,超过三次会有验证操作进行  
895 -function authUntilThreeTimesAsync() {  
896 - return $.ajax({  
897 - url: '/passport/login/account',  
898 - type: 'GET',  
899 - data: {  
900 - account: currentLogin.getAccountVal()  
901 - }  
902 - }).then(function(res) {  
903 - var defer = $.Deferred(); // eslint-disable-line  
904 -  
905 - if (res.data && res.data.needCaptcha) {  
906 - defer.resolve();  
907 - } else {  
908 - defer.reject();  
909 - }  
910 -  
911 - return defer.promise();  
912 - });  
913 -}  
914 -  
915 // 设置 refer 信息 995 // 设置 refer 信息
916 function setRefer() { 996 function setRefer() {
917 var refer = queryString().refer || '', // eslint-disable-line 997 var refer = queryString().refer || '', // eslint-disable-line
@@ -973,17 +1053,6 @@ mailAc($accountInput1, function() { @@ -973,17 +1053,6 @@ mailAc($accountInput1, function() {
973 return currentLogin.validateAccountLocal(); 1053 return currentLogin.validateAccountLocal();
974 }); 1054 });
975 1055
976 -// 短信下手机输入框失去焦点:  
977 -// 1. 本地验证格式;2.服务器检查用户是否注册;3.始终检查验证用户次数  
978 -$accountInput2.on('blur', function() {  
979 - return currentLogin.validateAccountLocal().then(function() {  
980 - return currentLogin.validateAccountAsync()  
981 - .always(function() {  
982 - return authUntilThreeTimesAsync().then(showCaptchaImgPic);  
983 - });  
984 - });  
985 -});  
986 -  
987 // 密码输入框事件 1056 // 密码输入框事件
988 $passwordInput.on('blur', function() { 1057 $passwordInput.on('blur', function() {
989 validatePasswordLocal(); 1058 validatePasswordLocal();
@@ -1007,6 +1076,19 @@ $passwordInput.on('blur', function() { @@ -1007,6 +1076,19 @@ $passwordInput.on('blur', function() {
1007 // 图像验证码输入框事件 1076 // 图像验证码输入框事件
1008 $captchaImgInput.on('blur', validateCaptchaImg); 1077 $captchaImgInput.on('blur', validateCaptchaImg);
1009 1078
  1079 +
  1080 +/** ************************************************************************/
  1081 +
  1082 +// 短信下手机输入框失去焦点:本地验证格式
  1083 +$accountInput2.on('blur', function() {
  1084 + return currentLogin.validateAccountLocal();
  1085 +});
  1086 +
  1087 +// 图形验证码失去焦点验证
  1088 +$smsCaptchaImgInput.on('blur', function() {
  1089 + validateSmsCaptchaImg();
  1090 +});
  1091 +
1010 // sms验证码输入框事件 1092 // sms验证码输入框事件
1011 $captchaSmsInput.on('blur', validateCaptchaSms); 1093 $captchaSmsInput.on('blur', validateCaptchaSms);
1012 1094
@@ -1049,6 +1131,11 @@ $captchaImgWrapper.on('click', '.change-captcha, .captcha-img', function() { @@ -1049,6 +1131,11 @@ $captchaImgWrapper.on('click', '.change-captcha, .captcha-img', function() {
1049 $captchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now()); 1131 $captchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
1050 }); 1132 });
1051 1133
  1134 +// 刷新短信图形验证码
  1135 +$smsCaptchaImgWrapper.on('click', '.change-captcha, .captcha-img', function() {
  1136 + $smsCaptchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
  1137 +});
  1138 +
1052 // 切换登录模式:密码登录和短信登录 1139 // 切换登录模式:密码登录和短信登录
1053 $PhoneLoginSwitcher.on('click', 'div', function() { 1140 $PhoneLoginSwitcher.on('click', 'div', function() {
1054 var $this = $(this), 1141 var $this = $(this),
@@ -1100,7 +1187,7 @@ $deviceSwitcher.on('click', function() { @@ -1100,7 +1187,7 @@ $deviceSwitcher.on('click', function() {
1100 } 1187 }
1101 }); 1188 });
1102 1189
1103 -// 鼠标移动到上面 1190 +// 鼠标移动到二维码上面
1104 $qrCodeHoverPanel.hover(function() { 1191 $qrCodeHoverPanel.hover(function() {
1105 $qrCodeContainer.stop(false, true).animate({left: '-=65'}, { 1192 $qrCodeContainer.stop(false, true).animate({left: '-=65'}, {
1106 complete: function() { 1193 complete: function() {