Authored by biao

update for bind mobile. code review by LZF

@@ -9,6 +9,7 @@ var $phoneNum = $('#phone-num'), @@ -9,6 +9,7 @@ var $phoneNum = $('#phone-num'),
9 $countrySelect = $('#country-select'), 9 $countrySelect = $('#country-select'),
10 $areaCode = $('#area-code'), 10 $areaCode = $('#area-code'),
11 $openId = $('#openId'), 11 $openId = $('#openId'),
  12 + $nickname = $('#nickname'),
12 $sourceType = $('#sourceType'), 13 $sourceType = $('#sourceType'),
13 $btnNext = $('#btn-next'); 14 $btnNext = $('#btn-next');
14 15
@@ -25,10 +26,16 @@ function nextStep(url, mobileNo, areaCode) { @@ -25,10 +26,16 @@ function nextStep(url, mobileNo, areaCode) {
25 url: '/passport/bind/sendBindMsg', 26 url: '/passport/bind/sendBindMsg',
26 data: { 27 data: {
27 phoneNum: mobileNo, 28 phoneNum: mobileNo,
28 - areaCode: areaCode 29 + areaCode: areaCode.replace('+', '')
  30 + },
  31 + success: function(res) {
  32 + console.log(res.data);
  33 + location.href = url;
  34 + },
  35 + error: function() {
  36 + tip.show('出错了,请重试!');
29 } 37 }
30 }); 38 });
31 - location.href = url;  
32 } 39 }
33 40
34 api.selectCssHack($('#country-select')); 41 api.selectCssHack($('#country-select'));
@@ -50,6 +57,7 @@ $countrySelect.change(function() { @@ -50,6 +57,7 @@ $countrySelect.change(function() {
50 $btnNext.on('touchstart', function() { 57 $btnNext.on('touchstart', function() {
51 var pn = trim($phoneNum.val()), 58 var pn = trim($phoneNum.val()),
52 openId = trim($openId.val()), 59 openId = trim($openId.val()),
  60 + nickname = trim($nickname.val()),
53 sourceType = trim($sourceType.val()), 61 sourceType = trim($sourceType.val()),
54 areaCode = $countrySelect.val(); 62 areaCode = $countrySelect.val();
55 63
@@ -63,9 +71,10 @@ $btnNext.on('touchstart', function() { @@ -63,9 +71,10 @@ $btnNext.on('touchstart', function() {
63 type: 'POST', 71 type: 'POST',
64 data: { 72 data: {
65 areaCode: areaCode.replace('+', ''), 73 areaCode: areaCode.replace('+', ''),
66 - mobile: pn, 74 + phoneNum: pn,
67 openId: openId, 75 openId: openId,
68 - sourceType: sourceType 76 + sourceType: sourceType,
  77 + nickname: nickname
69 }, 78 },
70 success: function(res) { 79 success: function(res) {
71 console.log(res); 80 console.log(res);
@@ -14,6 +14,40 @@ var tip = require('../../plugin/tip'); @@ -14,6 +14,40 @@ var tip = require('../../plugin/tip');
14 var trim = $.trim; 14 var trim = $.trim;
15 var showErrTip = tip.show; 15 var showErrTip = tip.show;
16 16
  17 +var nickname = $('#nickname').val(),
  18 + sourceType = $('#sourceType').val(),
  19 + openId = $('#openId').val(),
  20 + phoneNum = $('#phone-num').val(),
  21 + areaCode = $('#area-code').val().replace('+', '');
  22 +
  23 +function startBind(password) {
  24 + $.ajax({
  25 + url: '/passport/bind/bindMobile',
  26 + type: 'post',
  27 + data: {
  28 + areaCode: areaCode.replace('+', ''),
  29 + phoneNum: phoneNum,
  30 + openId: openId,
  31 + sourceType: sourceType,
  32 + nickname: nickname,
  33 + password: password
  34 + },
  35 + success: function(res) {
  36 + if (res.code === 200) {
  37 + tip.show('登录成功');
  38 + setTimeout(function() {
  39 + location.href = res.data.refer;
  40 + }, 2000);
  41 + } else {
  42 + tip.show(res.message);
  43 + }
  44 + },
  45 + error: function(err) {
  46 + tip.show('登录失败,请重试!');
  47 + }
  48 + });
  49 + }
  50 +
17 api.bindEyesEvt({ 51 api.bindEyesEvt({
18 status: 'open' //默认眼睛打开 52 status: 'open' //默认眼睛打开
19 }); 53 });
@@ -36,35 +70,6 @@ $btnSure.on('touchstart', function() { @@ -36,35 +70,6 @@ $btnSure.on('touchstart', function() {
36 if (api.pwdValidate(pwd) === false) { 70 if (api.pwdValidate(pwd) === false) {
37 showErrTip('密码6-20位,请重新输入'); 71 showErrTip('密码6-20位,请重新输入');
38 } else { 72 } else {
39 - $.ajax({  
40 - type: 'POST',  
41 - url: '/passport/reg/setpassword',  
42 - data: {  
43 - password: pwd,  
44 - phoneNum: $('#phone-num').val(),  
45 - areaCode: $('#area-code').val(),  
46 - token: $('#token').val()  
47 - },  
48 - success: function(data) {  
49 - var res;  
50 -  
51 - if (data.code === 200) {  
52 - res = data.data;  
53 - showErrTip('注册成功');  
54 -  
55 - $.ajax({  
56 - url: res.session,  
57 - dataType: 'jsonp'  
58 - });  
59 -  
60 - //1000ms后跳转页面  
61 - setTimeout(function() {  
62 - location.href = res.href;  
63 - }, 1000);  
64 - } else {  
65 - showErrTip(data.message);  
66 - }  
67 - }  
68 - }); 73 + startBind(pwd);
69 } 74 }
70 -});  
  75 +});
@@ -9,6 +9,10 @@ module.exports = function(useInRegister, useForBind) { @@ -9,6 +9,10 @@ module.exports = function(useInRegister, useForBind) {
9 var $captcha = $('#captcha'), 9 var $captcha = $('#captcha'),
10 $btnNext = $('#btn-next'), 10 $btnNext = $('#btn-next'),
11 $captchaTip = $('#captcha-tip'), 11 $captchaTip = $('#captcha-tip'),
  12 + isReg = parseInt($('#isReg').val()),
  13 + nickname = $('#nickname').val(),
  14 + sourceType = $('#sourceType').val(),
  15 + openId = $('#openId').val(),
12 phoneNum = $('#phone-num').val(), 16 phoneNum = $('#phone-num').val(),
13 areaCode = $('#area-code').val().replace('+', ''); 17 areaCode = $('#area-code').val().replace('+', '');
14 18
@@ -20,6 +24,34 @@ module.exports = function(useInRegister, useForBind) { @@ -20,6 +24,34 @@ module.exports = function(useInRegister, useForBind) {
20 24
21 var urlMid = useInRegister ? 'reg' : 'back'; 25 var urlMid = useInRegister ? 'reg' : 'back';
22 26
  27 + function startBind() {
  28 + $.ajax({
  29 + url: '/passport/bind/bindMobile',
  30 + type: 'post',
  31 + data: {
  32 + areaCode: areaCode.replace('+', ''),
  33 + phoneNum: phoneNum,
  34 + openId: openId,
  35 + sourceType: sourceType,
  36 + nickname: nickname,
  37 + password: ''
  38 + },
  39 + success: function(res) {
  40 + if (res.code === 200) {
  41 + tip.show('登录成功');
  42 + setTimeout(function() {
  43 + location.href = res.data.refer;
  44 + }, 2000);
  45 + } else {
  46 + tip.show(res.message);
  47 + }
  48 + },
  49 + error: function(err) {
  50 + tip.show('登录失败,请重试!');
  51 + }
  52 + });
  53 + }
  54 +
23 function countDown() { 55 function countDown() {
24 var count = 59, 56 var count = 59,
25 itime; 57 itime;
@@ -77,7 +109,7 @@ module.exports = function(useInRegister, useForBind) { @@ -77,7 +109,7 @@ module.exports = function(useInRegister, useForBind) {
77 109
78 $.ajax({ 110 $.ajax({
79 type: 'POST', 111 type: 'POST',
80 - url: useForBind ? '/passport/bind/sendBindMsg' : '/passport/' + urlMid + '/verifycode', 112 + url: useForBind ? '/passport/bind/checkBindMsg' : '/passport/' + urlMid + '/verifycode',
81 data: { 113 data: {
82 phoneNum: phoneNum, 114 phoneNum: phoneNum,
83 areaCode: areaCode, 115 areaCode: areaCode,
@@ -85,13 +117,22 @@ module.exports = function(useInRegister, useForBind) { @@ -85,13 +117,22 @@ module.exports = function(useInRegister, useForBind) {
85 token: $('#token').val() 117 token: $('#token').val()
86 }, 118 },
87 success: function(data) { 119 success: function(data) {
88 - if (data.code === 200) {  
89 - location.href = data.data;  
90 - } else { 120 + if (data.code === 200) {
  121 + if (useForBind) {
  122 + if (isReg) {
  123 + startBind();
  124 + } else {
  125 + location.href = '/passport/bind/password?phoneNum=' + phoneNum + '&areaCode=' + areaCode + '&openId=' + openId + '&sourceType=' + sourceType + '&nickname=' + nickname;
  126 + }
  127 + } else {
  128 + location.href = data.data;
  129 + }
  130 + } else {
  131 +
  132 + //验证码不正确,显示提示
  133 + showErrTip(data.message);
  134 + }
91 135
92 - //验证码不正确,显示提示  
93 - showErrTip(data.message);  
94 - }  
95 } 136 }
96 }); 137 });
97 }); 138 });
1 {{> layout/header}} 1 {{> layout/header}}
2 <div class="reg-code-page passport-page yoho-page"> 2 <div class="reg-code-page passport-page yoho-page">
  3 + <input type="hidden" id="isReg" value="{{isReg}}">
  4 + <input type="hidden" id="openId" value="{{openId}}">
  5 + <input type="hidden" id="sourceType" value="{{sourceType}}">
  6 + <input type="hidden" id="nickname" value="{{nickname}}">
3 {{> passport/code}} 7 {{> passport/code}}
4 </div> 8 </div>
5 {{> layout/footer}} 9 {{> layout/footer}}
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 <div class="bind-page passport-page yoho-page"> 2 <div class="bind-page passport-page yoho-page">
3 <input type="hidden" id="openId" value="{{openId}}"> 3 <input type="hidden" id="openId" value="{{openId}}">
4 <input type="hidden" id="sourceType" value="{{sourceType}}"> 4 <input type="hidden" id="sourceType" value="{{sourceType}}">
  5 + <input type="hidden" id="nickname" value="{{nickname}}">
5 {{> passport/header}} 6 {{> passport/header}}
6 <div class="content"> 7 <div class="content">
7 {{> passport/country_list}} 8 {{> passport/country_list}}
1 {{> layout/header}} 1 {{> layout/header}}
2 <div class="bind-password-page passport-page yoho-page"> 2 <div class="bind-password-page passport-page yoho-page">
  3 + <input type="hidden" id="openId" value="{{openId}}">
  4 + <input type="hidden" id="sourceType" value="{{sourceType}}">
  5 + <input type="hidden" id="nickname" value="{{nickname}}">
3 {{> passport/header}} 6 {{> passport/header}}
4 <div class="content"> 7 <div class="content">
5 <div class="input-container row has-eye"> 8 <div class="input-container row has-eye">