Authored by htoooth

add fix

@@ -16,7 +16,7 @@ const config = global.yoho.config; @@ -16,7 +16,7 @@ const config = global.yoho.config;
16 const cache = global.yoho.cache; 16 const cache = global.yoho.cache;
17 const AuthHelper = require('../models/auth-helper'); 17 const AuthHelper = require('../models/auth-helper');
18 const PassportHelper = require('../models/passport-helper'); 18 const PassportHelper = require('../models/passport-helper');
19 -const loginPage = `${config.siteUrl}/signin`; 19 +const loginPage = `${config.siteUrl}/passport/login`;
20 20
21 // 第三方登录回调 21 // 第三方登录回调
22 function doPassportCallback(req, res, user) { 22 function doPassportCallback(req, res, user) {
@@ -302,67 +302,11 @@ const alipay = { @@ -302,67 +302,11 @@ const alipay = {
302 } 302 }
303 }; 303 };
304 304
305 -const douban = {  
306 - login: (req, res, next) => {  
307 - req.session = req.session || {};  
308 - req.session.authState = uuid.v4();  
309 - return passport.authenticate('douban', {  
310 - state: req.session.authState  
311 - })(req, res, next);  
312 - },  
313 - callback: (req, res, next) => {  
314 - passport.authenticate('douban', (err, user) => {  
315 - if (err) {  
316 - log.error(`douban authenticate error : ${JSON.stringify(err)}`);  
317 - return res.redirect(loginPage);  
318 - }  
319 -  
320 - let nickname = user.displayName;  
321 - let openId = user.id;  
322 -  
323 - doPassportCallback(req, res, {  
324 - openId: openId,  
325 - nickname: nickname,  
326 - sourceType: 'douban'  
327 - }).catch(next);  
328 - })(req, res, next);  
329 - }  
330 -};  
331 -  
332 -const renren = {  
333 - login: (req, res, next) => {  
334 - req.session = req.session || {};  
335 - req.session.authState = uuid.v4();  
336 - return passport.authenticate('renren', {  
337 - state: req.session.authState  
338 - })(req, res, next);  
339 - },  
340 - callback: (req, res, next) => {  
341 - passport.authenticate('renren', (err, user) => {  
342 - if (err) {  
343 - log.error(`renren authenticate error : ${JSON.stringify(err)}`);  
344 - return res.redirect(loginPage);  
345 - }  
346 -  
347 - let nickname = user.displayName;  
348 - let openId = user.id;  
349 -  
350 - doPassportCallback(req, res, {  
351 - openId: openId,  
352 - nickname: nickname,  
353 - sourceType: 'renren'  
354 - }).catch(next);  
355 - })(req, res, next);  
356 - }  
357 -};  
358 -  
359 module.exports = { 305 module.exports = {
360 common: common, 306 common: common,
361 - wechat: wechat,  
362 local: local, 307 local: local,
363 - sina: sina, 308 + wechat: wechat,
364 qq: qq, 309 qq: qq,
365 - alipay: alipay,  
366 - douban: douban,  
367 - renren: renren 310 + sina: sina,
  311 + alipay: alipay
368 }; 312 };
@@ -69,7 +69,7 @@ @@ -69,7 +69,7 @@
69 <li class="clearfix"> 69 <li class="clearfix">
70 <input name="refer" id="refer" type="hidden" value="http%3A%2F%2Fwww.yohoblk.com%2F"> 70 <input name="refer" id="refer" type="hidden" value="http%3A%2F%2Fwww.yohoblk.com%2F">
71 <div class="center"> 71 <div class="center">
72 - <input id="find-btn" class="find-btn disable" type="submit" value="下一步"> 72 + <a id="find-btn" class="find-btn disable" >下一步</a>
73 </div> 73 </div>
74 </li> 74 </li>
75 </form> 75 </form>
@@ -15,7 +15,8 @@ var $regionCodeText = $('#country-code'), @@ -15,7 +15,8 @@ var $regionCodeText = $('#country-code'),
15 $imgCaptchaInput = $('#verifyCode'), 15 $imgCaptchaInput = $('#verifyCode'),
16 $regionSelectCtrl = $('#area'), 16 $regionSelectCtrl = $('#area'),
17 $nextBtn = $('#find-btn'), 17 $nextBtn = $('#find-btn'),
18 - $phone = $('#phone'); 18 + $phone = $('#phone'),
  19 + $form = $('#back-form');
