Authored by 郭成尧

username-passport-login-verify-control

@@ -128,11 +128,13 @@ const local = { @@ -128,11 +128,13 @@ const local = {
128 // 设置登录有效时间30分钟, 防机器刷,cache不稳定,改为cookie 128 // 设置登录有效时间30分钟, 防机器刷,cache不稳定,改为cookie
129 // res.cookie('LE' + md5('_LOGIN_EXPIRE'), (new Date()).getTime() / 1000 + 1800); 129 // res.cookie('LE' + md5('_LOGIN_EXPIRE'), (new Date()).getTime() / 1000 + 1800);
130 130
  131 + // 170406 账户密码方式登录可以选择是否开启验证码,默认开关是关闭状态,此时开启验证码,开关开启,无需验证
  132 + let captchaShow = _.get(req.app.locals.wap, 'close.loginValidation', false);
131 133
132 res.render('login', { 134 res.render('login', {
133 width750: true, 135 width750: true,
134 loginIndex: true, // 模板中使用JS的标识 136 loginIndex: true, // 模板中使用JS的标识
135 - captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码 137 + captchaShow: !captchaShow, // 170306 因为暴力破解密码问题,要求每次都展示验证码
136 backUrl: 'javascript:history.go(-1)', // eslint-disable-line 138 backUrl: 'javascript:history.go(-1)', // eslint-disable-line
137 showHeaderImg: true, // 控制显示头部图片 139 showHeaderImg: true, // 控制显示头部图片
138 isPassportPage: true, // 模板中模块标识 140 isPassportPage: true, // 模板中模块标识
@@ -20,6 +20,11 @@ const check = (req, res, next) => { @@ -20,6 +20,11 @@ const check = (req, res, next) => {
20 return next(); 20 return next();
21 } 21 }
22 22
  23 + // 170406 采用账号密码方式登录验证码可以配置关闭,默认开关是关闭状态,这时需要验证,开关开启,无需验证
  24 + if (_.get(req.app.locals.wap, 'close.loginValidation', false) && req.path === '/passport/login/auth') {
  25 + return next();
  26 + }
  27 +
23 // 使用极验证 28 // 使用极验证
24 let useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false); 29 let useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false);
25 30
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 <input id="pwd" class="pwd input" type="password" placeholder="密码"> 9 <input id="pwd" class="pwd input" type="password" placeholder="密码">
10 </div> 10 </div>
11 {{!--图片验证--}} 11 {{!--图片验证--}}
12 - <div data-geetest="{{useGeetest}}" id="js-img-check"></div> 12 + <div data-userverify="{{captchaShow}}" data-geetest="{{useGeetest}}" id="js-img-check"></div>
13 <span id="btn-login" class="btn btn-login disable">登录</span> 13 <span id="btn-login" class="btn btn-login disable">登录</span>
14 <p class="op-container"> 14 <p class="op-container">
15 <a class="op-item internat" href={{internationalUrl}}>海外手机</a> 15 <a class="op-item internat" href={{internationalUrl}}>海外手机</a>
@@ -14,6 +14,7 @@ let $account = $('#account'), @@ -14,6 +14,7 @@ let $account = $('#account'),
14 $ways = $('#retrive-pwd-ways'), 14 $ways = $('#retrive-pwd-ways'),
15 15
16 $captcha = $('#js-img-check'), 16 $captcha = $('#js-img-check'),
  17 + useVerify = $captcha.data('userverify'), // 170406 是否使用验证
17 18
18 accPass = false, 19 accPass = false,
19 pwdPass = false; 20 pwdPass = false;
@@ -25,14 +26,18 @@ let trim = $.trim; @@ -25,14 +26,18 @@ let trim = $.trim;
25 let showErrTip = tip.show; 26 let showErrTip = tip.show;
26 27
27 28
28 -let validate = new Validate($captcha, {  
29 - useREM: {  
30 - rootFontSize: 40,  
31 - picWidth: 150  
32 - }  
33 -}); 29 +let validate = {};
  30 +
  31 +if (useVerify) {
  32 + validate = new Validate($captcha, {
  33 + useREM: {
  34 + rootFontSize: 40,
  35 + picWidth: 150
  36 + }
  37 + });
34 38
35 -validate.init(); 39 + validate.init();
  40 +}
36 41
37 // 登录按钮状态切换 42 // 登录按钮状态切换
38 function switchLoginBtnStatus() { 43 function switchLoginBtnStatus() {
@@ -60,6 +65,62 @@ function hideRetrivePanel() { @@ -60,6 +65,62 @@ function hideRetrivePanel() {
60 $ways.hide(); 65 $ways.hide();
61 } 66 }
62 67
  68 +/**
  69 + * 登录校验
  70 + */
  71 +function loginAuth(params, acc) {
  72 + $.ajax({
  73 + type: 'POST',
  74 + url: '/passport/login/auth',
  75 + data: params,
  76 + success: function(data) {
  77 + let res,
  78 + LOGI_TYPE;
  79 +
  80 + if (acc.indexOf('@') > 0) {
  81 + LOGI_TYPE = 8;
  82 + } else {
  83 + LOGI_TYPE = 5;
  84 + }
  85 +
  86 + if (window._yas && window._yas.sendCustomInfo) {
  87 + window._yas.sendCustomInfo({
  88 + op: 'YB_MY_LOGIN_C',
  89 + param: JSON.stringify({
  90 + C_ID: window._ChannelVary[window.cookie('_Channel')],
  91 + LOGI_TYPE: LOGI_TYPE
  92 + })
  93 + }, true);
  94 + }
  95 + validate && validate.type === 2 && validate.refresh();
  96 + if (data.code === 200) {
  97 + res = data.data;
  98 +
  99 + showErrTip('登录成功');
  100 + location.href = res.href;
  101 + $loginBtn.text('登录成功');
  102 + } else {
  103 + if (useVerify && data.captchaShow) {
  104 + ((data.changeCaptcha && validate.type !== 2) && validate.refresh());
  105 + }
  106 +
  107 + showErrTip(data.message);
  108 + resetForm();
  109 + }
  110 +
  111 + return data;
  112 + },
  113 + error: function() {
  114 + showErrTip('网络断开连接啦~');
  115 +
  116 + validate && validate.refresh();
  117 + },
  118 + complete: function() {
  119 + $loginBtn.text('登录').removeClass('disable');
  120 + }
  121 + });
  122 +}
  123 +
63 // 密码显示与隐藏 124 // 密码显示与隐藏
64 api.bindEyesEvt(); 125 api.bindEyesEvt();
65 126
@@ -95,67 +156,23 @@ $loginBtn.on('touchstart', function() { @@ -95,67 +156,23 @@ $loginBtn.on('touchstart', function() {
95 156
96 // 验证账号(数字或者邮箱)和密码合理性 157 // 验证账号(数字或者邮箱)和密码合理性
97 if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) { 158 if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) {
98 - validate.getResults().then((result) => {  
99 - $loginBtn.text('正在登录...').addClass('disable');  
100 -  
101 - let params = {  
102 - account: acc,  
103 - password: pwd  
104 - };  
105 -  
106 - $.extend(params, result);  
107 -  
108 - $.ajax({  
109 - type: 'POST',  
110 - url: '/passport/login/auth',  
111 - data: params,  
112 - success: function(data) {  
113 - let res,  
114 - LOGI_TYPE;  
115 -  
116 - if (acc.indexOf('@') > 0) {  
117 - LOGI_TYPE = 8;  
118 - } else {  
119 - LOGI_TYPE = 5;  
120 - }  
121 -  
122 - if (window._yas && window._yas.sendCustomInfo) {  
123 - window._yas.sendCustomInfo({  
124 - op: 'YB_MY_LOGIN_C',  
125 - param: JSON.stringify({  
126 - C_ID: window._ChannelVary[window.cookie('_Channel')],  
127 - LOGI_TYPE: LOGI_TYPE  
128 - })  
129 - }, true);  
130 - }  
131 - validate.type === 2 && validate.refresh();  
132 - if (data.code === 200) {  
133 - res = data.data;  
134 -  
135 - showErrTip('登录成功');  
136 - location.href = res.href;  
137 - $loginBtn.text('登录成功');  
138 - } else {  
139 - if (data.captchaShow) {  
140 - ((data.changeCaptcha && validate.type !== 2) && validate.refresh());  
141 - }  
142 -  
143 - showErrTip(data.message);  
144 - resetForm();  
145 - }  
146 -  
147 - return data;  
148 - },  
149 - error: function() {  
150 - showErrTip('网络断开连接啦~');  
151 -  
152 - validate.refresh();  
153 - },  
154 - complete: function() {  
155 - $loginBtn.text('登录').removeClass('disable');  
156 - }  
157 - });  
158 - }, () => {}); 159 + let params = {
  160 + account: acc,
  161 + password: pwd
  162 + };
  163 +
  164 + if (useVerify) {
  165 + validate.getResults().then((result) => {
  166 + $loginBtn.text('正在登录...').addClass('disable');
  167 +
  168 + $.extend(params, result);
  169 +
  170 + // auth
  171 + loginAuth(params, acc);
  172 + }, () => {});
  173 + } else {
  174 + loginAuth(params, acc);
  175 + }
159 } else { 176 } else {
160 showErrTip('账号或密码有错误,请重新输入'); 177 showErrTip('账号或密码有错误,请重新输入');
161 $loginBtn.text('登录').removeClass('disable'); 178 $loginBtn.text('登录').removeClass('disable');