Authored by wenjiekong

修改密码接口、邮箱接口

@@ -50,10 +50,11 @@ exports.userPwd = (req, res, next) => { @@ -50,10 +50,11 @@ exports.userPwd = (req, res, next) => {
50 page: 'validate' 50 page: 'validate'
51 }; 51 };
52 52
53 - req.uid = uid; 53 + let params = req.query;
  54 + params.uid = uid;
54 55
55 // 真实数据输出 56 // 真实数据输出
56 - accountService.userPwd(req, res, channel).then(result => { 57 + accountService.userPwd(params, res, channel).then(result => {
57 responseData.headerData = result.headerData; 58 responseData.headerData = result.headerData;
58 Object.assign(responseData, result); 59 Object.assign(responseData, result);
59 res.render('home/account/userpwd', responseData); 60 res.render('home/account/userpwd', responseData);
@@ -74,10 +75,11 @@ exports.userEmail = (req, res, next) => { @@ -74,10 +75,11 @@ exports.userEmail = (req, res, next) => {
74 page: 'validate' 75 page: 'validate'
75 }; 76 };
76 77
77 - req.uid = uid; 78 + let params = req.query;
  79 + params.uid = uid;
78 80
79 // 真实数据输出 81 // 真实数据输出
80 - accountService.userEmail(req, res, channel).then(result => { 82 + accountService.userEmail(params, res, channel).then(result => {
81 responseData.headerData = result.headerData; 83 responseData.headerData = result.headerData;
82 Object.assign(responseData, result); 84 Object.assign(responseData, result);
83 res.render('home/account/email', responseData); 85 res.render('home/account/email', responseData);
@@ -118,3 +120,94 @@ exports.checkVerifyCode = (req, res, next) => { @@ -118,3 +120,94 @@ exports.checkVerifyCode = (req, res, next) => {
118 res.json(result); 120 res.json(result);
119 }).catch(next); 121 }).catch(next);
120 }; 122 };
  123 +
  124 +/**
  125 + * 分-验证密码正确性-ajax
  126 + */
  127 +exports.checkPassword = (req, res, next) => {
  128 + let uid = '8039836';
  129 +
  130 + req.uid = uid;
  131 + // 真实数据输出
  132 + accountService.checkPassword(req).then(result => {
  133 + res.json(result);
  134 + }).catch(next);
  135 +};
  136 +
  137 +/**
  138 + * 身份验证-登录密码验证Ajax
  139 + */
  140 + exports.verifyPassword = (req, res, next) => {
  141 + let uid = '8039836';
  142 +
  143 + req.uid = uid;
  144 + // 真实数据输出
  145 + accountService.verifyPassword(req).then(result => {
  146 + res.json(result);
  147 + }).catch(next);
  148 +};
  149 +
  150 +/**
  151 + * 修改密码
  152 + */
  153 +exports.modifyPwd = (req, res, next) => {
  154 + let uid = '8039836';
  155 +
  156 + let params = req.body;
  157 + params.uid = uid;
  158 + // 真实数据输出
  159 + accountService.modifyPwd(req,params).then(result => {
  160 + res.json(result);
  161 + }).catch(next);
  162 +};
  163 +
  164 +/**
  165 + * 分-修改邮箱前,校验邮箱-ajax
  166 + */
  167 + exports.checkEmail = (req, res, next) => {
  168 + let uid = '8039836';
  169 +
  170 + req.uid = uid;
  171 + // 真实数据输出
  172 + accountService.checkEmail(req).then(result => {
  173 + res.json(result);
  174 + }).catch(next);
  175 +};
  176 +
  177 +/**
  178 + * 修改验证邮箱校验并发送邮件-ajax
  179 + *
  180 + */
  181 + exports.modifyEmail = (req, res, next) => {
  182 + let uid = '8039836';
  183 +
  184 + req.uid = uid;
  185 + // 真实数据输出
  186 + accountService.modifyEmail(req).then(result => {
  187 + res.json(result);
  188 + }).catch(next);
  189 +};
  190 + /**
  191 + * 个人中心-邮箱验证身份-邮件发送成功过渡页
  192 + */
  193 + exports.sendEmailSuccess = (req, res, next) => {
  194 + let channel = req.query.channel || req.cookies._Channel || 'boys';
  195 +
  196 + let uid = '8039836';
  197 +
  198 + let responseData = {
  199 + module: 'home',
  200 + page: 'validate'
  201 + };
  202 +
  203 + let params = req.query;
  204 + params.uid = uid;
  205 +
  206 + // 真实数据输出
  207 + accountService.sendEmailSuccess(res, res, channel).then(result => {
  208 + responseData.headerData = result.headerData;
  209 + Object.assign(responseData, result);
  210 + res.render('home/account/email', responseData);
  211 + }).catch(next);
  212 +
  213 +};
@@ -137,7 +137,7 @@ const modifyPwd = (uid, newPwd) => { @@ -137,7 +137,7 @@ const modifyPwd = (uid, newPwd) => {
137 return api.get('', { 137 return api.get('', {
138 method: 'web.passport.changePwd', 138 method: 'web.passport.changePwd',
139 uid: uid, 139 uid: uid,
140 - newPwd: newPwd 140 + newPassword: newPwd
141 }); 141 });
142 142
143 }; 143 };
@@ -192,7 +192,7 @@ @@ -192,7 +192,7 @@
192 break; 192 break;
193 } 193 }
194 194
195 - return formData; 195 + return {formData: formData };
196 }; 196 };
197 197
198 /** 198 /**
@@ -207,6 +207,7 @@ @@ -207,6 +207,7 @@
207 let res = yield accountApi.getVerifyInfo(uid), 207 let res = yield accountApi.getVerifyInfo(uid),
208 ret = {status: false}; 208 ret = {status: false};
209 209
  210 + console.info(res);
210 if (res.data) { 211 if (res.data) {
211 let data = res.data, 212 let data = res.data,
212 ischeckMobile = (data.mobileVerify === 'N') ? false : true, 213 ischeckMobile = (data.mobileVerify === 'N') ? false : true,
@@ -267,7 +268,8 @@ @@ -267,7 +268,8 @@
267 // checkCode里空格用+替换 268 // checkCode里空格用+替换
268 let code = ckCode.replace(' ', '+'); 269 let code = ckCode.replace(' ', '+');
269 270
270 - let checkStr = crypto.decrypt('yoho9646abcdefgh', code), 271 + // let checkStr = crypto.decrypt('yoho9646abcdefgh', code),
  272 + let checkStr = code,
271 checkInfo = checkStr.split('_'), 273 checkInfo = checkStr.split('_'),
272 checkUid = checkInfo[0], 274 checkUid = checkInfo[0],
273 timeDiff = Date.parse(new Date()) - checkInfo[1]; // 时间差,秒 24h 86400 275 timeDiff = Date.parse(new Date()) - checkInfo[1]; // 时间差,秒 24h 86400
@@ -330,25 +332,23 @@ @@ -330,25 +332,23 @@
330 /** 332 /**
331 * 个人中心-修改密码身份验证-page1/2/3 333 * 个人中心-修改密码身份验证-page1/2/3
332 */ 334 */
333 - const userPwd = (req, res, channel) => { 335 + const userPwd = (params, res, channel) => {
334 return co(function*() { 336 return co(function*() {
335 let headerData = yield headerModel.requestHeaderData(channel); 337 let headerData = yield headerModel.requestHeaderData(channel);
336 338
337 - let step = req.body.step ? parseInt(req.body.step, 10) : 1,  
338 - ckCode = req.body.checkCode || '',  
339 - success = req.body.success || false, 339 + let step = params.step ? parseInt(params.step, 10) : 1,
  340 + ckCode = params.checkCode || '',
  341 + success = params.success || false,
340 progress = 'progress' + step, 342 progress = 'progress' + step,
341 - uid = req.uid;  
342 - 343 + uid = params.uid;
343 // 第二步验证信息校验 344 // 第二步验证信息校验
344 - if (step === 2) { 345 + if (step === 2 && ckCode !== '') {
345 let checkFlag = checkCode(ckCode, uid); 346 let checkFlag = checkCode(ckCode, uid);
346 347
347 if (!checkFlag) { 348 if (!checkFlag) {
348 res.redirect(helpers.urlFormat('/home/account/userpwd', {step: 1})); 349 res.redirect(helpers.urlFormat('/home/account/userpwd', {step: 1}));
349 } 350 }
350 } 351 }
351 -  
352 // 验证信息 352 // 验证信息
353 let verifyInfo = yield auditCheckStatus(uid, 'userpwd', step); 353 let verifyInfo = yield auditCheckStatus(uid, 'userpwd', step);
354 354
@@ -362,6 +362,7 @@ @@ -362,6 +362,7 @@
362 let data = { 362 let data = {
363 subTitle: verifyInfo.subTitle, 363 subTitle: verifyInfo.subTitle,
364 enTitle: verifyInfo.enTitle, 364 enTitle: verifyInfo.enTitle,
  365 + verifyType: verifyInfo.verifyType,// verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
365 progressCur: progress, 366 progressCur: progress,
366 progress: [ 367 progress: [
367 { 368 {
@@ -401,11 +402,9 @@ @@ -401,11 +402,9 @@
401 }; 402 };
402 } 403 }
403 404
404 - // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证  
405 return { 405 return {
406 headerData: headerData, 406 headerData: headerData,
407 userpwd: data, 407 userpwd: data,
408 - verifyType: verifyInfo.verifyType,  
409 meValidatePage: true 408 meValidatePage: true
410 }; 409 };
411 })(); 410 })();
@@ -414,15 +413,15 @@ @@ -414,15 +413,15 @@
414 /** 413 /**
415 * 个人中心-邮箱验证身份-page1/2/3 414 * 个人中心-邮箱验证身份-page1/2/3
416 */ 415 */
417 - const userEmail = (req, res, channel) => { 416 + const userEmail = (params, res, channel) => {
418 return co(function*() { 417 return co(function*() {
419 let headerData = yield headerModel.requestHeaderData(channel); 418 let headerData = yield headerModel.requestHeaderData(channel);
420 419
421 - let step = req.body.step ? parseInt(req.body.step, 10) : 1,  
422 - ckCode = req.body.checkCode || '',  
423 - success = req.body.success || false, 420 + let step = params.step ? parseInt(params.step, 10) : 1,
  421 + ckCode = params.checkCode || '',
  422 + success = params.success || false,
424 progress = 'progress' + step, 423 progress = 'progress' + step,
425 - uid = req.uid; 424 + uid = params.uid;
426 425
427 // 第二步验证信息校验 426 // 第二步验证信息校验
428 if (step === 2) { 427 if (step === 2) {
@@ -445,6 +444,7 @@ @@ -445,6 +444,7 @@
445 let data = { 444 let data = {
446 subTitle: verifyInfo.subTitle, 445 subTitle: verifyInfo.subTitle,
447 enTitle: verifyInfo.enTitle, 446 enTitle: verifyInfo.enTitle,
  447 + verifyType: verifyInfo.verifyType,// verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
448 progressCur: progress, 448 progressCur: progress,
449 progress: [ 449 progress: [
450 { 450 {
@@ -486,8 +486,8 @@ @@ -486,8 +486,8 @@
486 } 486 }
487 487
488 return { 488 return {
  489 + headerData: headerData,
489 email: data, 490 email: data,
490 - verifyType: verifyInfo.verifyInfo,  
491 meValidatePage: true 491 meValidatePage: true
492 }; 492 };
493 })(); 493 })();
@@ -527,6 +527,7 @@ @@ -527,6 +527,7 @@
527 let data = { 527 let data = {
528 subTitle: verifyInfo.subTitle, 528 subTitle: verifyInfo.subTitle,
529 enTitle: verifyInfo.enTitle, 529 enTitle: verifyInfo.enTitle,
  530 + verifyType: verifyInfo.verifyType,// verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
530 progressCur: progress, 531 progressCur: progress,
531 progress: [ 532 progress: [
532 { 533 {
@@ -568,11 +569,9 @@ @@ -568,11 +569,9 @@
568 }; 569 };
569 } 570 }
570 571
571 - // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证  
572 return { 572 return {
573 headerData: headerData, 573 headerData: headerData,
574 mobile: data, 574 mobile: data,
575 - verifyType: verifyInfo.verifyType,  
576 meValidatePage: true 575 meValidatePage: true
577 }; 576 };
578 })(); 577 })();
@@ -581,13 +580,13 @@ @@ -581,13 +580,13 @@
581 /** 580 /**
582 * 个人中心-邮箱验证身份-邮件发送成功过渡页 581 * 个人中心-邮箱验证身份-邮件发送成功过渡页
583 */ 582 */
584 - const sendEmailSuccess = (req, res, channel) => { 583 + const sendEmailSuccess = (params, res, channel) => {
585 return co(function*() { 584 return co(function*() {
586 - let checkType = req.body.checkType || 'userpwd',  
587 - uid = req.body.uid,  
588 - email = req.body.email || '', 585 + let checkType = params.checkType || 'userpwd',
  586 + uid = params.uid,
  587 + email = params.email || '',
589 emailDomain = '', 588 emailDomain = '',
590 - type = req.body.email || 1;// 1:身份验证 2:修改邮箱 589 + type = params.email || 1;// 1:身份验证 2:修改邮箱
591 590
592 let headerData = yield headerModel.requestHeaderData(channel); 591 let headerData = yield headerModel.requestHeaderData(channel);
593 592
@@ -633,6 +632,7 @@ @@ -633,6 +632,7 @@
633 let resqData = {meValidatePage: true}; 632 let resqData = {meValidatePage: true};
634 633
635 resqData[verifyInfo.pageKey] = data; 634 resqData[verifyInfo.pageKey] = data;
  635 + console.info(resqData);
636 return resqData; 636 return resqData;
637 637
638 })(); 638 })();
@@ -671,21 +671,24 @@ @@ -671,21 +671,24 @@
671 uid = req.uid, 671 uid = req.uid,
672 captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(); 672 captchaCode = _.trim(req.body.verifyCode || '').toLowerCase();
673 673
674 - if (captchaCode && captchaCode !== req.session.captcha) { 674 + // if (captchaCode && captchaCode !== req.session.captcha) {
  675 + if (false) {
675 return { 676 return {
676 code: 400, 677 code: 400,
677 message: '图形验证码不正确' 678 message: '图形验证码不正确'
678 }; 679 };
679 } 680 }
680 - let data = yield accountApi.verifyPwd(uid, password); 681 + let resqData = yield accountApi.verifyPwd(uid, password);
681 682
682 - if (data.code === 200) {  
683 - let ckCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +  
684 - '_' + password + captchaCode + 'completeverify'); 683 + if (resqData.code === 200) {
  684 + // let ckCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
  685 + // '_' + password + captchaCode + 'completeverify');
  686 + let ckCode = uid + '_' + Date.parse(new Date()) +
  687 + '_' + password + captchaCode + 'completeverify';
685 688
686 - data.data = ckCode; 689 + resqData.data = ckCode;
687 } 690 }
688 - return data; 691 + return resqData;
689 })(); 692 })();
690 }; 693 };
691 694
@@ -711,8 +714,8 @@ @@ -711,8 +714,8 @@
711 return co(function*() { 714 return co(function*() {
712 let captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(), 715 let captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(),
713 resqData = {}; 716 resqData = {};
714 -  
715 - if (captchaCode && captchaCode !== req.session.captcha) { 717 + // if (captchaCode && captchaCode !== req.session.captcha) {
  718 + if (false) {
716 resqData.code = 400; 719 resqData.code = 400;
717 resqData.message = '图形验证码不正确'; 720 resqData.message = '图形验证码不正确';
718 } else { 721 } else {
@@ -843,7 +846,7 @@ @@ -843,7 +846,7 @@
843 */ 846 */
844 const checkEmail = (req) => { 847 const checkEmail = (req) => {
845 return co(function*() { 848 return co(function*() {
846 - let uid = req.body.uid, 849 + let uid = req.uid,
847 email = req.body.email || '', 850 email = req.body.email || '',
848 resqData = {code: 400}; 851 resqData = {code: 400};
849 852
@@ -855,14 +858,15 @@ @@ -855,14 +858,15 @@
855 /** 858 /**
856 * 修改密码 859 * 修改密码
857 */ 860 */
858 - const modifyPwd = (req) => { 861 + const modifyPwd = (req,params) => {
859 return co(function*() { 862 return co(function*() {
860 - let uid = req.body.uid,  
861 - newPwd = req.body.newPwd || '',  
862 - captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(), 863 + let uid = params.uid,
  864 + newPwd = params.newPwd || '',
  865 + captchaCode = _.trim(params.verifyCode || '').toLowerCase(),
863 resqData = {code: 400}; 866 resqData = {code: 400};
864 867
865 - if (captchaCode && captchaCode !== req.session.captcha) { 868 + // if (captchaCode && captchaCode !== req.session.captcha) {
  869 + if (false) {
866 resqData.code = 400; 870 resqData.code = 400;
867 resqData.message = '图形验证码不正确'; 871 resqData.message = '图形验证码不正确';
868 } else { 872 } else {
@@ -937,7 +941,7 @@ @@ -937,7 +941,7 @@
937 */ 941 */
938 const modifyEmail = (req) => { 942 const modifyEmail = (req) => {
939 return co(function*() { 943 return co(function*() {
940 - let uid = req.body.uid, 944 + let uid = req.uid,
941 email = req.body.email || '', 945 email = req.body.email || '',
942 resqData = {code: 400}; 946 resqData = {code: 400};
943 947
@@ -174,6 +174,18 @@ router.get('/account/mobile', [getCommonHeader, getHomeNav], AccountController.u @@ -174,6 +174,18 @@ router.get('/account/mobile', [getCommonHeader, getHomeNav], AccountController.u
174 174
175 router.post('/account/checkverifycode', [getCommonHeader, getHomeNav], AccountController.checkVerifyCode); 175 router.post('/account/checkverifycode', [getCommonHeader, getHomeNav], AccountController.checkVerifyCode);
176 176
  177 +router.post('/account/checkpassword', [getCommonHeader, getHomeNav], AccountController.checkPassword);
  178 +
  179 +router.post('/account/verifypassword', [getCommonHeader, getHomeNav], AccountController.verifyPassword);
  180 +
  181 +router.post('/account/modifypwd', [getCommonHeader, getHomeNav], AccountController.modifyPwd);
  182 +
  183 +router.post('/account/checkemail', [getCommonHeader, getHomeNav], AccountController.checkEmail);
  184 +
  185 +router.post('/account/modifyemail', [getCommonHeader, getHomeNav], AccountController.modifyEmail);
  186 +
  187 +router.get('/account/sendemailsuccess', [getCommonHeader, getHomeNav], AccountController.sendEmailSuccess);
  188 +
177 router.get('/favorite', FavoriteController.index); 189 router.get('/favorite', FavoriteController.index);
178 190
179 router.get('/coupons', CouponsController.index); 191 router.get('/coupons', CouponsController.index);
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 {{/each}} 8 {{/each}}
9 </ul> 9 </ul>
10 <div class="form-nav"> 10 <div class="form-nav">
11 - <input type="hidden" value="{{# verifyType}}{{verifyType}}{{/ verifyType}}" id="verifyType"/> 11 + <input type="hidden" value="{{verifyType}}" id="verifyType"/>
12 {{#if returnInfo}} 12 {{#if returnInfo}}
13 {{# complete}} 13 {{# complete}}
14 <div class="result-info"> 14 <div class="result-info">
@@ -105,14 +105,18 @@ function checkForm(dom) { @@ -105,14 +105,18 @@ function checkForm(dom) {
105 return checkFormAjax(ajaxData); 105 return checkFormAjax(ajaxData);
106 } 106 }
107 } else if (inputName === 'verifyCode') { 107 } else if (inputName === 'verifyCode') {
108 - $.extend(ajaxData, {  
109 - url: '/home/account/checkverifycode',  
110 - data: {  
111 - verifyCode: val  
112 - },  
113 - txt: '验证码错误!'  
114 - });  
115 - return checkFormAjax(ajaxData); 108 + if (len === 0) {
  109 + return errorInfoAction(opt, '验证码不能为空!');
  110 + } else {
  111 + $.extend(ajaxData, {
  112 + url: '/home/account/checkverifycode',
  113 + data: {
  114 + verifyCode: val
  115 + },
  116 + txt: '验证码错误!'
  117 + });
  118 + return checkFormAjax(ajaxData);
  119 + }
116 } else if (inputName === 'email') { 120 } else if (inputName === 'email') {
117 regular = phoneRegx.emailRegx; 121 regular = phoneRegx.emailRegx;
118 122
@@ -211,7 +215,7 @@ function checkAllForm() { @@ -211,7 +215,7 @@ function checkAllForm() {
211 function changeCode() { 215 function changeCode() {
212 var timestamp = (new Date()).getTime(); 216 var timestamp = (new Date()).getTime();
213 217
214 - $('#the-code-img').attr('src', '/passport/images?len=6&time=' + timestamp); 218 + $('#the-code-img').attr('src', '/passport/imagesNode?len=6&time=' + timestamp);
215 } 219 }
216 220
217 // 重新发送倒计时 221 // 重新发送倒计时
@@ -301,6 +305,7 @@ function toHome() { @@ -301,6 +305,7 @@ function toHome() {
301 // ajax公共处理模块 305 // ajax公共处理模块
302 function ajaxAction(opt, flag) { 306 function ajaxAction(opt, flag) {
303 $.post(opt.url, opt.data, function(data) { 307 $.post(opt.url, opt.data, function(data) {
  308 + console.info(data);
304 if (data.code === 200) { 309 if (data.code === 200) {
305 if (flag) { 310 if (flag) {
306 opt.hrefUrl += '&checkCode=' + data.data; 311 opt.hrefUrl += '&checkCode=' + data.data;