Authored by htoooth

fix black

@@ -68,14 +68,19 @@ const validateInputPage = (req, res, next) => { @@ -68,14 +68,19 @@ const validateInputPage = (req, res, next) => {
68 req.inputInfo = result; 68 req.inputInfo = result;
69 next(); 69 next();
70 }) 70 })
71 - .catch(()=> {  
72 - res.redirect(helpers.urlFormat('/passport/back/index')); 71 + .catch((err) => {
  72 + res.json({
  73 + code: 400,
  74 + message: err
  75 + });
73 }); 76 });
74 }; 77 };
75 78
76 const getUserInfoAPI = (req, res, next) => { 79 const getUserInfoAPI = (req, res, next) => {
77 let inputInfo = req.inputInfo; 80 let inputInfo = req.inputInfo;
78 81
  82 + req.session.type = 'back-step1';
  83 +
79 service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) 84 service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
80 .then(result => { 85 .then(result => {
81 res.json(result); 86 res.json(result);
@@ -93,7 +98,13 @@ const sendCodePage = (req, res, next) => { @@ -93,7 +98,13 @@ const sendCodePage = (req, res, next) => {
93 service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) 98 service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
94 .then(result => { 99 .then(result => {
95 if (!(result.code && result.code === 200)) { 100 if (!(result.code && result.code === 200)) {
96 - return res.redirect(helpers.urlFormat('/passport/back/index')); 101 + return res.json({
  102 + code: 400,
  103 + message: '发送验证码错误',
  104 + data: {
  105 + refer: helpers.urlFormat('/passport/back/index')
  106 + }
  107 + });
97 } 108 }
98 109
99 return next(); 110 return next();
@@ -102,19 +113,45 @@ const sendCodePage = (req, res, next) => { @@ -102,19 +113,45 @@ const sendCodePage = (req, res, next) => {
102 }; 113 };
103 114
104 const saveInSession = (req, res) => { 115 const saveInSession = (req, res) => {
  116 + if (req.session.type !== 'back-step1') {
  117 + return res.json({
  118 + code: 400,
  119 + message: '未验证',
  120 + data: {
  121 + refer: helpers.urlFormat('/passport/back/index')
  122 + }
  123 + });
  124 + }
  125 +
  126 + req.session.type = 'back-step2';
  127 +
105 switch (req.inputInfo.type) { 128 switch (req.inputInfo.type) {
106 case 'email': 129 case 'email':
107 req.session.email = req.inputInfo.phone; 130 req.session.email = req.inputInfo.phone;
108 - res.redirect(helpers.urlFormat('/passport/back/sendEmail'));  
109 - break; 131 + return res.json({
  132 + code: 200,
  133 + data: {
  134 + refer: helpers.urlFormat('/passport/back/sendemail')
  135 + }
  136 + });
110 case 'mobile': 137 case 'mobile':
111 req.session.mobile = req.inputInfo.phone; 138 req.session.mobile = req.inputInfo.phone;
112 req.session.area = req.inputInfo.area; 139 req.session.area = req.inputInfo.area;
113 req.session.captcha = req.body.verifyCode; 140 req.session.captcha = req.body.verifyCode;
114 - res.redirect(helpers.urlFormat('/passport/back/verification'));  
115 - break; 141 +
  142 + return res.json({
  143 + code: 200,
  144 + data: {
  145 + refer: helpers.urlFormat('/passport/back/verification')
  146 + }
  147 + });
116 default: 148 default:
117 - res.redirect(helpers.urlFormat('/passport/back/index')); 149 + return res.json({
  150 + code: 500,
  151 + data: {
  152 + refer: helpers.urlFormat('/passport/back/index')
  153 + }
  154 + });
118 } 155 }
119 }; 156 };
120 157
@@ -133,6 +170,10 @@ const validateMobileAPI = (req, res, next) => { @@ -133,6 +170,10 @@ const validateMobileAPI = (req, res, next) => {
133 let mobile = req.body.mobile || ''; 170 let mobile = req.body.mobile || '';
134 const ERR = {code: 400, message: '验证失败'}; 171 const ERR = {code: 400, message: '验证失败'};
135 172
  173 + if (req.session.type !== 'back-step3') {
  174 + return res.json(ERR);
  175 + }
  176 +
136 if (!passportHelper.validator.isMobile(mobile)) { 177 if (!passportHelper.validator.isMobile(mobile)) {
137 return res.json(ERR); 178 return res.json(ERR);
138 } 179 }
@@ -157,6 +198,12 @@ const validateEmailInSession = (req, res, next) => { @@ -157,6 +198,12 @@ const validateEmailInSession = (req, res, next) => {
157 }; 198 };
158 199
159 const sendEmailPage = (req, res, next) => { 200 const sendEmailPage = (req, res, next) => {
  201 + if (req.session.type !== 'back-step2') {
  202 + return res.redirect(helpers.urlFormat('/passport/back/index'));
  203 + }
  204 +
  205 + req.session.type = 'back-step3';
  206 +
160 passportHelper.getLeftBannerAsync() 207 passportHelper.getLeftBannerAsync()
161 .then(result => { 208 .then(result => {
162 res.render('back/send-email', Object.assign({ 209 res.render('back/send-email', Object.assign({
@@ -215,7 +262,11 @@ const resetPasswordPage = (req, res, next) => { @@ -215,7 +262,11 @@ const resetPasswordPage = (req, res, next) => {
215 }; 262 };
216 263
217 const verifyCodeByMobilePage = (req, res, next) => { 264 const verifyCodeByMobilePage = (req, res, next) => {
218 - req.session.type = 'back-step2'; 265 + if (req.session.type !== 'back-step2') {
  266 + return res.redirect(helpers.urlFormat('/passport/back/index'));
  267 + }
  268 +
  269 + req.session.type = 'back-step3';
219 270
220 passportHelper.getLeftBannerAsync() 271 passportHelper.getLeftBannerAsync()
221 .then(result => { 272 .then(result => {
@@ -282,7 +333,7 @@ const verifyCodeByMobileAPI = (req, res) => { @@ -282,7 +333,7 @@ const verifyCodeByMobileAPI = (req, res) => {
282 return res.json(ERR); 333 return res.json(ERR);
283 } 334 }
284 335
285 - if (session.type !== 'back-step2') { 336 + if (session.type !== 'back-step3') {
286 return res.json(ERR); 337 return res.json(ERR);
287 } 338 }
288 339
@@ -359,10 +410,9 @@ const updatePwdAPI = (req, res, next) => { @@ -359,10 +410,9 @@ const updatePwdAPI = (req, res, next) => {
359 410
360 const validateMobileInSession = (req, res, next) => { 411 const validateMobileInSession = (req, res, next) => {
361 req.body.mobile = req.session.mobile || ''; 412 req.body.mobile = req.session.mobile || '';
362 - req.body.verifyCode = req.session.captcha || '';  
363 req.body.area = req.session.area || ''; 413 req.body.area = req.session.area || '';
364 414
365 - if (!(req.body.mobile && req.body.verifyCode)) { 415 + if (!req.body.mobile) {
366 return res.redirect(helpers.urlFormat('/passport/back/index')); 416 return res.redirect(helpers.urlFormat('/passport/back/index'));
367 } 417 }
368 418
@@ -119,7 +119,7 @@ router.get('/passport/reg/success', reg.success); @@ -119,7 +119,7 @@ router.get('/passport/reg/success', reg.success);
119 // 找回密码首页 119 // 找回密码首页
120 router.get('/passport/back/index', back.index); 120 router.get('/passport/back/index', back.index);
121 121
122 -// 实时验证输入是否正确 122 +// 验证输入是否正确
123 router.post('/passport/back/authcode', 123 router.post('/passport/back/authcode',
124 captcha.requiredAPI, 124 captcha.requiredAPI,
125 back.validateInputAPI, 125 back.validateInputAPI,
@@ -127,14 +127,12 @@ router.post('/passport/back/authcode', @@ -127,14 +127,12 @@ router.post('/passport/back/authcode',
127 127
128 // 提交按钮邮件API 128 // 提交按钮邮件API
129 router.post('/passport/back/email', 129 router.post('/passport/back/email',
130 - captcha.requiredPage,  
131 back.validateInputPage, 130 back.validateInputPage,
132 back.sendCodePage, 131 back.sendCodePage,
133 back.saveInSession); 132 back.saveInSession);
134 133
135 -// 提交按钮手机API 134 +// 提交按钮手机AP
136 router.post('/passport/back/mobile', 135 router.post('/passport/back/mobile',
137 - captcha.requiredPage,  
138 back.validateInputPage, 136 back.validateInputPage,
139 back.sendCodePage, 137 back.sendCodePage,
140 back.saveInSession); 138 back.saveInSession);
@@ -29,6 +29,32 @@ var $cr = $('#country-code-hide'), @@ -29,6 +29,32 @@ var $cr = $('#country-code-hide'),
29 require('../../simple-header'); 29 require('../../simple-header');
30 require('yoho-jquery-placeholder'); 30 require('yoho-jquery-placeholder');
31 require('../../common/promise'); 31 require('../../common/promise');
  32 +require('../../common');
  33 +
  34 +function authcode() {
  35 + return $.ajax({
  36 + type: 'POST',
  37 + url: '/passport/back/authcode',
  38 + data: {
  39 + verifyCode: captcha.getResults(),
  40 + phoneNum: $phoneNum.val(),
  41 + area: $cr.val()
  42 + }
  43 +
  44 + }).then(function(data) {
  45 + if (data.code === 200) {
  46 + $('#captcha-value').val(captcha.getResults());
  47 + return $.Deferred().resolve().promise(); //eslint-disable-line
  48 + } else if (data.code === 402) {
  49 + $accErr.removeClass('hide').find('em').text('该账号不存在');
  50 + $phoneNum.addClass('error');
  51 + return $.Deferred().reject().promise();//eslint-disable-line
  52 + } else if (data.code === 405) {
  53 + captcha.showTip(data.message);
  54 + return $.Deferred().reject().promise();//eslint-disable-line
  55 + }
  56 + });
  57 +}
32 58
33 function vaPn(v) { 59 function vaPn(v) {
34 var pass = true, 60 var pass = true,
@@ -151,7 +177,27 @@ $btn.click(function(e) { @@ -151,7 +177,27 @@ $btn.click(function(e) {
151 $('#captcha-value').val(captcha.getResults()); 177 $('#captcha-value').val(captcha.getResults());
152 178
153 if (hasPh) { 179 if (hasPh) {
154 - $('#back-form').submit(); 180 + authcode().then(function() {
  181 + $.post($('#back-form').attr('action'), {
  182 + phoneNum: $('#phone-num').val(),
  183 + area: $('#country-code-hide').val()
  184 + }).then(function(result) {
  185 + if (result.code === 200) {
  186 + window.jumpUrl(result.data.refer);
  187 + return;
  188 + }
  189 +
  190 + if (result.code === 405) {
  191 + captcha.showTip(result.message);
  192 + $accErr.addClass('hide');
  193 + $phoneNum.removeClass('error');
  194 + return;
  195 + }
  196 +
  197 + $accErr.removeClass('hide').find('em').text(result.message);
  198 + $phoneNum.addClass('error');
  199 + });
  200 + });
155 } 201 }
156 202
157 e.preventDefault(); 203 e.preventDefault();