Authored by lore-w

完善信息页面逻辑 code review by liuyue

@@ -78,10 +78,21 @@ @@ -78,10 +78,21 @@
78 {{!-- 注册页--}} 78 {{!-- 注册页--}}
79 {{#if registerPage}} 79 {{#if registerPage}}
80 <script> 80 <script>
81 - seajs.use('js/passport/reg'); 81 + seajs.use('js/passport/reg', function (reg) {
  82 + reg.init('reg');
  83 + });
82 </script> 84 </script>
83 {{/if}} 85 {{/if}}
84 86
  87 +{{!-- 第三方登录完善信息页--}}
  88 +{{#if thirdPage}}
  89 +<script>
  90 + seajs.use('js/passport/reg', function (reg) {
  91 + reg.init('third');
  92 + });
  93 +</script>
  94 +{{/if}}
  95 +
85 {{!-- 找回密码--}} 96 {{!-- 找回密码--}}
86 {{#if backPage}} 97 {{#if backPage}}
87 <script> 98 <script>
@@ -83,14 +83,30 @@ validateResult = [ @@ -83,14 +83,30 @@ validateResult = [
83 ]; 83 ];
84 84
85 //手机号ajax校验 85 //手机号ajax校验
86 -function phoneAjaxFn(callback) {  
87 - $.ajax({  
88 - url: '/passport/register/checkmobile',  
89 - type: 'POST',  
90 - data: { 86 +function phoneAjaxFn(page, callback) {
  87 + var url,
  88 + data;
  89 +
  90 + if (page === 'reg') {
  91 + url = '/passport/register/checkmobile';
  92 + data = {
91 mobile: $pn.val(), 93 mobile: $pn.val(),
92 area: $region.text().split('+')[1] 94 area: $region.text().split('+')[1]
93 - } 95 + };
  96 + } else if (page === 'third') {
  97 + url = '/passport/autouserinfo/bindCheck';
  98 + data = {
  99 + mobile: $pn.val(),
  100 + area: $region.text().split('+')[1],
  101 + openId: 1,
  102 + sourceType: 'QQ'
  103 + };
  104 + }
  105 +
  106 + $.ajax({
  107 + url: url,
  108 + type: 'POST',
  109 + data: data
94 }).then(function(data) { 110 }).then(function(data) {
95 switch (data.code) { 111 switch (data.code) {
96 case 200: 112 case 200:
@@ -108,10 +124,17 @@ function phoneAjaxFn(callback) { @@ -108,10 +124,17 @@ function phoneAjaxFn(callback) {
108 } 124 }
109 125
110 //图形验证码ajax校验 126 //图形验证码ajax校验
111 -function picCaptchaAjaxFn(callback) { 127 +function picCaptchaAjaxFn(page, callback) {
  128 + var url;
  129 +
  130 + if (page === 'reg') {
  131 + url = '/passport/register/piccaptcha';
  132 + } else if (page === 'third') {
  133 + url = '/passport/autouserinfo/checkPicCode';
  134 + }
112 $.ajax({ 135 $.ajax({
113 type: 'POST', 136 type: 'POST',
114 - url: '/passport/register/piccaptcha', 137 + url: url,
115 data: { 138 data: {
116 code: $ca.val(), 139 code: $ca.val(),
117 mobile: $pn.val(), 140 mobile: $pn.val(),
@@ -123,7 +146,7 @@ function picCaptchaAjaxFn(callback) { @@ -123,7 +146,7 @@ function picCaptchaAjaxFn(callback) {
123 validateResult[1].message = ''; 146 validateResult[1].message = '';
124 validateResult[1].status = true; 147 validateResult[1].status = true;
125 break; 148 break;
126 - case 404: 149 + case 400:
127 validateResult[1].message = '图形验证码错误'; 150 validateResult[1].message = '图形验证码错误';
128 validateResult[1].status = false; 151 validateResult[1].status = false;
129 break; 152 break;
@@ -133,10 +156,17 @@ function picCaptchaAjaxFn(callback) { @@ -133,10 +156,17 @@ function picCaptchaAjaxFn(callback) {
133 } 156 }
134 157
135 //短信验证码ajax校验 158 //短信验证码ajax校验
136 -function msgCaptchaAjaxFn(callback) { 159 +function msgCaptchaAjaxFn(page, callback) {
  160 + var url;
  161 +
  162 + if (page === 'reg') {
  163 + url = '/passport/register/msgcaptcha';
  164 + } else if (page === 'third') {
  165 + url = '/passport/autouserinfo/checkBindMsg';
  166 + }
137 $.ajax({ 167 $.ajax({
138 type: 'POST', 168 type: 'POST',
139 - url: '/passport/register/msgcaptcha', 169 + url: url,
140 data: { 170 data: {
141 code: $ca.val(), 171 code: $ca.val(),
142 mobile: $pn.val(), 172 mobile: $pn.val(),
@@ -148,7 +178,7 @@ function msgCaptchaAjaxFn(callback) { @@ -148,7 +178,7 @@ function msgCaptchaAjaxFn(callback) {
148 validateResult[2].message = ''; 178 validateResult[2].message = '';
149 validateResult[2].status = true; 179 validateResult[2].status = true;
150 break; 180 break;
151 - case 404: 181 + case 400:
152 validateResult[2].message = '短信验证码错误'; 182 validateResult[2].message = '短信验证码错误';
153 validateResult[2].status = false; 183 validateResult[2].status = false;
154 break; 184 break;
@@ -159,7 +189,7 @@ function msgCaptchaAjaxFn(callback) { @@ -159,7 +189,7 @@ function msgCaptchaAjaxFn(callback) {
159 } 189 }
160 190
161 // 验证 191 // 验证
162 -function validateRule($element, callback) { 192 +function validateRule(page, $element, callback) {
163 193
164 var val = $.trim($element.val()), 194 var val = $.trim($element.val()),
165 regionCode; 195 regionCode;
@@ -181,7 +211,7 @@ function validateRule($element, callback) { @@ -181,7 +211,7 @@ function validateRule($element, callback) {
181 callback(); 211 callback();
182 212
183 } else { 213 } else {
184 - phoneAjaxFn(callback); 214 + phoneAjaxFn(page, callback);
185 } 215 }
186 216
187 //图形验证码校验 217 //图形验证码校验
@@ -200,7 +230,7 @@ function validateRule($element, callback) { @@ -200,7 +230,7 @@ function validateRule($element, callback) {
200 230
201 // 并且手机号正确 231 // 并且手机号正确
202 if (validateResult[0].status) { 232 if (validateResult[0].status) {
203 - picCaptchaAjaxFn(callback); 233 + picCaptchaAjaxFn(page, callback);
204 } else { 234 } else {
205 validateResult[1].message = '图形验证码错误'; 235 validateResult[1].message = '图形验证码错误';
206 validateResult[1].status = false; 236 validateResult[1].status = false;
@@ -226,7 +256,7 @@ function validateRule($element, callback) { @@ -226,7 +256,7 @@ function validateRule($element, callback) {
226 256
227 // 并且图形验证码正确 257 // 并且图形验证码正确
228 if (validateResult[1].status) { 258 if (validateResult[1].status) {
229 - msgCaptchaAjaxFn(callback); 259 + msgCaptchaAjaxFn(page, callback);
230 } else { 260 } else {
231 validateResult[2].message = '短信验证码错误'; 261 validateResult[2].message = '短信验证码错误';
232 validateResult[2].status = false; 262 validateResult[2].status = false;
@@ -379,140 +409,169 @@ function pwdFn($obj) { @@ -379,140 +409,169 @@ function pwdFn($obj) {
379 409
380 // 失去焦点时开始校验 410 // 失去焦点时开始校验
381 // Tips: 不可以在获得焦点的时候验证,获得焦点和失去焦点的间隔太小,如果中间存在ajax校验的话会出现问题 411 // Tips: 不可以在获得焦点的时候验证,获得焦点和失去焦点的间隔太小,如果中间存在ajax校验的话会出现问题
382 -$registerPage.find('.va').keyup(function() { 412 +// ( ▼-▼ )注册页和信息完善页面接口不同
  413 +exports.init = function(page) {
  414 + $registerPage.find('.va').keyup(function() {
383 415
384 - var j,  
385 - statusLen = 0,  
386 - vLen = validateResult.length,  
387 - $that = $(this); 416 + var j,
  417 + statusLen = 0,
  418 + vLen = validateResult.length,
  419 + $that = $(this);
388 420
389 - validateRule($(this), function() {  
390 - showErrTip(); // 显示错误提示  
391 - showBorder(); // 显示红色边框 421 + validateRule(page, $(this), function() {
  422 + showErrTip(); // 显示错误提示
  423 + showBorder(); // 显示红色边框
392 424
393 - // 如果validateResult中有4个status为true表示验证通过  
394 - for (j = 0; j < vLen; j++) { 425 + // 如果validateResult中有4个status为true表示验证通过
  426 + for (j = 0; j < vLen; j++) {
395 427
396 - if (validateResult[j].status) { 428 + if (validateResult[j].status) {
397 429
398 - statusLen++;  
399 - }  
400 -  
401 - } 430 + statusLen++;
  431 + }
402 432
403 - if (statusLen === 4 && $('#agree-terms').is(':checked')) {  
404 - $registerBtn.removeClass('disable').removeAttr('disabled');  
405 - } else {  
406 - $registerBtn.addClass('disable').attr('disabled', 'true');  
407 - } 433 + }
408 434
409 - // 图形验证通过时,发送短信按钮可点击  
410 - if (validateResult[1].status) {  
411 - $sendCaptcha.removeClass('disable');  
412 - } else {  
413 - $sendCaptcha.addClass('disable');  
414 - } 435 + if (statusLen === 4 && $('#agree-terms').is(':checked')) {
  436 + $registerBtn.removeClass('disable').removeAttr('disabled');
  437 + } else {
  438 + $registerBtn.addClass('disable').attr('disabled', 'true');
  439 + }
415 440
416 - //图形验证通过时,发送短信按钮可点击 end 441 + // 图形验证通过时,发送短信按钮可点击
  442 + if (validateResult[1].status) {
  443 + $sendCaptcha.removeClass('disable');
  444 + } else {
  445 + $sendCaptcha.addClass('disable');
  446 + }
417 447
418 - }); 448 + //图形验证通过时,发送短信按钮可点击 end
419 449
420 - // 如果是密码则校验强度  
421 - if (($that).hasClass('pwd')) {  
422 - pwdFn($that);  
423 - }  
424 -  
425 -}).blur(function() { 450 + });
426 451
427 - /*validateRule($(this), function() {  
428 - showErrTip();  
429 - showBorder(); // 显示红色边框  
430 - });*/  
431 -}); 452 + // 如果是密码则校验强度
  453 + if (($that).hasClass('pwd')) {
  454 + pwdFn($that);
  455 + }
432 456
433 -$regionSelect.change(function() { 457 + }).blur(function() {
434 458
435 - $region.text('+' + $('#region').val()); 459 + /*validateRule($(this), function() {
  460 + showErrTip();
  461 + showBorder(); // 显示红色边框
  462 + });*/
  463 + });
436 464
437 - validateRule($pn, showErrTip); //验证  
438 -}); 465 + $regionSelect.change(function() {
439 466
440 -// 点击发送验证码  
441 -$sendCaptcha.click(function() {  
442 - var timeResidue = 10,  
443 - t; 467 + $region.text('+' + $('#region').val());
444 468
445 - if ($(this).hasClass('disable')) {  
446 - return;  
447 - } 469 + validateRule(page, $pn, showErrTip); //验证
  470 + });
448 471
449 - //todo ajax 472 + // 点击发送验证码
  473 + $sendCaptcha.click(function() {
  474 + var timeResidue = 20,
  475 + t,
  476 + url;
450 477
451 - t = setInterval(function() {  
452 - if (timeResidue <= 0) {  
453 - $sendCaptcha.removeClass('disable').val('获取短信验证码');  
454 - clearInterval(t); 478 + if ($(this).hasClass('disable')) {
455 return; 479 return;
456 } 480 }
457 - $sendCaptcha.addClass('disable').val(timeResidue-- + '秒可重新发送');  
458 - }, 1000);  
459 -});  
460 481
461 -//form表单提交  
462 -$registerBtn.click(function() {  
463 -  
464 - if ($(this).hasClass('disable')) {  
465 - return;  
466 - } else { 482 + if (page === 'reg') {
  483 + url = '/passport/register/sendBindMsg';
  484 + } else if (page === 'third') {
  485 + url = '/passport/autouserinfo/sendBindMsg';
  486 + }
467 487
468 - //ajax提交 488 + //todo ajax 发送验证码
469 $.ajax({ 489 $.ajax({
470 type: 'POST', 490 type: 'POST',
471 - url: '/passport/register/mobileregister', 491 + url: url,
472 data: { 492 data: {
473 area: $region.text().split('+')[1], 493 area: $region.text().split('+')[1],
474 mobile: $pn.val(), 494 mobile: $pn.val(),
475 - captcha: $ca.val(),  
476 - code: $mc.val(),  
477 - password: $pwd.val() 495 + code: $ca.val()
478 } 496 }
479 }).then(function(data) { 497 }).then(function(data) {
  498 + if (data.code === 200) {
  499 + t = setInterval(function() {
  500 + if (timeResidue <= 0) {
  501 + $sendCaptcha.removeClass('disable').val('获取短信验证码');
  502 + clearInterval(t);
  503 + return;
  504 + }
  505 + $sendCaptcha.addClass('disable').val(timeResidue-- + '秒可重新发送');
  506 + }, 1000);
  507 + }
  508 + });
  509 + });
480 510
481 - var time = 0,  
482 - t,  
483 - refer = data.href; 511 + //ajax表单提交
  512 + $registerBtn.click(function() {
484 513
485 - t = setTimeout(function() {  
486 - time++;  
487 - }, 1000); 514 + var url;
488 515
  516 + if (page === 'reg') {
  517 + url = '/passport/register/mobileregister';
  518 + } else if (page === 'third') {
  519 + url = '/passport/autouserinfo/bindMobile';
  520 + }
  521 +
  522 + if ($(this).hasClass('disable')) {
  523 + return;
  524 + } else {
  525 +
  526 + //ajax提交
489 $.ajax({ 527 $.ajax({
490 type: 'POST', 528 type: 'POST',
491 - url: '/passport/register/mobileregister', 529 + url: url,
492 data: { 530 data: {
493 - session: data.session 531 + area: $region.text().split('+')[1],
  532 + mobile: $pn.val(),
  533 + captcha: $ca.val(),
  534 + code: $mc.val(),
  535 + password: $pwd.val()
494 } 536 }
495 }).then(function(data) { 537 }).then(function(data) {
496 538
497 - if (data.code === 200 && t < 3) { 539 + var time = 0,
  540 + t,
  541 + refer = data.href;
  542 +
  543 + t = setTimeout(function() {
  544 + time++;
  545 + }, 1000);
  546 +
  547 + $.ajax({
  548 + type: 'POST',
  549 + url: '/passport/register/mobileregister',
  550 + data: {
  551 + session: data.session
  552 + }
  553 + }).then(function(data) {
  554 +
  555 + if (data.code === 200 && t < 3) {
  556 + clearInterval(t);
  557 + location.href = refer;
  558 + }
  559 + });
  560 +
  561 + if (t >= 3) {
498 clearInterval(t); 562 clearInterval(t);
499 location.href = refer; 563 location.href = refer;
500 } 564 }
501 - });  
502 -  
503 - if (t >= 3) {  
504 - clearInterval(t);  
505 - location.href = refer;  
506 - }  
507 565
508 - });  
509 - }  
510 -}); 566 + });
  567 + }
  568 + });
511 569
512 -$('.change-captcha').click(function() {  
513 - var time = new Date(),  
514 - $captchaImg = $('.captcha-img'),  
515 - captchaImgSrc = $captchaImg.attr('src').split('?')[0]; 570 + $('.change-captcha').click(function() {
  571 + var time = new Date(),
  572 + $captchaImg = $('.captcha-img'),
  573 + captchaImgSrc = $captchaImg.attr('src').split('?')[0];
516 574
517 - $captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());  
518 -});  
  575 + $captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
  576 + });
  577 +};
@@ -44,13 +44,13 @@ class AutouserinfoController extends AbstractAction @@ -44,13 +44,13 @@ class AutouserinfoController extends AbstractAction
44 44
45 //整合 45 //整合
46 $data = array( 46 $data = array(
47 - 'registerPage' => true, 47 + 'thirdPage' => true,
48 'simpleHeader' => $simpleHeader, 48 'simpleHeader' => $simpleHeader,
49 'passport' => array( 49 'passport' => array(
50 'actionUrl' => Helpers::url('/autouserinfo/bind'), 50 'actionUrl' => Helpers::url('/autouserinfo/bind'),
51 'region' => RegData::getAreasData(), 51 'region' => RegData::getAreasData(),
52 'location' => '+86', 52 'location' => '+86',
53 - 'captchaUrl' => Helpers::url('/passport/images?t=' . time()), 53 + 'captchaUrl' => '/passport/images?t=1449799445',
54 'itemUrl' => Helpers::url('/help/?category_id=9'), 54 'itemUrl' => Helpers::url('/help/?category_id=9'),
55 'referUrl' => $refer, 55 'referUrl' => $refer,
56 'skipUrl' => SITE_MAIN, 56 'skipUrl' => SITE_MAIN,