19 20
20 var emailRegx = regx.emailRegx, 21 var emailRegx = regx.emailRegx,
21 phoneRegx = regx.phoneRegx; 22 phoneRegx = regx.phoneRegx;
@@ -73,15 +74,8 @@ function validatePhoneNumAsync() { @@ -73,15 +74,8 @@ function validatePhoneNumAsync() {
73 } 74 }
74 75
75 function nextStep(url) { 76 function nextStep(url) {
76 - return $.ajax({  
77 - type: 'POST',  
78 - url: url,  
79 - data: {  
80 - verifyCode: $.trim($imgCaptchaInput.val()),  
81 - phoneNum: $phoneNumInput.val(),  
82 - area: $regionCodeText.text()  
83 - }  
84 - }); 77 + $form.attr('action', url);
  78 + $form.submit();
85 } 79 }
86 80
87 function validatePhoneNumLocal() { 81 function validatePhoneNumLocal() {
@@ -230,22 +224,21 @@ exports.init = function() { @@ -230,22 +224,21 @@ exports.init = function() {
230 }); 224 });
231 225
232 $nextBtn.on('click', function() { 226 $nextBtn.on('click', function() {
233 -  
234 var urlPhone = '/passport/back/mobile', 227 var urlPhone = '/passport/back/mobile',
235 urlEmail = '/passport/back/email'; 228 urlEmail = '/passport/back/email';
236 229
237 var url = null; 230 var url = null;
238 231
  232 + if ($(this).hasClass('disable')) {
  233 + return;
  234 + }
  235 +
239 if (/^[0-9]+$/.test($.trim($phoneNumInput.val()))) { 236 if (/^[0-9]+$/.test($.trim($phoneNumInput.val()))) {
240 url = urlPhone; 237 url = urlPhone;
241 } else { 238 } else {
242 url = urlEmail; 239 url = urlEmail;
243 } 240 }
244 241
245 - if ($(this).hasClass('disable')) {  
246 - return;  
247 - }  
248 -  
249 $nextBtn.addClass('disable'); 242 $nextBtn.addClass('disable');
250 243
251 nextStep(url); 244 nextStep(url);
@@ -9,7 +9,7 @@ var EventProxy = require('../common/eventproxy'); @@ -9,7 +9,7 @@ var EventProxy = require('../common/eventproxy');
9 9
10 var $phoneNumInput = $('#account'), 10 var $phoneNumInput = $('#account'),
11 $passwordInput = $('#password'), 11 $passwordInput = $('#password'),
12 - $captchaInput = $('#captcha'), 12 + $imgCaptchaInput = $('#captcha'),
13 $loginBtn = $('#login-btn'), 13 $loginBtn = $('#login-btn'),
14 $phone = $('#phone'); 14 $phone = $('#phone');
15 15
@@ -37,8 +37,6 @@ var checkbox = { @@ -37,8 +37,6 @@ var checkbox = {
37 unchecked: '&#xe601;' 37 unchecked: '&#xe601;'
38 }; 38 };
39 39
40 -var emailAcTime;  
41 -  
42 var $errTip = $('.tips'); 40 var $errTip = $('.tips');
43 var $errMsg = $errTip.find('.rectangle'); 41 var $errMsg = $errTip.find('.rectangle');
44 42
@@ -56,7 +54,6 @@ function errTip(ele, msg) { @@ -56,7 +54,6 @@ function errTip(ele, msg) {
56 }).removeClass('hide'); 54 }).removeClass('hide');
57 } 55 }
58 56
59 -  
60 // 验证账户名 57 // 验证账户名
61 function validateAccountLocal() { 58 function validateAccountLocal() {
62 var phoneNum = $.trim($phoneNumInput.val()), 59 var phoneNum = $.trim($phoneNumInput.val()),
@@ -66,7 +63,6 @@ function validateAccountLocal() { @@ -66,7 +63,6 @@ function validateAccountLocal() {
66 if (/^[0-9]+$/.test(phoneNum)) { 63 if (/^[0-9]+$/.test(phoneNum)) {
67 // 不是11位 64 // 不是11位
68 if (phoneNum.length !== 11) { 65 if (phoneNum.length !== 11) {
69 - ep.emit('phone', false);  
70 errTip($phone, '手机号码不正确,请重新输入'); 66 errTip($phone, '手机号码不正确,请重新输入');
71 return false; 67 return false;
72 } 68 }
@@ -74,10 +70,8 @@ function validateAccountLocal() { @@ -74,10 +70,8 @@ function validateAccountLocal() {
74 // 如果是纯数字,则作为手机号码处理 70 // 如果是纯数字,则作为手机号码处理
75 if (regionCode !== '+86' || 71 if (regionCode !== '+86' ||
76 mailPhoneRegx.phoneRegx[regionCode].test(phoneNum)) { 72 mailPhoneRegx.phoneRegx[regionCode].test(phoneNum)) {
77 - ep.emit('phone', true);  
78 return true; 73 return true;
79 } else { 74 } else {
80 - ep.emit('phone', false);  
81 errTip($phone, '手机号码不正确,请重新输入'); 75 errTip($phone, '手机号码不正确,请重新输入');
82 return false; 76 return false;
83 } 77 }
@@ -85,17 +79,14 @@ function validateAccountLocal() { @@ -85,17 +79,14 @@ function validateAccountLocal() {
85 79
86 // 邮箱验证 80 // 邮箱验证
87 if (mailPhoneRegx.emailRegx.test(phoneNum)) { 81 if (mailPhoneRegx.emailRegx.test(phoneNum)) {
88 - ep.emit('phone', true);  
89 return true; 82 return true;
90 } else { 83 } else {
91 - ep.emit('phone', false);  
92 errTip($phone, '邮箱格式不正确,请重新输入'); 84 errTip($phone, '邮箱格式不正确,请重新输入');
93 return false; 85 return false;
94 } 86 }
95 } 87 }
96 88
97 } else { 89 } else {
98 - ep.emit('phone', false);  
99 errTip($phone, '请输入账号'); 90 errTip($phone, '请输入账号');
100 return false; 91 return false;
101 } 92 }
@@ -111,10 +102,8 @@ function validateAccountAsync() { @@ -111,10 +102,8 @@ function validateAccountAsync() {
111 } 102 }
112 }).then(function(data) { 103 }).then(function(data) {
113 if (data.code && data.code === 200) { 104 if (data.code && data.code === 200) {
114 - ep.emit('phone', true);  
115 return true; 105 return true;
116 } else { 106 } else {
117 - ep.emit('phone', false);  
118 errTip($phone, '账号不存在'); 107 errTip($phone, '账号不存在');
119 return false; 108 return false;
120 } 109 }
@@ -122,17 +111,29 @@ function validateAccountAsync() { @@ -122,17 +111,29 @@ function validateAccountAsync() {
122 } 111 }
123 112
124 function validateAccount() { 113 function validateAccount() {
125 - var defer = $.Deferred(); // eslint-disable-line 114 + function validate() {
  115 + var defer = $.Deferred(); // eslint-disable-line
126 116
127 - if (validateAccountLocal()) {  
128 - validateAccountAsync().then(function(result) {  
129 - defer.resolve(result);  
130 - });  
131 - } else {  
132 - defer.resolve(false); 117 + if (validateAccountLocal()) {
  118 + validateAccountAsync().then(function(result) {
  119 + if (result) {
  120 + defer.resolve(result);
  121 + } else {
  122 + defer.reject(result);
  123 + }
  124 + });
  125 + } else {
  126 + defer.reject(false);
  127 + }
  128 +
  129 + return defer.promise();
133 } 130 }
134 131
135 - return defer.promise(); 132 + return validate().then(function() {
  133 + ep.emit('phone', true);
  134 + }).fail(function() {
  135 + ep.emit('phone', false);
  136 + });
136 } 137 }
137 138
138 // 验证密码 139 // 验证密码
@@ -158,7 +159,7 @@ function validatePasswordLocal() { @@ -158,7 +159,7 @@ function validatePasswordLocal() {
158 159
159 // 验证验证码 160 // 验证验证码
160 function validateCaptchaLocal() { 161 function validateCaptchaLocal() {
161 - var captcha = $.trim($captchaInput.val()); 162 + var captcha = $.trim($imgCaptchaInput.val());
162 var length = captcha.length; 163 var length = captcha.length;
163 164
164 if ($captchaWrap.hasClass('hide')) { 165 if ($captchaWrap.hasClass('hide')) {
@@ -168,14 +169,14 @@ function validateCaptchaLocal() { @@ -168,14 +169,14 @@ function validateCaptchaLocal() {
168 169
169 switch (length) { 170 switch (length) {
170 case 0: 171 case 0:
171 - errTip($captchaInput, '请输入验证码'); 172 + errTip($imgCaptchaInput, '请输入验证码');
172 ep.emit('captcha', false); 173 ep.emit('captcha', false);
173 break; 174 break;
174 case 4: 175 case 4:
175 ep.emit('captcha', true); 176 ep.emit('captcha', true);
176 break; 177 break;
177 default: 178 default:
178 - errTip($captchaInput, '请输入长度为4字符的验证码'); 179 + errTip($imgCaptchaInput, '请输入长度为4字符的验证码');
179 ep.emit('captcha', false); 180 ep.emit('captcha', false);
180 break; 181 break;
181 } 182 }
@@ -185,7 +186,7 @@ function validateCaptchaLocal() { @@ -185,7 +186,7 @@ function validateCaptchaLocal() {
185 function showAccountErrTimes() { 186 function showAccountErrTimes() {
186 $captchaWrap.removeClass('hide'); 187 $captchaWrap.removeClass('hide');
187 $captchaImg.attr('src', captchaUrl + $.now()); 188 $captchaImg.attr('src', captchaUrl + $.now());
188 - $captchaInput.val(''); 189 + $imgCaptchaInput.val('');
189 } 190 }
190 191
191 // 登录 192 // 登录
@@ -197,7 +198,7 @@ function login() { @@ -197,7 +198,7 @@ function login() {
197 areaCode: $regionCodeText.text().replace('+', ''), 198 areaCode: $regionCodeText.text().replace('+', ''),
198 account: $.trim($phoneNumInput.val()), 199 account: $.trim($phoneNumInput.val()),
199 password: $.trim($passwordInput.val()), 200 password: $.trim($passwordInput.val()),
200 - captcha: $.trim($captchaInput.val()), 201 + captcha: $.trim($imgCaptchaInput.val()),
201 isRemember: $remember.hasClass('checked') ? true : false 202 isRemember: $remember.hasClass('checked') ? true : false
202 }, 203 },
203 success: function(res) { 204 success: function(res) {
@@ -209,7 +210,7 @@ function login() { @@ -209,7 +210,7 @@ function login() {
209 } 210 }
210 } else { 211 } else {
211 if (res.data.errorType === 'captcha') { 212 if (res.data.errorType === 'captcha') {
212 - $captchaInput.val(''); 213 + $imgCaptchaInput.val('');
213 } else { 214 } else {
214 $loginTip.removeClass('hide').children('em').html(res.message); 215 $loginTip.removeClass('hide').children('em').html(res.message);
215 $passwordInput.val(''); 216 $passwordInput.val('');
@@ -225,7 +226,7 @@ function login() { @@ -225,7 +226,7 @@ function login() {
225 } 226 }
226 227
227 mailAc($phoneNumInput, function() { 228 mailAc($phoneNumInput, function() {
228 - function validateUser() { 229 + function throttle() {
229 return $.ajax({ 230 return $.ajax({
230 url: '/passport/login/account', 231 url: '/passport/login/account',
231 type: 'GET', 232 type: 'GET',
@@ -237,7 +238,7 @@ mailAc($phoneNumInput, function() { @@ -237,7 +238,7 @@ mailAc($phoneNumInput, function() {
237 238
238 validateAccount().then(function(result) { 239 validateAccount().then(function(result) {
239 if (result) { 240 if (result) {
240 - return validateUser(); 241 + return throttle();
241 } else { 242 } else {
242 return false; 243 return false;
243 } 244 }
@@ -260,6 +261,7 @@ $phoneNumInput.on('focus', function() { @@ -260,6 +261,7 @@ $phoneNumInput.on('focus', function() {
260 261
261 $('[placeholder]').placeholder(); 262 $('[placeholder]').placeholder();
262 263
  264 +// 选择地点
263 $regionSelectCtrl.change(function() { 265 $regionSelectCtrl.change(function() {
264 var $this = $(this); 266 var $this = $(this);
265 267
@@ -270,22 +272,20 @@ $regionSelectCtrl.change(function() { @@ -270,22 +272,20 @@ $regionSelectCtrl.change(function() {
270 $passwordInput.on('blur', function() { 272 $passwordInput.on('blur', function() {
271 $passwordInput.removeClass('focus'); 273 $passwordInput.removeClass('focus');
272 validatePasswordLocal(); 274 validatePasswordLocal();
273 - $captchaInput.trigger('blur');  
274 }).on('focus', function() { 275 }).on('focus', function() {
275 $passwordInput.addClass('focus'); 276 $passwordInput.addClass('focus');
276 }); 277 });
277 278
278 // 验证码 279 // 验证码
279 -$captchaInput.on('blur', function() {  
280 - $captchaInput.removeClass('focus'); 280 +$imgCaptchaInput.on('blur', function() {
  281 + $imgCaptchaInput.removeClass('focus');
281 validateCaptchaLocal(); 282 validateCaptchaLocal();
282 }).on('focus', function() { 283 }).on('focus', function() {
283 - $captchaInput.addClass('focus'); 284 + $imgCaptchaInput.addClass('focus');
284 }); 285 });
285 286
286 // 邮箱自动完成列表项点击 287 // 邮箱自动完成列表项点击
287 $emailAutoComplete.on('click', 'li', function() { 288 $emailAutoComplete.on('click', 'li', function() {
288 - clearTimeout(emailAcTime); // 清空默认关闭  
289 $phoneNumInput.val($(this).text()).focus(); 289 $phoneNumInput.val($(this).text()).focus();
290 $emailAutoComplete.addClass('hide'); 290 $emailAutoComplete.addClass('hide');
291 }); 291 });
@@ -303,13 +303,6 @@ $remember.on('click', function() { @@ -303,13 +303,6 @@ $remember.on('click', function() {
303 } 303 }
304 }); 304 });
305 305
306 -// focus到输入框则隐藏错误提示和样式  
307 -$('.va').on('focus', function() {  
308 - var $this = $(this);  
309 -  
310 - $this.siblings('.err-tip').addClass('hide');  
311 -});  
312 -  
313 // 验证码刷新 306 // 验证码刷新
314 $captchaWrap.on('click', '.change-captcha, .captcha-img', function() { 307 $captchaWrap.on('click', '.change-captcha, .captcha-img', function() {
315 $captchaImg.attr('src', captchaUrl + $.now()); 308 $captchaImg.attr('src', captchaUrl + $.now());
@@ -363,3 +356,5 @@ $('input.va').on('keypress', function(e) { @@ -363,3 +356,5 @@ $('input.va').on('keypress', function(e) {
363 } 356 }
364 }); 357 });
365 358
  359 +// 首次触发
  360 +$imgCaptchaInput.trigger('blur');
@@ -87,12 +87,13 @@ @@ -87,12 +87,13 @@
87 } 87 }
88 88
89 .find-btn { 89 .find-btn {
90 - border: 0; 90 + display: inline-block;
91 width: 180px; 91 width: 180px;
92 height: $item-height; 92 height: $item-height;
93 background-color: $theme-color; 93 background-color: $theme-color;
94 color: white; 94 color: white;
95 margin-top: 40px; 95 margin-top: 40px;
  96 + line-height: @height;
96 97
97 &.disable { 98 &.disable {
98 background-color: $inactive-color; 99 background-color: $inactive-color;