Authored by 刘传洋

Merge branch 'feature/shoppingCart' of http://git.yoho.cn/fe/yohobuy-node into feature/shoppingCart

@@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
7 const captchaService = require('../models/captcha-service'); 7 const captchaService = require('../models/captcha-service');
8 const helpers = global.yoho.helpers; 8 const helpers = global.yoho.helpers;
9 9
10 -// 中间件  
11 const requiredAPI = (req, res, next) => { 10 const requiredAPI = (req, res, next) => {
12 let captchaToken = req.body.verifyCode || ''; 11 let captchaToken = req.body.verifyCode || '';
13 12
@@ -21,7 +20,6 @@ const requiredAPI = (req, res, next) => { @@ -21,7 +20,6 @@ const requiredAPI = (req, res, next) => {
21 } 20 }
22 }; 21 };
23 22
24 -// 重定向调用  
25 const requiredPage = (req, res, next) => { 23 const requiredPage = (req, res, next) => {
26 let captchaToken = req.body.verifyCode || ''; 24 let captchaToken = req.body.verifyCode || '';
27 25
@@ -32,29 +30,20 @@ const requiredPage = (req, res, next) => { @@ -32,29 +30,20 @@ const requiredPage = (req, res, next) => {
32 } 30 }
33 }; 31 };
34 32
35 -// 生成二维码  
36 -const generate = (req, res, next) => {  
37 - captchaService.generateCaptcha().then((result) => {  
38 - req.session.captcha = result.data.text; 33 +const generate = (req, res) => {
  34 + let width = req.query.w || 150;
  35 + let height = req.query.h || 50;
  36 + let length = +(req.query.l || 4);
  37 + let captcha = captchaService.generateCaptcha(width, height, length);
39 38
40 - if (result.code === 200) {  
41 - return res.json({  
42 - code: result.code,  
43 - data: {  
44 - images: result.data.images  
45 - }  
46 - });  
47 - } else {  
48 - return res.json({  
49 - code: result.code,  
50 - message: result.message  
51 - });  
52 - } 39 + req.session.captcha = captcha.text;
  40 + res.writeHead(200, {
  41 + 'Content-Type': 'image/png'
  42 + });
53 43
54 - }).catch(next); 44 + res.end(captcha.image);
55 }; 45 };
56 46
57 -// ajax 异步调用  
58 const checkAPI = (req, res) => { 47 const checkAPI = (req, res) => {
59 let captchaToken = req.body.verifyCode || ''; 48 let captchaToken = req.body.verifyCode || '';
60 49
@@ -207,8 +207,6 @@ const cert = { @@ -207,8 +207,6 @@ const cert = {
207 let email; 207 let email;
208 208
209 userService.profile(uid).then(info => { 209 userService.profile(uid).then(info => {
210 -  
211 - console.log(JSON.stringify(info));  
212 if (info && info.code === 200) { 210 if (info && info.code === 200) {
213 email = _.get(info, 'data.email'); 211 email = _.get(info, 'data.email');
214 } else { 212 } else {
@@ -73,7 +73,7 @@ let index = (req, res, next) => { @@ -73,7 +73,7 @@ let index = (req, res, next) => {
73 let area = req.query.area; 73 let area = req.query.area;
74 74
75 refer && res.cookie('refer', encodeURI(refer), { 75 refer && res.cookie('refer', encodeURI(refer), {
76 - domain: 'yohobuy.com' 76 + domain: config.cookieDomain
77 }); 77 });
78 78
79 regService.getRegData().then((result) => { 79 regService.getRegData().then((result) => {
@@ -4,30 +4,21 @@ @@ -4,30 +4,21 @@
4 4
5 'use strict'; 5 'use strict';
6 6
7 -const api = require('./captcha-api'); 7 +const _ = require('lodash');
  8 +const Captchapng = require('captchapng');
8 9
9 -exports.generateCaptcha = () => {  
10 - return api.gen().then((result) => {  
11 - if (result.code === 200) {  
12 - let codeStr = result.data.degrees.map((rotate) => {  
13 - return (4 - rotate / 90 % 4) % 4;  
14 - }).join(''); 10 +exports.generateCaptcha = (width, height, length) => {
  11 + let min = Math.pow(10, (length - 1 || 1));
  12 + let max = Math.pow(10, (length - 1 || 1)) * 9;
  13 + let token = '' + _.random(min, max);
15 14
16 - return {  
17 - code: 200,  
18 - data: {  
19 - text: codeStr,  
20 - images: `${result.data.verifiedGraphicCode}?imageView/2/w/240`  
21 - }  
22 - };  
23 - } else {  
24 - return {  
25 - code: 400,  
26 - message: '生成二维码失败,请重新刷新!',  
27 - data: {  
28 - text: 'yoho9636'  
29 - }  
30 - };  
31 - }  
32 - }); 15 + let png = new Captchapng(width, height, token);//
  16 +
  17 + png.color(0, 0, 0, 0); // First color: background (red, green, blue, alpha)
  18 + png.color(80, 80, 80, 255); // Second color: paint (red, green, blue, alpha)
  19 +
  20 + return {
  21 + image: new Buffer(png.getBase64(), 'base64'),
  22 + text: token
  23 + };
33 }; 24 };
@@ -24,10 +24,14 @@ @@ -24,10 +24,14 @@
24 <em>账户名不能为空</em> 24 <em>账户名不能为空</em>
25 </span> 25 </span>
26 </li> 26 </li>
27 -  
28 - <input name="verifyCode" id="captcha-value" type="hidden" value="">  
29 -  
30 - <li id='captcha-img' class="input-container-li clearfix"> 27 + <li class="input-container-li clearfix">
  28 + <input id="captcha" class="input va captcha" type="text" name="verifyCode" placeholder="验证码" autocomplete="off" maxlength="4">
  29 + <img id="captcha-img" class="captcha-img" src="{{captchaUrl}}" alt="">
  30 + <a id="change-captcha" class="link change-captcha">换一张</a>
  31 + <span id="captcha-err" class="err-tip captcha-err hide">
  32 + <i></i>
  33 + <em>验证码不能为空</em>
  34 + </span>
31 </li> 35 </li>
32 <li class="input-container-li clearfix"> 36 <li class="input-container-li clearfix">
33 <input name="refer" id="refer" type="hidden" value="http%3A%2F%2Fwww.yohobuy.com%2F"> 37 <input name="refer" id="refer" type="hidden" value="http%3A%2F%2Fwww.yohobuy.com%2F">
@@ -77,6 +77,15 @@ @@ -77,6 +77,15 @@
77 </li> 77 </li>
78 78
79 <li class="clearfix sms-captcha-img-wrap sms-login hide"> 79 <li class="clearfix sms-captcha-img-wrap sms-login hide">
  80 + <input id="sms-captcha-input" class="input va captcha" type="text" name="captcha"
  81 + placeholder="图形验证码"
  82 + autocomplete="off" maxlength="4">
  83 + <img id="sms-captcha-img" class="captcha-img" alt="">
  84 + <a class="link change-captcha">换一张</a>
  85 + <span class="err-tip hide">
  86 + <i></i>
  87 + <em></em>
  88 + </span>
80 </li> 89 </li>
81 90
82 <li class="relative clearfix sms-login hide"> 91 <li class="relative clearfix sms-login hide">
1 -<div class="register-page">  
2 - <ul>  
3 - <li class="clearfix">  
4 - <select id="region" class="region" name="region">  
5 - {{#each region}}  
6 - <option {{#if selected}}selected="selected"{{/if}} value="{{areaCode}}">{{name}}</option>  
7 - {{/each}}  
8 - </select>  
9 - </li>  
10 - <li class="clearfix" data-index="0">  
11 - <span id="country-code" class="country-code">{{location}}</span>  
12 - <input value="{{#if defaultMobile}}{{defaultMobile}}{{/if}}" id="phone-num" class="input va phone-num"  
13 - type="text" name="phoneNum" placeholder="请输入手机号码" autocomplete="off">  
14 - </li>  
15 - <li id="captcha-img" class="w330 clearfix" data-index="1">  
16 - </li>  
17 - <li class="clearfix" data-index="2">  
18 - <input id="msg-captcha" class="input va msg-captcha" type="text" name="msgCaptcha" placeholder="短信验证码"  
19 - autocomplete="off" maxlength="4">  
20 - <input id="send-captcha" class="btn send-captcha" type="button" value="获取短信验证码">  
21 - <span id="msg-tip" class="hide msg-tip">短信验证码已发送至您的手机,请查收</span>  
22 - </li>  
23 - <li class="clearfix" data-index="3">  
24 - <input id="pwd" class="input va pwd" name="pwd" placeholder="设置密码" autocomplete="off" maxlength="20"  
25 - type="password">  
26 - <div class="pwd-intensity-container">  
27 - <span class="pwd-intensity low"></span>  
28 - <span class="pwd-intensity mid"></span>  
29 - <span class="pwd-intensity high"></span>  
30 - </div>  
31 - <div id="pwd-tips" class="hide pwd-tips">  
32 - <div class="default" id="pwd-tip1"><i></i>密码只支持6-20位字符</div>  
33 - <div class="default" id="pwd-tip2"><i></i>由字母、 数字组合,不能包含特殊符号</div>  
34 - </div>  
35 - </li>  
36 -  
37 - <li class="items-container clearfix">  
38 - <input id="agree-terms" class="agree-terms" type="checkbox" checked="">  
39 - <span>  
40 - 我已阅读并同意遵守  
41 - <a class="link go-yoho-items" href="{{itemUrl}}" target="_blank">YOHO!BUY 有货服务条款</a>  
42 - </span>  
43 - </li>  
44 - <li class="clearfix">  
45 - <input name="refer" id="refer" type="hidden" value="{{referUrl}}">  
46 - <input id="register-btn" class="btn register-btn disable" type="submit" value="{{regBtnText}}" disabled="">  
47 - </li>  
48 - {{# loginUrl}}  
49 - <li class="quick-login-container">  
50 - 我已注册YOHO!BUY 有货账号  
51 - <a class="link go-login" href="{{.}}">快速登录</a>  
52 - </li>  
53 - {{/loginUrl}}  
54 -  
55 - {{# skipUrl}}  
56 - <li class="skip-user-info">  
57 - <a href="{{.}}">跳过此步</a>  
58 - </li>  
59 - {{/skipUrl}}  
60 -  
61 - </ul>  
62 - <div id="err-tip" class="err-tip hide">  
63 - <span></span>  
64 - <b></b>  
65 - </div>  
66 - <input name="" type="hidden" id="open-id" value="{{openId}}"/>  
67 - <input name="" type="hidden" id="source-type" value="{{sourceType}}"/>  
68 -</div> 1 +<div class="register-page">
  2 + <ul>
  3 + <li class="clearfix">
  4 + <select id="region" class="region" name="region">
  5 + {{#each region}}
  6 + <option {{#if selected}}selected="selected"{{/if}} value="{{areaCode}}">{{name}}</option>
  7 + {{/each}}
  8 + </select>
  9 + </li>
  10 + <li class="clearfix" data-index="0">
  11 + <span id="country-code" class="country-code">{{location}}</span>
  12 + <input value="{{#if defaultMobile}}{{defaultMobile}}{{/if}}" id="phone-num" class="input va phone-num"
  13 + type="text" name="phoneNum" placeholder="请输入手机号码" autocomplete="off">
  14 + </li>
  15 + <li class="w330 clearfix" data-index="1">
  16 + <input id="captcha" class="input va captcha" type="text" name="captcha" placeholder="图形验证码"
  17 + autocomplete="off" maxlength="4">
  18 + <img id="captcha-img" class="captcha-img" src="{{captchaUrl}}" alt="">
  19 + <a class="link change-captcha">换一张</a>
  20 + </li>
  21 + <li class="clearfix" data-index="2">
  22 + <input id="msg-captcha" class="input va msg-captcha" type="text" name="msgCaptcha" placeholder="短信验证码"
  23 + autocomplete="off" maxlength="4">
  24 + <input id="send-captcha" class="btn send-captcha disable" type="button" value="获取短信验证码">
  25 + <span id="msg-tip" class="hide msg-tip">短信验证码已发送至您的手机,请查收</span>
  26 + </li>
  27 + <li class="clearfix" data-index="3">
  28 + <input id="pwd" class="input va pwd" name="pwd" placeholder="设置密码" autocomplete="off" maxlength="20"
  29 + type="password">
  30 + <div class="pwd-intensity-container">
  31 + <span class="pwd-intensity low"></span>
  32 + <span class="pwd-intensity mid"></span>
  33 + <span class="pwd-intensity high"></span>
  34 + </div>
  35 + <div id="pwd-tips" class="hide pwd-tips">
  36 + <div class="default" id="pwd-tip1"><i></i>密码只支持6-20位字符</div>
  37 + <div class="default" id="pwd-tip2"><i></i>由字母、 数字组合,不能包含特殊符号</div>
  38 + </div>
  39 + </li>
  40 +
  41 + <li class="items-container clearfix">
  42 + <input id="agree-terms" class="agree-terms" type="checkbox" checked="">
  43 + <span>
  44 + 我已阅读并同意遵守
  45 + <a class="link go-yoho-items" href="{{itemUrl}}" target="_blank">YOHO!BUY 有货服务条款</a>
  46 + </span>
  47 + </li>
  48 + <li class="clearfix">
  49 + <input name="refer" id="refer" type="hidden" value="{{referUrl}}">
  50 + <input id="register-btn" class="btn register-btn disable" type="submit" value="{{regBtnText}}" disabled="">
  51 + </li>
  52 + {{# loginUrl}}
  53 + <li class="quick-login-container">
  54 + 我已注册YOHO!BUY 有货账号
  55 + <a class="link go-login" href="{{.}}">快速登录</a>
  56 + </li>
  57 + {{/loginUrl}}
  58 +
  59 + {{# skipUrl}}
  60 + <li class="skip-user-info">
  61 + <a href="{{.}}">跳过此步</a>
  62 + </li>
  63 + {{/skipUrl}}
  64 +
  65 + </ul>
  66 + <div id="err-tip" class="err-tip hide">
  67 + <span></span>
  68 + <b></b>
  69 + </div>
  70 + <input name="" type="hidden" id="open-id" value="{{openId}}"/>
  71 + <input name="" type="hidden" id="source-type" value="{{sourceType}}"/>
  72 +</div>
@@ -15,7 +15,9 @@ @@ -15,7 +15,9 @@
15 <p class="star-text">非常满意</p> 15 <p class="star-text">非常满意</p>
16 </div> 16 </div>
17 <div class="detail-reason"> 17 <div class="detail-reason">
18 - <div class="discontent"></div> 18 + <div class="dis-wrap">
  19 + <div class="discontent"></div>
  20 + </div>
19 <textarea class="other-reason" maxlength="50" placeholder="请您输入不满意的其他原因" spellcheck="false"></textarea> 21 <textarea class="other-reason" maxlength="50" placeholder="请您输入不满意的其他原因" spellcheck="false"></textarea>
20 </div> 22 </div>
21 </div> 23 </div>
1 { 1 {
2 "name": "yohobuy-node", 2 "name": "yohobuy-node",
3 - "version": "5.3.0", 3 + "version": "5.3.2",
4 "private": true, 4 "private": true,
5 "description": "A New Yohobuy Project With Express", 5 "description": "A New Yohobuy Project With Express",
6 "repository": { 6 "repository": {
@@ -8,8 +8,6 @@ var $ = require('yoho-jquery'); @@ -8,8 +8,6 @@ var $ = require('yoho-jquery');
8 8
9 var regx = require('../common/mail-phone-regx'); 9 var regx = require('../common/mail-phone-regx');
10 10
11 -var Captcha = require('../../plugins/captcha');  
12 -  
13 var emailAc = require('../common/ac-email'); // 邮箱自动完成 11 var emailAc = require('../common/ac-email'); // 邮箱自动完成
14 12
15 var emailReg = regx.emailRegx, 13 var emailReg = regx.emailRegx,
@@ -22,15 +20,24 @@ var $cr = $('#country-code-hide'), @@ -22,15 +20,24 @@ var $cr = $('#country-code-hide'),
22 $cc = $('#country-code'), 20 $cc = $('#country-code'),
23 $btn = $('#find-btn'), 21 $btn = $('#find-btn'),
24 $accErr = $('#account-err'), 22 $accErr = $('#account-err'),
  23 + $caErr = $('#captcha-err'),
25 caCount = 4, // 验证码位数 24 caCount = 4, // 验证码位数
26 hasPh = false, 25 hasPh = false,
27 - captcha = new Captcha('#captcha-img').init(); 26 + hasCa = false;
28 27
29 require('../../simple-header'); 28 require('../../simple-header');
30 require('yoho-jquery-placeholder'); 29 require('yoho-jquery-placeholder');
31 30
  31 +function imgcode() {
  32 + var time = new Date(),
  33 + $captchaImg = $('#captcha-img'),
  34 + captchaImgSrc = $captchaImg.attr('src').split('?')[0];
  35 +
  36 + $('#captcha-img').attr('src', captchaImgSrc + '?t=' + time.getTime());
  37 +}
  38 +
32 function enableBtn() { 39 function enableBtn() {
33 - if (hasPh) { 40 + if (hasPh && hasCa) {
34 $btn.removeClass('disable').prop('disabled', false); 41 $btn.removeClass('disable').prop('disabled', false);
35 } else { 42 } else {
36 $btn.addClass('disable').prop('disabled', true); 43 $btn.addClass('disable').prop('disabled', true);
@@ -38,27 +45,33 @@ function enableBtn() { @@ -38,27 +45,33 @@ function enableBtn() {
38 } 45 }
39 46
40 function authcode() { 47 function authcode() {
41 - return $.ajax({ 48 + if (!hasPh || !hasCa) {
  49 + enableBtn();
  50 + return;
  51 + }
  52 +
  53 + $.ajax({
42 type: 'POST', 54 type: 'POST',
43 url: '/passport/back/authcode', 55 url: '/passport/back/authcode',
44 data: { 56 data: {
45 - verifyCode: captcha.getResults(), 57 + verifyCode: $.trim($ca.val()),
46 phoneNum: $phoneNum.val(), 58 phoneNum: $phoneNum.val(),
47 area: $cr.val() 59 area: $cr.val()
48 } 60 }
49 61
50 }).then(function(data) { 62 }).then(function(data) {
51 if (data.code === 200) { 63 if (data.code === 200) {
52 - $('#captcha-value').val(captcha.getResults());  
53 - return $.Deferred().resolve().promise(); //eslint-disable-line 64 + hasCa = true;
54 } else if (data.code === 402) { 65 } else if (data.code === 402) {
  66 + hasPh = false;
  67 + hasCa = true;
55 $accErr.removeClass('hide').find('em').text('该账号不存在'); 68 $accErr.removeClass('hide').find('em').text('该账号不存在');
56 $phoneNum.addClass('error'); 69 $phoneNum.addClass('error');
57 - return $.Deferred().reject().promise();//eslint-disable-line  
58 } else if (data.code === 400) { 70 } else if (data.code === 400) {
59 - captcha.showTip();  
60 - return $.Deferred().reject().promise();//eslint-disable-line 71 + hasCa = false;
  72 + imgcode();
61 } 73 }
  74 + enableBtn();
62 }); 75 });
63 } 76 }
64 77
@@ -88,6 +101,7 @@ function vaPn(v) { @@ -88,6 +101,7 @@ function vaPn(v) {
88 pass = false; 101 pass = false;
89 } 102 }
90 hasPh = pass; 103 hasPh = pass;
  104 + authcode();
91 105
92 return { 106 return {
93 pass: pass, 107 pass: pass,
@@ -95,13 +109,26 @@ function vaPn(v) { @@ -95,13 +109,26 @@ function vaPn(v) {
95 }; 109 };
96 } 110 }
97 111
  112 +function vaCa() {
  113 + var v = $.trim($ca.val());
  114 +
  115 + if (v === '' || v.length < caCount) {
  116 + hasCa = false;
  117 + enableBtn();
  118 + return;
  119 + }
  120 +
  121 + hasCa = true;
  122 +
  123 + authcode();
  124 +}
  125 +
98 emailAc($phoneNum, function() { 126 emailAc($phoneNum, function() {
99 var pnVa = vaPn($phoneNum.val()); 127 var pnVa = vaPn($phoneNum.val());
100 128
101 if (pnVa.pass) { 129 if (pnVa.pass) {
102 $accErr.addClass('hide'); 130 $accErr.addClass('hide');
103 $phoneNum.removeClass('error'); 131 $phoneNum.removeClass('error');
104 - enableBtn();  
105 } else { 132 } else {
106 $accErr.removeClass('hide').find('em').text(pnVa.errTxt); 133 $accErr.removeClass('hide').find('em').text(pnVa.errTxt);
107 $phoneNum.addClass('error'); 134 $phoneNum.addClass('error');
@@ -114,6 +141,10 @@ $ca.attr('maxlength', caCount); @@ -114,6 +141,10 @@ $ca.attr('maxlength', caCount);
114 // IE8 placeholder 141 // IE8 placeholder
115 $('input').placeholder(); 142 $('input').placeholder();
116 143
  144 +$('#change-captcha, #captcha-img').on('click', function() {
  145 + imgcode();
  146 +});
  147 +
117 $cc.on('click', function(e) { 148 $cc.on('click', function(e) {
118 e.stopPropagation(); 149 e.stopPropagation();
119 if ($ccList.css('style') === 'block') { 150 if ($ccList.css('style') === 'block') {
@@ -153,8 +184,6 @@ $(document).click(function() { @@ -153,8 +184,6 @@ $(document).click(function() {
153 } 184 }
154 }); 185 });
155 186
156 -captcha.refresh();  
157 -  
158 $phoneNum.keyup(function() { 187 $phoneNum.keyup(function() {
159 vaPn($.trim($(this).val())); 188 vaPn($.trim($(this).val()));
160 }).focus(function() { 189 }).focus(function() {
@@ -164,22 +193,43 @@ $phoneNum.keyup(function() { @@ -164,22 +193,43 @@ $phoneNum.keyup(function() {
164 $accErr.addClass('hide'); 193 $accErr.addClass('hide');
165 }); 194 });
166 195
167 -// 下一步 196 +// 验证码在鼠标移开后验证, keyup时不再验证
  197 +$ca.blur(function() {
  198 + var errTxt = $.trim($ca.val()) === '' ? '验证码不能为空' : '验证码不正确';
  199 +
  200 + if (hasCa) {
  201 + $caErr.addClass('hide');
  202 + $ca.removeClass('error');
  203 + } else {
  204 + $caErr.removeClass('hide').find('em').text(errTxt);
  205 + $ca.addClass('error');
  206 +
  207 + // 验证码错误则刷新验证码
  208 + if ($ca.val() < caCount) {
  209 +
  210 + // 防止重复刷新验证码
  211 + imgcode();
  212 + }
  213 + }
  214 +}).focus(function() {
  215 + $(this).removeClass('error');
  216 +
  217 + // focus隐藏错误提示
  218 + $caErr.addClass('hide');
  219 +}).keyup(function() {
  220 + vaCa();
  221 +});
  222 +
168 $('#find-btn').click(function(e) { 223 $('#find-btn').click(function(e) {
  224 +
169 if (/^[0-9]+$/.test($.trim($phoneNum.val()))) { 225 if (/^[0-9]+$/.test($.trim($phoneNum.val()))) {
170 $('#find-form').attr('action', '/passport/back/mobile'); 226 $('#find-form').attr('action', '/passport/back/mobile');
171 } 227 }
172 -  
173 if ($(this).hasClass('disable')) { 228 if ($(this).hasClass('disable')) {
174 return; 229 return;
175 } 230 }
176 -  
177 - if (hasPh) {  
178 - authcode().then(function() {  
179 - $('#back-form').submit();  
180 - }); 231 + if (!hasCa || !hasPh) {
  232 + e.preventDefault();
  233 + return true;
181 } 234 }
182 -  
183 - e.preventDefault();  
184 - return true;  
185 }); 235 });
@@ -31,8 +31,7 @@ @@ -31,8 +31,7 @@
31 * 变成的设备登录:分为桌面(普通登录和手机验证码登录)和手机登录(二维码登录)。 31 * 变成的设备登录:分为桌面(普通登录和手机验证码登录)和手机登录(二维码登录)。
32 */ 32 */
33 33
34 -var $ = require('yoho-jquery'),  
35 - Captcha = require('../../plugins/captcha'); 34 +var $ = require('yoho-jquery');
36 35
37 // 密码输入帐号 36 // 密码输入帐号
38 var $accountInput1 = $('#account1'), 37 var $accountInput1 = $('#account1'),
@@ -53,11 +52,12 @@ var $accountInput1 = $('#account1'), @@ -53,11 +52,12 @@ var $accountInput1 = $('#account1'),
53 }, 52 },
54 53
55 // 图像验证码 54 // 图像验证码
  55 + $captchaImgInput = $('#captcha'),
56 $captchaImgWrapper = $('.captcha-wrap'), 56 $captchaImgWrapper = $('.captcha-wrap'),
57 - captchaImg = new Captcha('.captcha-wrap').init(),  
58 - $showCaptchaImg = false, 57 + $captchaImgPic = $captchaImgWrapper.find('#captcha-img'),
  58 + $showCaptchImg = false,
59 getCaptchaImgVal = function() { 59 getCaptchaImgVal = function() {
60 - return captchaImg.getResults(); 60 + return $.trim($captchaImgInput.val());
61 }, 61 },
62 62
63 // 短信验证码 63 // 短信验证码
@@ -70,9 +70,11 @@ var $accountInput1 = $('#account1'), @@ -70,9 +70,11 @@ var $accountInput1 = $('#account1'),
70 getCaptchaSmsTokenVal = function() { // 短信登录凭证 70 getCaptchaSmsTokenVal = function() { // 短信登录凭证
71 return $.trim($captchaSmsTokenHideInput.val()); 71 return $.trim($captchaSmsTokenHideInput.val());
72 }, 72 },
73 - smsCaptchaImg = new Captcha('.sms-captcha-img-wrap').init(), 73 + $smsCaptchaImgWrapper = $('.sms-captcha-img-wrap'),
  74 + $smsCaptchaImgInput = $smsCaptchaImgWrapper.find('#sms-captcha-input'),
  75 + $smsCaptchaImgPic = $smsCaptchaImgWrapper.find('#sms-captcha-img'),
74 getSmsCaptchaImgVal = function() { // 短信登录图形验证码 76 getSmsCaptchaImgVal = function() { // 短信登录图形验证码
75 - return smsCaptchaImg.getResults(); 77 + return $.trim($smsCaptchaImgInput.val());
76 }, 78 },
77 79
78 // 区域选择 80 // 区域选择
@@ -104,12 +106,17 @@ var $accountInput1 = $('#account1'), @@ -104,12 +106,17 @@ var $accountInput1 = $('#account1'),
104 var $accountTip1 = $accountInput1.siblings('.err-tip'), 106 var $accountTip1 = $accountInput1.siblings('.err-tip'),
105 $accountTip2 = $accountInput2.siblings('.err-tip'), 107 $accountTip2 = $accountInput2.siblings('.err-tip'),
106 $passwordTip = $passwordInput.siblings('.err-tip'), 108 $passwordTip = $passwordInput.siblings('.err-tip'),
  109 + $captchaImgTip = $captchaImgInput.siblings('.err-tip'),
107 $captchaSmsTip = $captchaSmsInput.siblings('.err-tip'), 110 $captchaSmsTip = $captchaSmsInput.siblings('.err-tip'),
  111 + $smsCaptchaImgTip = $smsCaptchaImgInput.siblings('.err-tip'),
108 $capsLock = $('#caps-lock'); 112 $capsLock = $('#caps-lock');
109 113
110 var mailPhoneRegx = require('../common/mail-phone-regx'), // 邮箱格式验证 114 var mailPhoneRegx = require('../common/mail-phone-regx'), // 邮箱格式验证
111 mailAc = require('../common/ac-email'); // 邮箱自动完成 115 mailAc = require('../common/ac-email'); // 邮箱自动完成
112 116
  117 +// 图像验证码URL
  118 +var CAPTCHA_IMG_URL = '/passport/imagesNode?t=';
  119 +
113 // 刷新手机短信图形验证码 120 // 刷新手机短信图形验证码
114 var refreshSmsImgCallBack = $.Callbacks(); // eslint-disable-line 121 var refreshSmsImgCallBack = $.Callbacks(); // eslint-disable-line
115 122
@@ -265,8 +272,10 @@ accountChangeEvent.add(function(type) { @@ -265,8 +272,10 @@ accountChangeEvent.add(function(type) {
265 hideSmsCaptchaImgTip(); // eslint-disable-line 272 hideSmsCaptchaImgTip(); // eslint-disable-line
266 273
267 $passwordInput.val(''); 274 $passwordInput.val('');
  275 + $captchaImgInput.val('');
268 276
269 $captchaSmsInput.val(''); 277 $captchaSmsInput.val('');
  278 + $smsCaptchaImgInput.val('');
270 $captchaSmsTokenHideInput.val(''); 279 $captchaSmsTokenHideInput.val('');
271 280
272 if (type === AccountLoginData.QRCodeLogin.name) { 281 if (type === AccountLoginData.QRCodeLogin.name) {
@@ -276,14 +285,13 @@ accountChangeEvent.add(function(type) { @@ -276,14 +285,13 @@ accountChangeEvent.add(function(type) {
276 285
277 // 密码登录的图形验证码 286 // 密码登录的图形验证码
278 if (type === AccountLoginData.PasswordLogin.name) { 287 if (type === AccountLoginData.PasswordLogin.name) {
279 - if ($showCaptchaImg) { 288 + if ($showCaptchImg) {
280 $captchaImgWrapper.removeClass('hide'); 289 $captchaImgWrapper.removeClass('hide');
281 - captchaImg.refresh();  
282 } 290 }
283 } 291 }
284 292
285 if (type === AccountLoginData.SMSLogin.name) { 293 if (type === AccountLoginData.SMSLogin.name) {
286 - if ($showCaptchaImg) { 294 + if ($showCaptchImg) {
287 $captchaImgWrapper.addClass('hide'); 295 $captchaImgWrapper.addClass('hide');
288 } 296 }
289 } 297 }
@@ -293,7 +301,7 @@ accountChangeEvent.add(function(type) { @@ -293,7 +301,7 @@ accountChangeEvent.add(function(type) {
293 accountChangeEvent.add(function(type) { 301 accountChangeEvent.add(function(type) {
294 if (type === AccountLoginData.SMSLogin.name) { 302 if (type === AccountLoginData.SMSLogin.name) {
295 $accountInput2.val($accountInput1.val()); 303 $accountInput2.val($accountInput1.val());
296 - refreshSmsCaptchaImg(); 304 + $smsCaptchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
297 } else { 305 } else {
298 $accountInput1.val($accountInput2.val()); 306 $accountInput1.val($accountInput2.val());
299 } 307 }
@@ -308,7 +316,8 @@ mobileTipShowOnce.add(function() { @@ -308,7 +316,8 @@ mobileTipShowOnce.add(function() {
308 }); 316 });
309 317
310 refreshSmsImgCallBack.add(function() { 318 refreshSmsImgCallBack.add(function() {
311 - refreshSmsCaptchaImg(); 319 + $smsCaptchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
  320 + $smsCaptchaImgInput.val('');
312 }); 321 });
313 322
314 /** ************************************************************************/ 323 /** ************************************************************************/
@@ -365,8 +374,12 @@ function hidePasswordTip() { @@ -365,8 +374,12 @@ function hidePasswordTip() {
365 374
366 /** ************************************************************************/ 375 /** ************************************************************************/
367 376
  377 +function showCaptchaImgTip(msg) {
  378 + return errTipShow($captchaImgTip, $captchaImgInput, msg);
  379 +}
  380 +
368 function hideCaptchaImgTip() { 381 function hideCaptchaImgTip() {
369 - return captchaImg.hide(); 382 + return errTipHide($captchaImgTip, $captchaImgInput);
370 } 383 }
371 384
372 /** ************************************************************************/ 385 /** ************************************************************************/
@@ -382,13 +395,13 @@ function hideCaptchaSmsTip() { @@ -382,13 +395,13 @@ function hideCaptchaSmsTip() {
382 395
383 /** ************************************************************************/ 396 /** ************************************************************************/
384 397
385 -function showSmsCaptchaImgTip() { 398 +function showSmsCaptchaImgTip(msg) {
386 refreshSmsImgCallBack.fire(); 399 refreshSmsImgCallBack.fire();
387 - smsCaptchaImg.showTip(); 400 + return errTipShow($smsCaptchaImgTip, $smsCaptchaImgInput, msg);
388 } 401 }
389 402
390 function hideSmsCaptchaImgTip() { 403 function hideSmsCaptchaImgTip() {
391 - smsCaptchaImg.hideTip(); 404 + return errTipHide($smsCaptchaImgTip, $smsCaptchaImgInput);
392 } 405 }
393 406
394 /** ************************************************************************/ 407 /** ************************************************************************/
@@ -480,6 +493,7 @@ function validateAccount() { @@ -480,6 +493,7 @@ function validateAccount() {
480 .then(currentLogin.hideAccountTip); 493 .then(currentLogin.hideAccountTip);
481 } 494 }
482 495
  496 +
483 /** ************************************************************************/ 497 /** ************************************************************************/
484 /* 密码验证 */ 498 /* 密码验证 */
485 /** ************************************************************************/ 499 /** ************************************************************************/
@@ -517,8 +531,59 @@ function validatePasswordLocal() { @@ -517,8 +531,59 @@ function validatePasswordLocal() {
517 /** ************************************************************************/ 531 /** ************************************************************************/
518 /* 图形验证码 */ 532 /* 图形验证码 */
519 /** ************************************************************************/ 533 /** ************************************************************************/
  534 +
  535 +function validateCaptchaImgLocal() {
  536 + var captcha = getCaptchaImgVal(),
  537 + err;
  538 +
  539 + var defer = $.Deferred(); // eslint-disable-line
  540 +
  541 + if (captcha !== '') {
  542 + if (captcha.length !== 4) {
  543 + err = '请输入长度为4字符的验证码';
  544 +
  545 + defer.reject();
  546 + } else {
  547 +
  548 + defer.resolve();
  549 + }
  550 + } else {
  551 + err = '请输入验证码';
  552 +
  553 + defer.reject();
  554 + }
  555 +
  556 + if (defer.state() === 'resolved') {
  557 + hideCaptchaImgTip();
  558 + } else {
  559 + showCaptchaImgTip(err);
  560 + }
  561 +
  562 + return defer.promise();
  563 +}
  564 +
520 function validateCaptchaImgAsync() { 565 function validateCaptchaImgAsync() {
521 - return captchaImg.check(); 566 + return $.ajax({
  567 + url: '/passport/captcha/img',
  568 + type: 'POST',
  569 + data: {
  570 + verifyCode: getCaptchaImgVal()
  571 + }
  572 + }).then(function(result) {
  573 + var defer = $.Deferred(); // eslint-disable-line
  574 +
  575 + if (result.code === 200) {
  576 + hideCaptchaImgTip();
  577 +
  578 + defer.resolve();
  579 + } else {
  580 + showCaptchaImgTip('验证码不正确');
  581 +
  582 + defer.reject();
  583 + }
  584 +
  585 + return defer.promise();
  586 + });
522 } 587 }
523 588
524 function validateCaptchaImg() { 589 function validateCaptchaImg() {
@@ -527,7 +592,8 @@ function validateCaptchaImg() { @@ -527,7 +592,8 @@ function validateCaptchaImg() {
527 return $.Deferred().resolve().promise(); //eslint-disable-line 592 return $.Deferred().resolve().promise(); //eslint-disable-line
528 } 593 }
529 594
530 - return validateCaptchaImgAsync() 595 + return validateCaptchaImgLocal()
  596 + .then(validateCaptchaImgAsync)
531 .then(hideCaptchaSmsTip); 597 .then(hideCaptchaSmsTip);
532 } 598 }
533 599
@@ -642,12 +708,64 @@ function sendCaptchaSmsAsync() { @@ -642,12 +708,64 @@ function sendCaptchaSmsAsync() {
642 /* 短信验证图形验证 */ 708 /* 短信验证图形验证 */
643 /** ************************************************************************/ 709 /** ************************************************************************/
644 710
645 -function validateSmsCaptchaImg() {  
646 - return smsCaptchaImg.check(); 711 +function smsCaptchaImgLocal() {
  712 + var captcha = getSmsCaptchaImgVal(),
  713 + err;
  714 +
  715 + var defer = $.Deferred(); // eslint-disable-line
  716 +
  717 + if (captcha !== '') {
  718 + if (captcha.length !== 4) {
  719 + err = '请输入长度为4字符的验证码';
  720 +
  721 + defer.reject();
  722 + } else {
  723 +
  724 + defer.resolve();
  725 + }
  726 + } else {
  727 + err = '请输入验证码';
  728 +
  729 + defer.reject();
  730 + }
  731 +
  732 + if (defer.state() === 'resolved') {
  733 + hideSmsCaptchaImgTip();
  734 + } else {
  735 + showSmsCaptchaImgTip(err);
  736 + }
  737 +
  738 + return defer.promise();
  739 +}
  740 +
  741 +function smsCaptchaImgAsync() {
  742 + return $.ajax({
  743 + url: '/passport/captcha/img',
  744 + type: 'POST',
  745 + data: {
  746 + verifyCode: getSmsCaptchaImgVal()
  747 + }
  748 + }).then(function(result) {
  749 + var defer = $.Deferred(); // eslint-disable-line
  750 +
  751 + if (result.code === 200) {
  752 + hideSmsCaptchaImgTip();
  753 +
  754 + defer.resolve();
  755 + } else {
  756 + showSmsCaptchaImgTip('验证码不正确');
  757 +
  758 + defer.reject();
  759 + }
  760 +
  761 + return defer.promise();
  762 + });
647 } 763 }
648 764
649 -function refreshSmsCaptchaImg() {  
650 - smsCaptchaImg.refresh(); 765 +function validateSmsCaptchaImg() {
  766 + return smsCaptchaImgLocal()
  767 + .then(smsCaptchaImgAsync)
  768 + .then(hideSmsCaptchaImgTip);
651 } 769 }
652 770
653 /** ************************************************************************/ 771 /** ************************************************************************/
@@ -876,11 +994,10 @@ function loginAsync() { @@ -876,11 +994,10 @@ function loginAsync() {
876 } 994 }
877 995
878 function showCaptchaImgPic() { 996 function showCaptchaImgPic() {
879 - captchaImg.refresh().then(function() {  
880 - $captchaImgWrapper.removeClass('hide');  
881 - });  
882 -  
883 - $showCaptchaImg = true; 997 + $captchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
  998 + $captchaImgInput.val('');
  999 + $captchaImgWrapper.removeClass('hide');
  1000 + $showCaptchImg = true;
884 } 1001 }
885 1002
886 // 设置 refer 信息 1003 // 设置 refer 信息
@@ -964,6 +1081,10 @@ $passwordInput.on('blur', function() { @@ -964,6 +1081,10 @@ $passwordInput.on('blur', function() {
964 $capsLock.addClass('hide'); 1081 $capsLock.addClass('hide');
965 }); 1082 });
966 1083
  1084 +// 图像验证码输入框事件
  1085 +$captchaImgInput.on('blur', validateCaptchaImg);
  1086 +
  1087 +
967 /** ************************************************************************/ 1088 /** ************************************************************************/
968 1089
969 // 短信下手机输入框失去焦点:本地验证格式 1090 // 短信下手机输入框失去焦点:本地验证格式
@@ -971,6 +1092,11 @@ $accountInput2.on('blur', function() { @@ -971,6 +1092,11 @@ $accountInput2.on('blur', function() {
971 return currentLogin.validateAccountLocal(); 1092 return currentLogin.validateAccountLocal();
972 }); 1093 });
973 1094
  1095 +// 图形验证码失去焦点验证
  1096 +$smsCaptchaImgInput.on('blur', function() {
  1097 + validateSmsCaptchaImg();
  1098 +});
  1099 +
974 // sms验证码输入框事件 1100 // sms验证码输入框事件
975 $captchaSmsInput.on('blur', validateCaptchaSms); 1101 $captchaSmsInput.on('blur', validateCaptchaSms);
976 1102
@@ -1010,6 +1136,16 @@ $('.va').on('focus', function() { @@ -1010,6 +1136,16 @@ $('.va').on('focus', function() {
1010 $this.siblings('.err-tip').addClass('hide'); 1136 $this.siblings('.err-tip').addClass('hide');
1011 }); 1137 });
1012 1138
  1139 +// 验证码刷新
  1140 +$captchaImgWrapper.on('click', '.change-captcha, .captcha-img', function() {
  1141 + $captchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
  1142 +});
  1143 +
  1144 +// 刷新短信图形验证码
  1145 +$smsCaptchaImgWrapper.on('click', '.change-captcha, .captcha-img', function() {
  1146 + $smsCaptchaImgPic.attr('src', CAPTCHA_IMG_URL + $.now());
  1147 +});
  1148 +
1013 // 切换登录模式:密码登录和短信登录 1149 // 切换登录模式:密码登录和短信登录
1014 $PhoneLoginSwitcher.on('click', 'div', function() { 1150 $PhoneLoginSwitcher.on('click', 'div', function() {
1015 var $this = $(this), 1151 var $this = $(this),
@@ -5,8 +5,7 @@ @@ -5,8 +5,7 @@
5 5
6 var $ = require('yoho-jquery'), 6 var $ = require('yoho-jquery'),
7 regValidate = require('../common/mail-phone-regx'), 7 regValidate = require('../common/mail-phone-regx'),
8 - computeComplex = require('../common/pwd-strength'),  
9 - Captcha = require('../../plugins/captcha'); 8 + computeComplex = require('../common/pwd-strength');
10 9
11 var $registerPage = $('.register-page'), 10 var $registerPage = $('.register-page'),
12 $pwdTips = $('#pwd-tips'), 11 $pwdTips = $('#pwd-tips'),
@@ -16,19 +15,18 @@ var $registerPage = $('.register-page'), @@ -16,19 +15,18 @@ var $registerPage = $('.register-page'),
16 $countDown = $('#count-down'), 15 $countDown = $('#count-down'),
17 $successBtn = $('.success-btn'), 16 $successBtn = $('.success-btn'),
18 countDown = 5, 17 countDown = 5,
19 - clearT,  
20 - captchaImage = new Captcha('#captcha-img').init(); 18 + clearT;
21 19
22 var $sendCaptcha = $('#send-captcha'), 20 var $sendCaptcha = $('#send-captcha'),
  21 + caCount = 4,
23 validateResult = []; 22 validateResult = [];
24 23
25 var $pn = $('#phone-num'), 24 var $pn = $('#phone-num'),
26 $mc = $('#msg-captcha'), 25 $mc = $('#msg-captcha'),
27 $pwd = $('#pwd'), 26 $pwd = $('#pwd'),
28 - getCaptchaImageVal = function() {  
29 - return captchaImage.getResults();  
30 - },  
31 - timeSecond = 0; 27 + $repwd = $('#repwd'),
  28 + $ca = $('#captcha'),
  29 + timeResidue = 0;
32 30
33 // 密码强度验证 31 // 密码强度验证
34 var $pwdIntensity = $('.pwd-intensity'), 32 var $pwdIntensity = $('.pwd-intensity'),
@@ -38,6 +36,9 @@ var $pwdIntensity = $('.pwd-intensity'), @@ -38,6 +36,9 @@ var $pwdIntensity = $('.pwd-intensity'),
38 var $region = $('#country-code'), 36 var $region = $('#country-code'),
39 $regionSelect = $('#region'); 37 $regionSelect = $('#region');
40 38
  39 +var isPwd = false,
  40 + pwdVal;
  41 +
41 var pwdReg = regValidate.pwdValidateRegx; 42 var pwdReg = regValidate.pwdValidateRegx;
42 43
43 var $curErrContainer; 44 var $curErrContainer;
@@ -47,13 +48,20 @@ var oldPhone = ''; // 如果手机号改变时刷新验证码 @@ -47,13 +48,20 @@ var oldPhone = ''; // 如果手机号改变时刷新验证码
47 require('../../simple-header'); 48 require('../../simple-header');
48 require('yoho-jquery-placeholder'); 49 require('yoho-jquery-placeholder');
49 50
  51 +// 验证码位数
  52 +$ca.attr('maxlength', caCount);
  53 +
50 // 密码规则提示 54 // 密码规则提示
51 $pwd.focus(function() { 55 $pwd.focus(function() {
52 $pwdTips.removeClass('hide'); 56 $pwdTips.removeClass('hide');
  57 + isPwd = true;
  58 + pwdVal = $(this).val();
53 }).blur(function() { 59 }).blur(function() {
54 $pwdTips.addClass('hide'); 60 $pwdTips.addClass('hide');
  61 + isPwd = false;
55 }); 62 });
56 63
  64 +
57 // IE8 placeholder 65 // IE8 placeholder
58 $('[placeholder]').placeholder(); 66 $('[placeholder]').placeholder();
59 67
@@ -65,7 +73,7 @@ validateResult = [ @@ -65,7 +73,7 @@ validateResult = [
65 status: false // 当前的状态 73 status: false // 当前的状态
66 }, 74 },
67 { 75 {
68 - id: 'captcha-img', 76 + id: 'captcha',
69 message: '', 77 message: '',
70 status: false 78 status: false
71 }, 79 },
@@ -86,14 +94,13 @@ validateResult = [ @@ -86,14 +94,13 @@ validateResult = [
86 } 94 }
87 ]; 95 ];
88 96
89 -captchaImage.onRefresh(function() {  
90 - validateResult[1].message = 'err';  
91 - validateResult[1].status = false;  
92 -});  
93 -  
94 // 刷新图形验证码 97 // 刷新图形验证码
95 function refreshPic() { 98 function refreshPic() {
96 - captchaImage.refresh(); 99 + var time = new Date(),
  100 + $captchaImg = $('.captcha-img'),
  101 + captchaImgSrc = $captchaImg.attr('src').split('?')[0];
  102 +
  103 + $captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
97 } 104 }
98 105
99 // 手机号ajax校验 106 // 手机号ajax校验
@@ -120,17 +127,13 @@ function phoneAjaxFn(page, callback) { @@ -120,17 +127,13 @@ function phoneAjaxFn(page, callback) {
120 validateResult[0].message = 'err'; 127 validateResult[0].message = 'err';
121 validateResult[0].status = false; 128 validateResult[0].status = false;
122 129
123 - return $.ajax({ 130 + $.ajax({
124 url: url, 131 url: url,
125 type: 'POST', 132 type: 'POST',
126 data: data 133 data: data
127 }).then(function(res) { 134 }).then(function(res) {
128 - var defer = $.Deferred();  
129 -  
130 - defer.always(callback);  
131 -  
132 if (!res) { 135 if (!res) {
133 - return defer.reject().promise(); 136 + return;
134 } 137 }
135 138
136 switch (res.code) { 139 switch (res.code) {
@@ -140,7 +143,8 @@ function phoneAjaxFn(page, callback) { @@ -140,7 +143,8 @@ function phoneAjaxFn(page, callback) {
140 143
141 // 如果手机号发生改变则刷新验证码并且更新状态 144 // 如果手机号发生改变则刷新验证码并且更新状态
142 refreshPic(); 145 refreshPic();
143 - validateResult[1].message = 'err'; 146 + $sendCaptcha.addClass('disable').attr('disabled', 'disabled');
  147 + validateResult[1].message = '图形验证码错误';
144 validateResult[1].status = false; 148 validateResult[1].status = false;
145 } 149 }
146 150
@@ -148,28 +152,58 @@ function phoneAjaxFn(page, callback) { @@ -148,28 +152,58 @@ function phoneAjaxFn(page, callback) {
148 152
149 validateResult[0].message = ''; 153 validateResult[0].message = '';
150 validateResult[0].status = true; 154 validateResult[0].status = true;
151 -  
152 - return defer.resolve().promise(); 155 + break;
153 case 400: 156 case 400:
154 refreshPic(); 157 refreshPic();
155 validateResult[0].message = res.message; 158 validateResult[0].message = res.message;
156 validateResult[0].status = false; 159 validateResult[0].status = false;
157 - return defer.reject().promise(); 160 + break;
158 default: 161 default:
159 - return defer.reject().promise(); 162 + break;
160 } 163 }
  164 +
  165 + callback();
161 }); 166 });
162 } 167 }
163 168
164 // 图形验证码ajax校验 169 // 图形验证码ajax校验
165 -function picCaptchaAjaxFn(callback) {  
166 - return captchaImage.check().then(function() {  
167 - validateResult[1].message = '';  
168 - validateResult[1].status = true;  
169 - }).fail(function() {  
170 - validateResult[1].message = 'err';  
171 - validateResult[1].status = false;  
172 - }).always(callback); 170 +function picCaptchaAjaxFn(page, callback) {
  171 + var url;
  172 +
  173 + if (page === 'reg') {
  174 + url = '/passport/reg/piccaptcha';
  175 + } else if (page === 'third') {
  176 + url = '/passport/autouserinfo/checkPicCode';
  177 + }
  178 + $.ajax({
  179 + type: 'POST',
  180 + url: url,
  181 + data: {
  182 + verifyCode: $ca.val()
  183 +
  184 + // mobile: $pn.val(),
  185 + // area: $region.text().split('+')[1]
  186 + }
  187 + }).then(function(data) {
  188 + if (!data) {
  189 + return;
  190 + }
  191 +
  192 + switch (data.code) {
  193 + case 200:
  194 + validateResult[1].message = '';
  195 + validateResult[1].status = true;
  196 + break;
  197 + case 400:
  198 + refreshPic();
  199 + validateResult[1].message = '图形验证码错误';
  200 + validateResult[1].status = false;
  201 + break;
  202 + default:
  203 + break;
  204 + }
  205 + callback();
  206 + });
173 } 207 }
174 208
175 // 短信验证码ajax校验 209 // 短信验证码ajax校验
@@ -181,8 +215,7 @@ function msgCaptchaAjaxFn(page, callback) { @@ -181,8 +215,7 @@ function msgCaptchaAjaxFn(page, callback) {
181 } else if (page === 'third') { 215 } else if (page === 'third') {
182 url = '/passport/autouserinfo/checkBindMsg'; 216 url = '/passport/autouserinfo/checkBindMsg';
183 } 217 }
184 -  
185 - return $.ajax({ 218 + $.ajax({
186 type: 'POST', 219 type: 'POST',
187 url: url, 220 url: url,
188 data: { 221 data: {
@@ -191,26 +224,24 @@ function msgCaptchaAjaxFn(page, callback) { @@ -191,26 +224,24 @@ function msgCaptchaAjaxFn(page, callback) {
191 area: $region.text().split('+')[1] 224 area: $region.text().split('+')[1]
192 } 225 }
193 }).then(function(data) { 226 }).then(function(data) {
194 - var defer = $.Deferred();  
195 -  
196 - defer.always(callback);  
197 -  
198 if (!data) { 227 if (!data) {
199 - return defer.reject().promise(); 228 + return;
200 } 229 }
201 230
202 switch (data.code) { 231 switch (data.code) {
203 case 200: 232 case 200:
204 validateResult[2].message = ''; 233 validateResult[2].message = '';
205 validateResult[2].status = true; 234 validateResult[2].status = true;
206 - return defer.resolve().promise(); 235 + break;
207 case 400: 236 case 400:
208 validateResult[2].message = '短信验证码错误'; 237 validateResult[2].message = '短信验证码错误';
209 validateResult[2].status = false; 238 validateResult[2].status = false;
210 - return defer.reject().promise(); 239 + break;
211 default: 240 default:
212 - return defer.reject().promise(); 241 + break;
213 } 242 }
  243 +
  244 + callback();
214 }); 245 });
215 } 246 }
216 247
@@ -220,68 +251,80 @@ function validateRule(page, $element, callback) { @@ -220,68 +251,80 @@ function validateRule(page, $element, callback) {
220 var val = $.trim($element.val()), 251 var val = $.trim($element.val()),
221 regionCode; 252 regionCode;
222 253
  254 +
223 // 根据需求http://redmine.yoho.cn/issues/3117改成上边的正则 255 // 根据需求http://redmine.yoho.cn/issues/3117改成上边的正则
224 // 对应的错误提示语也改了,感觉要不了多久就会改回来 256 // 对应的错误提示语也改了,感觉要不了多久就会改回来
225 // pwdReg = /^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/gi; 257 // pwdReg = /^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/gi;
226 258
227 - var defer = $.Deferred();  
228 -  
229 - defer.always(callback);  
230 -  
231 // 手机号校验 259 // 手机号校验
232 if ($element.hasClass('phone-num')) { 260 if ($element.hasClass('phone-num')) {
  261 +
233 regionCode = $region.text(); 262 regionCode = $region.text();
234 263
  264 +
235 if (val === '') { 265 if (val === '') {
236 validateResult[0].message = '请输入手机号码'; 266 validateResult[0].message = '请输入手机号码';
237 validateResult[0].status = false; 267 validateResult[0].status = false;
238 - return defer.reject().promise(); 268 + return callback();
239 269
240 } else { 270 } else {
241 if (!/^[0-9]+$/.test(val) || 271 if (!/^[0-9]+$/.test(val) ||
242 (regionCode === '+86' && !regValidate.phoneRegx[regionCode].test(val))) { 272 (regionCode === '+86' && !regValidate.phoneRegx[regionCode].test(val))) {
243 validateResult[0].message = '手机号码格式不正确,请重新输入'; 273 validateResult[0].message = '手机号码格式不正确,请重新输入';
244 validateResult[0].status = false; 274 validateResult[0].status = false;
245 - return defer.reject().promise();  
246 - 275 + return callback();
247 } else { 276 } else {
248 - return phoneAjaxFn(page, callback); 277 + phoneAjaxFn(page, callback);
249 } 278 }
250 } 279 }
251 280
252 // 图形验证码校验 281 // 图形验证码校验
253 - } else if ($element.hasClass('w330')) {  
254 - // 并且手机号正确  
255 - if (validateResult[0].status) {  
256 - return picCaptchaAjaxFn(callback); 282 + } else if ($element.hasClass('captcha')) {
  283 + if (val === '') {
  284 + validateResult[1].message = '请输入图形验证码';
  285 + validateResult[1].status = false;
  286 + return callback();
257 287
258 - } else {  
259 - validateResult[1].message = 'err'; 288 + } else if (val.length <= 3) {
  289 + validateResult[1].message = '图形验证码为4位';
260 validateResult[1].status = false; 290 validateResult[1].status = false;
261 - return defer.reject().promise(); 291 + return callback();
  292 +
  293 + } else {
  294 +
  295 + // 并且手机号正确
  296 + if (validateResult[0].status) {
  297 + picCaptchaAjaxFn(page, callback);
  298 + } else {
  299 + validateResult[1].message = '图形验证码错误';
  300 + validateResult[1].status = false;
  301 + return callback();
  302 + }
  303 +
262 } 304 }
263 305
264 // 短信验证码校验 306 // 短信验证码校验
265 } else if ($element.hasClass('msg-captcha')) { 307 } else if ($element.hasClass('msg-captcha')) {
  308 +
266 if (val === '') { 309 if (val === '') {
267 validateResult[2].message = '请输入短信验证码'; 310 validateResult[2].message = '请输入短信验证码';
268 validateResult[2].status = false; 311 validateResult[2].status = false;
269 - return defer.reject().promise(); 312 + return callback();
270 313
271 } else if (val.length <= 3) { 314 } else if (val.length <= 3) {
272 validateResult[2].message = '短信验证码错误'; 315 validateResult[2].message = '短信验证码错误';
273 validateResult[2].status = false; 316 validateResult[2].status = false;
274 - return defer.reject().promise(); 317 + return callback();
275 318
276 } else { 319 } else {
277 320
278 // 并且图形验证码正确 321 // 并且图形验证码正确
279 if (validateResult[1].status) { 322 if (validateResult[1].status) {
280 - return msgCaptchaAjaxFn(page, callback); 323 + msgCaptchaAjaxFn(page, callback);
281 } else { 324 } else {
282 validateResult[2].message = '短信验证码错误'; 325 validateResult[2].message = '短信验证码错误';
283 validateResult[2].status = false; 326 validateResult[2].status = false;
284 - return defer.reject().promise(); 327 + return callback();
285 } 328 }
286 } 329 }
287 330
@@ -290,23 +333,39 @@ function validateRule(page, $element, callback) { @@ -290,23 +333,39 @@ function validateRule(page, $element, callback) {
290 if (val === '') { 333 if (val === '') {
291 validateResult[3].message = '请输入密码'; 334 validateResult[3].message = '请输入密码';
292 validateResult[3].status = false; 335 validateResult[3].status = false;
293 - return defer.reject().promise(); 336 +
294 } else if (val.length < 6 || val.length > 20) { 337 } else if (val.length < 6 || val.length > 20) {
295 validateResult[3].message = '密码只支持6-20位字符'; 338 validateResult[3].message = '密码只支持6-20位字符';
296 validateResult[3].status = false; 339 validateResult[3].status = false;
297 - return defer.reject().promise(); 340 +
298 } else if (!pwdReg.test($element.val())) { 341 } else if (!pwdReg.test($element.val())) {
299 validateResult[3].message = '密码须字母和数字组合'; 342 validateResult[3].message = '密码须字母和数字组合';
300 validateResult[3].status = false; 343 validateResult[3].status = false;
301 - return defer.reject().promise(); 344 +
302 } else { 345 } else {
303 validateResult[3].message = ''; 346 validateResult[3].message = '';
304 validateResult[3].status = true; 347 validateResult[3].status = true;
305 - return defer.resolve().promise();  
306 } 348 }
307 - } 349 + return callback();
  350 +
  351 + // 二次密码校验
  352 + } else if ($element.hasClass('repwd')) {
  353 + if (val === '') {
  354 + validateResult[4].message = '请输入密码确认';
  355 + validateResult[4].status = false;
  356 +
  357 + } else if ($pwd.val() !== val) {
  358 + validateResult[4].message = '与密码不一致,请重新输入';
  359 + validateResult[4].status = false;
  360 +
  361 + } else {
  362 + validateResult[4].message = '';
  363 + validateResult[4].status = true;
  364 +
  365 + }
308 366
309 - return defer.promise(); 367 + return callback();
  368 + }
310 } 369 }
311 370
312 function posErrTip() { 371 function posErrTip() {
@@ -352,7 +411,7 @@ function showBorder() { @@ -352,7 +411,7 @@ function showBorder() {
352 validateResultLen = validateResult.length; 411 validateResultLen = validateResult.length;
353 412
354 for (i = 0; i < validateResultLen; i++) { 413 for (i = 0; i < validateResultLen; i++) {
355 - if (validateResult[i].message && validateResult[i].message !== 'err') { 414 + if (validateResult[i].message) {
356 415
357 // 显示红色边框 416 // 显示红色边框
358 $errInput = $('#' + validateResult[i].id); 417 $errInput = $('#' + validateResult[i].id);
@@ -430,8 +489,6 @@ $(window).resize(function() { @@ -430,8 +489,6 @@ $(window).resize(function() {
430 // ( ▼-▼ )注册页和信息完善页面接口不同 489 // ( ▼-▼ )注册页和信息完善页面接口不同
431 exports.init = function(page) { 490 exports.init = function(page) {
432 491
433 - captchaImage.refresh();  
434 -  
435 $('#agree-terms').click(function() { 492 $('#agree-terms').click(function() {
436 493
437 var $this = $(this), 494 var $this = $(this),
@@ -494,6 +551,16 @@ exports.init = function(page) { @@ -494,6 +551,16 @@ exports.init = function(page) {
494 } else { 551 } else {
495 $registerBtn.addClass('disable').attr('disabled', 'disabled'); 552 $registerBtn.addClass('disable').attr('disabled', 'disabled');
496 } 553 }
  554 +
  555 + // 图形验证通过时,发送短信按钮可点击
  556 + if (validateResult[1].status && timeResidue <= 0) {
  557 + $sendCaptcha.removeClass('disable').removeAttr('disabled');
  558 + } else {
  559 + $sendCaptcha.addClass('disable').attr('disabled', 'disabled');
  560 + }
  561 +
  562 + // 图形验证通过时,发送短信按钮可点击 end
  563 +
497 }); 564 });
498 565
499 // 如果是密码则校验强度 566 // 如果是密码则校验强度
@@ -501,6 +568,12 @@ exports.init = function(page) { @@ -501,6 +568,12 @@ exports.init = function(page) {
501 pwdFn($that); 568 pwdFn($that);
502 } 569 }
503 570
  571 + }).blur(function() {
  572 +
  573 + /* validateRule($(this), function() {
  574 + showErrTip();
  575 + showBorder(); // 显示红色边框
  576 + });*/
504 }); 577 });
505 578
506 $regionSelect.change(function() { 579 $regionSelect.change(function() {
@@ -525,49 +598,37 @@ exports.init = function(page) { @@ -525,49 +598,37 @@ exports.init = function(page) {
525 url = '/passport/autouserinfo/sendBindMsg'; 598 url = '/passport/autouserinfo/sendBindMsg';
526 } 599 }
527 600
528 - // 1.验证图形验证码是否正确  
529 - // 2.验证手机号被注册过  
530 - // 3.发送短信  
531 - validateRule(page, $('#captcha-img'), function() {  
532 - showErrTip(); // 显示错误提示  
533 - showBorder(); // 显示红色边框  
534 - }).then(function() {  
535 - return validateRule(page, $pn, function() {  
536 - showErrTip(); // 显示错误提示  
537 - showBorder(); // 显示红色边框  
538 - });  
539 - }).then(function() {  
540 - return $.ajax({  
541 - type: 'POST',  
542 - url: url,  
543 - data: {  
544 - area: $region.text().split('+')[1],  
545 - mobile: $pn.val(),  
546 - verifyCode: getCaptchaImageVal()  
547 - }  
548 - }).then(function(result) {  
549 - if (result.code !== 200) {  
550 - validateResult[0].message = result.message;  
551 - validateResult[0].status = false; 601 + // todo ajax 发送验证码
  602 + $.ajax({
  603 + type: 'POST',
  604 + url: url,
  605 + data: {
  606 + area: $region.text().split('+')[1],
  607 + mobile: $pn.val(),
  608 + verifyCode: $ca.val()
  609 + }
  610 + }).then(function(result) {
  611 + if (result.code !== 200) {
  612 + validateResult[0].message = result.message;
  613 + validateResult[0].status = false;
552 614
553 - showErrTip();  
554 - return;  
555 - } 615 + showErrTip();
  616 + return;
  617 + }
556 618
557 - $('#msg-tip').removeClass('hide');  
558 - timeSecond = 60;  
559 - $sendCaptcha.addClass('disable').attr('disabled', 'disabled');  
560 - $sendCaptcha.val('60秒可重新发送'); 619 + $('#msg-tip').removeClass('hide');
  620 + timeResidue = 60;
  621 + $sendCaptcha.addClass('disable').attr('disabled', 'disabled');
  622 + $sendCaptcha.val('60秒可重新发送');
561 623
562 - t = setInterval(function() {  
563 - if (timeSecond <= 0) {  
564 - $sendCaptcha.removeClass('disable').removeAttr('disabled').val('获取短信验证码');  
565 - clearInterval(t);  
566 - return;  
567 - }  
568 - $sendCaptcha.val(timeSecond-- + '秒可重新发送');  
569 - }, 1000);  
570 - }); 624 + t = setInterval(function() {
  625 + if (timeResidue <= 0) {
  626 + $sendCaptcha.removeClass('disable').removeAttr('disabled').val('获取短信验证码');
  627 + clearInterval(t);
  628 + return;
  629 + }
  630 + $sendCaptcha.val(timeResidue-- + '秒可重新发送');
  631 + }, 1000);
571 }); 632 });
572 }); 633 });
573 634
@@ -599,7 +660,7 @@ exports.init = function(page) { @@ -599,7 +660,7 @@ exports.init = function(page) {
599 data: { 660 data: {
600 area: $region.text().split('+')[1], 661 area: $region.text().split('+')[1],
601 mobile: $pn.val(), 662 mobile: $pn.val(),
602 - verifyCode: getCaptchaImageVal(), 663 + verifyCode: $ca.val(),
603 code: $mc.val(), 664 code: $mc.val(),
604 password: $pwd.val() 665 password: $pwd.val()
605 } 666 }
@@ -635,13 +696,17 @@ exports.init = function(page) { @@ -635,13 +696,17 @@ exports.init = function(page) {
635 } else { 696 } else {
636 697
637 // todo 698 // todo
638 - alert(data.message); //eslint-disable-line 699 + console.log('网络超时~');
639 } 700 }
640 701
641 }); 702 });
642 } 703 }
643 }); 704 });
644 705
  706 + $('.change-captcha').click(function() {
  707 + refreshPic();
  708 + });
  709 +
645 // 注册成功页面5秒后跳转 710 // 注册成功页面5秒后跳转
646 if ($('.success-box').length > 0) { 711 if ($('.success-box').length > 0) {
647 clearT = setInterval(function() { 712 clearT = setInterval(function() {
@@ -655,15 +720,4 @@ exports.init = function(page) { @@ -655,15 +720,4 @@ exports.init = function(page) {
655 $countDown.text(countDown--); 720 $countDown.text(countDown--);
656 }, 1000); 721 }, 1000);
657 } 722 }
658 -  
659 - // 设置 refer 信息  
660 - (function() {  
661 - var refer = queryString().refer || ''; // eslint-disable-line  
662 -  
663 - if (refer) {  
664 - setCookie('refer', refer); // eslint-disable-line  
665 - } else {  
666 - setCookie('refer', ''); // eslint-disable-line  
667 - }  
668 - }());  
669 }; 723 };
@@ -694,6 +694,7 @@ function pageInit() { @@ -694,6 +694,7 @@ function pageInit() {
694 .last().find('.reconnect'); 694 .last().find('.reconnect');
695 695
696 if (!$reconnect.length) { 696 if (!$reconnect.length) {
  697 + socketChat.clear();
697 offlineTip(); 698 offlineTip();
698 } 699 }
699 }, 700 },
@@ -2,8 +2,7 @@ @@ -2,8 +2,7 @@
2 2
3 .content { 3 .content {
4 float: left; 4 float: left;
5 - margin-top: 80px;  
6 - margin-bottom: 100px; 5 + margin-top: 107px;
7 padding-left: 85px; 6 padding-left: 85px;
8 } 7 }
9 8
@@ -1069,49 +1069,52 @@ $color-3a3a3a: #3a3a3a; @@ -1069,49 +1069,52 @@ $color-3a3a3a: #3a3a3a;
1069 .detail-reason { 1069 .detail-reason {
1070 display: none; 1070 display: none;
1071 1071
1072 - .discontent { 1072 + .dis-wrap {
  1073 + margin-left: 8px;
1073 max-height: 155px; 1074 max-height: 155px;
1074 overflow-y: scroll; 1075 overflow-y: scroll;
1075 overflow-x: hidden; 1076 overflow-x: hidden;
1076 - margin-bottom: 30px;  
1077 1077
1078 - .dis-row {  
1079 - font-size: 0;  
1080 - text-align: center;  
1081 - margin-bottom: 13px; 1078 + .discontent {
  1079 + margin-bottom: 30px;
1082 1080
1083 - .type {  
1084 - position: relative;  
1085 - display: inline-block;  
1086 - width: 155px;  
1087 - height: 40px;  
1088 - padding: 0 2px;  
1089 - font-size: 12px;  
1090 - text-align: center;  
1091 - line-height: 40px;  
1092 - border: 1px #999999 solid;  
1093 - border-radius: 5px;  
1094 - cursor: pointer;  
1095 - text-overflow: ellipsis;  
1096 - white-space: nowrap;  
1097 - overflow: hidden; 1081 + .dis-row {
  1082 + font-size: 0;
  1083 + margin-bottom: 13px;
1098 1084
1099 - &.chosen {  
1100 - &:after {  
1101 - position: absolute;  
1102 - top: 13px;  
1103 - right: -2px;  
1104 - content: '';  
1105 - display: inline-block;  
1106 - height: 27px;  
1107 - width: 27px;  
1108 - background-image: resolve('service/btn-chosen.png'); 1085 + .type {
  1086 + position: relative;
  1087 + display: inline-block;
  1088 + width: 155px;
  1089 + height: 40px;
  1090 + padding: 0 2px;
  1091 + font-size: 12px;
  1092 + text-align: center;
  1093 + line-height: 40px;
  1094 + border: 1px #999999 solid;
  1095 + border-radius: 5px;
  1096 + cursor: pointer;
  1097 + text-overflow: ellipsis;
  1098 + white-space: nowrap;
  1099 + overflow: hidden;
  1100 +
  1101 + &.chosen {
  1102 + &:after {
  1103 + position: absolute;
  1104 + top: 13px;
  1105 + right: -2px;
  1106 + content: '';
  1107 + display: inline-block;
  1108 + height: 27px;
  1109 + width: 27px;
  1110 + background-image: resolve('service/btn-chosen.png');
1109 1111
  1112 + }
1110 } 1113 }
1111 - }  
1112 1114
1113 - &:first-child {  
1114 - margin-right: 15px; 1115 + &:first-child {
  1116 + margin-right: 15px;
  1117 + }
1115 } 1118 }
1116 } 1119 }
1117 } 1120 }