Authored by 陈轩

注册 图形旋转 验证码 完成

@@ -76,6 +76,7 @@ let index = (req, res) => { @@ -76,6 +76,7 @@ let index = (req, res) => {
76 } 76 }
77 77
78 res.render('reg/index', { 78 res.render('reg/index', {
  79 + width750: true,
79 module: 'passport', 80 module: 'passport',
80 page: 'reg', 81 page: 'reg',
81 title: '注册', 82 title: '注册',
@@ -99,7 +100,7 @@ let verifyMobile = (req, res, next) => { @@ -99,7 +100,7 @@ let verifyMobile = (req, res, next) => {
99 let mobile = +req.body.phoneNum; 100 let mobile = +req.body.phoneNum;
100 let area = +(req.body.areaCode || 86); 101 let area = +(req.body.areaCode || 86);
101 let captcha = (req.body.captcha || '').trim(); 102 let captcha = (req.body.captcha || '').trim();
102 - let diffCaptcha = _.get(req.session, 'phoneReg.captcha'); 103 + let diffCaptcha = _.get(req.session, 'captcha');
103 104
104 // error case: 没有验证码 105 // error case: 没有验证码
105 if (!diffCaptcha) { 106 if (!diffCaptcha) {
@@ -110,7 +111,7 @@ let verifyMobile = (req, res, next) => { @@ -110,7 +111,7 @@ let verifyMobile = (req, res, next) => {
110 }); 111 });
111 } 112 }
112 113
113 - delete req.session.phoneReg.captcha; // captcha 一次性 114 + delete req.session.captcha; // captcha 一次性
114 115
115 // error case: 验证码不匹配 116 // error case: 验证码不匹配
116 if (captcha !== diffCaptcha) { 117 if (captcha !== diffCaptcha) {
@@ -6,16 +6,13 @@ @@ -6,16 +6,13 @@
6 <span id="area-code" class="area-code">{{areaCode}}</span> 6 <span id="area-code" class="area-code">{{areaCode}}</span>
7 <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> 7 <input id="phone-num" class="input phone-num" type="text" placeholder="手机号">
8 </div> 8 </div>
9 - <!-- 验证码: start-->  
10 - <div class="passport-captcha row">  
11 - <div class="passport-captcha-img">  
12 - <img class="passport-captcha-png" src="{{captchaUrl}}"> 9 +
  10 + {{!--图片验证 start--}}
  11 + <div id="js-img-check">
  12 + <input type="hidden" name="captsrc" value="{{captsrc}}">
13 </div> 13 </div>
14 - <div class="passport-captcha-input">  
15 - <input id="js-captcha" type="text" placeholder="验证码">  
16 - </div>  
17 - </div>  
18 - <!-- 验证码: end--> 14 + {{!--图片验证 end--}}
  15 +
19 <span id="btn-next" class="btn btn-next disable row">下一步</span> 16 <span id="btn-next" class="btn btn-next disable row">下一步</span>
20 <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p> 17 <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p>
21 </div> 18 </div>
@@ -24,17 +24,29 @@ api.selectCssHack($('#country-select')); @@ -24,17 +24,29 @@ api.selectCssHack($('#country-select'));
24 24
25 api.bindClearEvt(); 25 api.bindClearEvt();
26 26
  27 +
  28 +// 图片验证码
  29 +let ImgCheck = require('plugin/img-check');
  30 +
  31 +let imgCheck = new ImgCheck('#js-img-check', {
  32 + useREM: {
  33 + rootFontSize: 40,
  34 + picWidth: 150
  35 + }
  36 +});
  37 +
  38 +imgCheck.init();
  39 +
27 /** 40 /**
28 * 必填校验 41 * 必填校验
29 */ 42 */
30 function checkEnableNext() { 43 function checkEnableNext() {
31 var phone = trim($phoneNum.val()); 44 var phone = trim($phoneNum.val());
32 var area = trim($countrySelect.val()); 45 var area = trim($countrySelect.val());
33 - var captcha = trim($captcha.val());  
34 46
35 var ret = true; 47 var ret = true;
36 48
37 - $.each([phone, area, captcha], function(i, val) { 49 + $.each([phone, area], function(i, val) {
38 if (!val) { 50 if (!val) {
39 ret = false; 51 ret = false;
40 return ret; 52 return ret;
@@ -44,24 +56,13 @@ function checkEnableNext() { @@ -44,24 +56,13 @@ function checkEnableNext() {
44 return ret; 56 return ret;
45 } 57 }
46 58
47 -  
48 -/**  
49 - * 刷新 校验码  
50 - */  
51 -function refreshCaptcha() {  
52 - $captcha.val('').focus();  
53 - $captchaPNG.attr('src', ['//m.yohobuy.com/passport/reg/captcha.png', '?t=', Date.now()].join(''));  
54 -}  
55 -  
56 -  
57 /* 59 /*
58 Event bind 60 Event bind
59 */ 61 */
60 $('.reg-page') 62 $('.reg-page')
61 - .on('input', '.phone-num, #js-captcha', function() { 63 + .on('input', '.phone-num', function() {
62 $btnNext.toggleClass('disable', !checkEnableNext()); 64 $btnNext.toggleClass('disable', !checkEnableNext());
63 - })  
64 - .on('click', '.passport-captcha-png', refreshCaptcha); 65 + });
65 66
66 $countrySelect.change(function() { 67 $countrySelect.change(function() {
67 $areaCode.text($countrySelect.val()); 68 $areaCode.text($countrySelect.val());
@@ -70,10 +71,10 @@ $countrySelect.change(function() { @@ -70,10 +71,10 @@ $countrySelect.change(function() {
70 $btnNext.on('touchstart', function() { 71 $btnNext.on('touchstart', function() {
71 var pn = trim($phoneNum.val()), 72 var pn = trim($phoneNum.val()),
72 areaCode = $countrySelect.val(), 73 areaCode = $countrySelect.val(),
73 - captcha = $captcha.val().trim(); 74 + captcha = imgCheck.getResults();
74 75
75 - if (!captcha) {  
76 - tip.show('请输入验证码'); 76 + if (captcha === '0000') {
  77 + tip.show('请将图片旋转到正确位置');
77 return false; 78 return false;
78 } 79 }
79 80
@@ -102,7 +103,7 @@ $btnNext.on('touchstart', function() { @@ -102,7 +103,7 @@ $btnNext.on('touchstart', function() {
102 if (data.code === 200) { 103 if (data.code === 200) {
103 location.href = data.data; 104 location.href = data.data;
104 } else { 105 } else {
105 - refreshCaptcha(); 106 + imgCheck.refresh();
106 107
107 showErrTip(data.message); 108 showErrTip(data.message);
108 requested = false; 109 requested = false;
@@ -110,7 +111,7 @@ $btnNext.on('touchstart', function() { @@ -110,7 +111,7 @@ $btnNext.on('touchstart', function() {
110 }, 111 },
111 error: function() { 112 error: function() {
112 showErrTip('出错了,请重试'); 113 showErrTip('出错了,请重试');
113 - refreshCaptcha(); 114 + imgCheck.refresh();
114 requested = false; 115 requested = false;
115 } 116 }
116 }); 117 });