Authored by wenjiekong

‘账号安全接口都写了

@@ -49,6 +49,7 @@ const checkVerifyMsg = (area, mobile, code) => { @@ -49,6 +49,7 @@ const checkVerifyMsg = (area, mobile, code) => {
49 }); 49 });
50 50
51 }; 51 };
  52 +
52 /** 53 /**
53 * 邮箱身份验证--发送邮件 54 * 邮箱身份验证--发送邮件
54 * @param type $email 55 * @param type $email
@@ -63,6 +64,7 @@ const sendVerifyEmailForNext = (email, callback) => { @@ -63,6 +64,7 @@ const sendVerifyEmailForNext = (email, callback) => {
63 }); 64 });
64 65
65 }; 66 };
  67 +
66 /** 68 /**
67 * 修改验证手机号 69 * 修改验证手机号
68 * @param type $uid 70 * @param type $uid
@@ -79,6 +81,7 @@ const modifyVerifyMobile = (uid, area, newMobile) => { @@ -79,6 +81,7 @@ const modifyVerifyMobile = (uid, area, newMobile) => {
79 }); 81 });
80 82
81 }; 83 };
  84 +
82 /** 85 /**
83 * 修改邮箱前校验 86 * 修改邮箱前校验
84 * @param type $uid 87 * @param type $uid
@@ -92,13 +95,14 @@ const checkVerifyEmail = (uid, email) => { @@ -92,13 +95,14 @@ const checkVerifyEmail = (uid, email) => {
92 }); 95 });
93 96
94 }; 97 };
  98 +
95 /** 99 /**
96 * 验证邮箱--发送邮件 100 * 验证邮箱--发送邮件
97 * @param type $uid 101 * @param type $uid
98 * @param type $email 102 * @param type $email
99 * @return type 103 * @return type
100 */ 104 */
101 - const sendVerifyEmail = (uid, email) => { 105 +const sendVerifyEmail = (uid, email) => {
102 return api.get('', { 106 return api.get('', {
103 method: 'web.passport.verifyEmail', 107 method: 'web.passport.verifyEmail',
104 uid: uid, 108 uid: uid,
@@ -137,6 +141,7 @@ const modifyPwd = (uid, newPwd) => { @@ -137,6 +141,7 @@ const modifyPwd = (uid, newPwd) => {
137 }); 141 });
138 142
139 }; 143 };
  144 +
140 module.exports = { 145 module.exports = {
141 getVerifyInfo, 146 getVerifyInfo,
142 checkEmailCode, 147 checkEmailCode,
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 24
25 return parseInt(now.getTime() / 1000, 10); 25 return parseInt(now.getTime() / 1000, 10);
26 } 26 }
  27 +
27 /** 28 /**
28 * 根据输入的mobile获取area 29 * 根据输入的mobile获取area
29 * @param type $mobile 30 * @param type $mobile
@@ -32,13 +33,13 @@ @@ -32,13 +33,13 @@
32 function handleMobile(mobile) { 33 function handleMobile(mobile) {
33 let res = {}; 34 let res = {};
34 35
35 - //国际号  
36 - if (mobile.indexOf("-") > 0) {  
37 - let areaTmp = mobile.split("-"); 36 + // 国际号
  37 + if (mobile.indexOf('-') > 0) {
  38 + let areaTmp = mobile.split('-');
38 39
39 res.area = areaTmp[0]; 40 res.area = areaTmp[0];
40 res.mobile = areaTmp[1]; 41 res.mobile = areaTmp[1];
41 - }else { 42 + } else {
42 res.area = 86; 43 res.area = 86;
43 res.mobile = mobile; 44 res.mobile = mobile;
44 } 45 }
@@ -583,13 +584,15 @@ @@ -583,13 +584,15 @@
583 const sendEmailSuccess = (req, res, channel) => { 584 const sendEmailSuccess = (req, res, channel) => {
584 return co(function*() { 585 return co(function*() {
585 let checkType = req.body.checkType || 'userpwd', 586 let checkType = req.body.checkType || 'userpwd',
  587 + uid = req.body.uid,
586 email = req.body.email || '', 588 email = req.body.email || '',
587 emailDomain = '', 589 emailDomain = '',
588 - type = req.body.email || 1;//1:身份验证 2:修改邮箱 590 + type = req.body.email || 1;// 1:身份验证 2:修改邮箱
589 591
590 let headerData = yield headerModel.requestHeaderData(channel); 592 let headerData = yield headerModel.requestHeaderData(channel);
  593 +
591 // 验证信息 594 // 验证信息
592 - let verifyInfo = yield auditCheckStatus(uid, 'mobile', step); 595 + let verifyInfo = yield auditCheckStatus(uid, checkType);
593 596
594 if (!verifyInfo.status) { 597 if (!verifyInfo.status) {
595 return { 598 return {
@@ -623,8 +626,7 @@ @@ -623,8 +626,7 @@
623 626
624 if (type === 1) { 627 if (type === 1) {
625 data.progress[0].iscur = true; 628 data.progress[0].iscur = true;
626 - }  
627 - else { 629 + } else {
628 data.progress[1].iscur = true; 630 data.progress[1].iscur = true;
629 } 631 }
630 632
@@ -635,6 +637,7 @@ @@ -635,6 +637,7 @@
635 637
636 })(); 638 })();
637 }; 639 };
  640 +
638 /** 641 /**
639 * 点击邮箱验证链接方法--修改验证邮箱 642 * 点击邮箱验证链接方法--修改验证邮箱
640 */ 643 */
@@ -649,19 +652,20 @@ @@ -649,19 +652,20 @@
649 652
650 if (data.code === 200) { 653 if (data.code === 200) {
651 res.redirect(helpers.urlFormat('/home/account/email', 654 res.redirect(helpers.urlFormat('/home/account/email',
652 - {step: 3,success: true})); 655 + {step: 3, success: true}));
653 } 656 }
654 } 657 }
655 658
656 res.redirect(helpers.urlFormat('/home/account/email', 659 res.redirect(helpers.urlFormat('/home/account/email',
657 - {step: 3,success: false})); 660 + {step: 3, success: false}));
658 661
659 })(); 662 })();
660 -}; 663 + };
  664 +
661 /** 665 /**
662 * 身份验证-登录密码验证Ajax 666 * 身份验证-登录密码验证Ajax
663 */ 667 */
664 -const verifyPassword = (req) => { 668 + const verifyPassword = (req) => {
665 return co(function*() { 669 return co(function*() {
666 let password = _.trim(req.body.password || ''), 670 let password = _.trim(req.body.password || ''),
667 uid = req.uid, 671 uid = req.uid,
@@ -670,20 +674,21 @@ const verifyPassword = (req) => { @@ -670,20 +674,21 @@ const verifyPassword = (req) => {
670 if (captchaCode && captchaCode !== req.session.captcha) { 674 if (captchaCode && captchaCode !== req.session.captcha) {
671 return { 675 return {
672 code: 400, 676 code: 400,
673 - message:'图形验证码不正确'  
674 - } 677 + message: '图形验证码不正确'
  678 + };
675 } 679 }
676 let data = yield accountApi.verifyPwd(uid, password); 680 let data = yield accountApi.verifyPwd(uid, password);
677 681
678 - if (data.code == 200) {  
679 - let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) + 682 + if (data.code === 200) {
  683 + let ckCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
680 '_' + password + captchaCode + 'completeverify'); 684 '_' + password + captchaCode + 'completeverify');
681 685
682 - data.data = checkCode; 686 + data.data = ckCode;
683 } 687 }
684 return data; 688 return data;
685 })(); 689 })();
686 -}; 690 + };
  691 +
687 /** 692 /**
688 * 分-验证密码正确性-ajax 693 * 分-验证密码正确性-ajax
689 */ 694 */
@@ -698,6 +703,7 @@ const verifyPassword = (req) => { @@ -698,6 +703,7 @@ const verifyPassword = (req) => {
698 return resqData; 703 return resqData;
699 })(); 704 })();
700 }; 705 };
  706 +
701 /** 707 /**
702 * 分-验证图形验证码-ajax 708 * 分-验证图形验证码-ajax
703 */ 709 */
@@ -708,13 +714,14 @@ const verifyPassword = (req) => { @@ -708,13 +714,14 @@ const verifyPassword = (req) => {
708 if (captchaCode && captchaCode !== req.session.captcha) { 714 if (captchaCode && captchaCode !== req.session.captcha) {
709 resqData.code = 400; 715 resqData.code = 400;
710 resqData.message = '图形验证码不正确'; 716 resqData.message = '图形验证码不正确';
711 - }else {  
712 - resqData.code = code; 717 + } else {
  718 + resqData.code = 200;
713 resqData.message = ''; 719 resqData.message = '';
714 } 720 }
715 721
716 return resqData; 722 return resqData;
717 }; 723 };
  724 +
718 /** 725 /**
719 * 手机身份验证-校验手机号 726 * 手机身份验证-校验手机号
720 */ 727 */
@@ -728,7 +735,7 @@ const verifyPassword = (req) => { @@ -728,7 +735,7 @@ const verifyPassword = (req) => {
728 735
729 let mobileInfo = handleMobile(mobile); 736 let mobileInfo = handleMobile(mobile);
730 737
731 - let userInfo = yield userApi.getUserInfoByMobile(area, mobile); 738 + let userInfo = yield userApi.getUserInfoByMobile(mobileInfo.area, mobile);
732 739
733 userId = 'uid' in userInfo.data ? userInfo.data.uid : 0; 740 userId = 'uid' in userInfo.data ? userInfo.data.uid : 0;
734 if (userId === uid) { 741 if (userId === uid) {
@@ -740,17 +747,18 @@ const verifyPassword = (req) => { @@ -740,17 +747,18 @@ const verifyPassword = (req) => {
740 code: 200, 747 code: 200,
741 message: '', 748 message: '',
742 data: '' 749 data: ''
743 - }  
744 - }else { 750 + };
  751 + } else {
745 resqData = { 752 resqData = {
746 code: 400, 753 code: 400,
747 message: '手机号错误', 754 message: '手机号错误',
748 data: '' 755 data: ''
749 - } 756 + };
750 } 757 }
751 return resqData; 758 return resqData;
752 })(); 759 })();
753 }; 760 };
  761 +
754 /** 762 /**
755 * 向验证手机号发送短信-ajax 763 * 向验证手机号发送短信-ajax
756 */ 764 */
@@ -767,10 +775,11 @@ const verifyPassword = (req) => { @@ -767,10 +775,11 @@ const verifyPassword = (req) => {
767 return resqData; 775 return resqData;
768 })(); 776 })();
769 }; 777 };
  778 +
770 /** 779 /**
771 * 校验短信验证码-ajax 780 * 校验短信验证码-ajax
772 */ 781 */
773 -const checkMobileMsg = (req) => { 782 + const checkMobileMsg = (req) => {
774 return co(function*() { 783 return co(function*() {
775 let mobile = req.body.mobile || '', 784 let mobile = req.body.mobile || '',
776 code = req.body.code || '', 785 code = req.body.code || '',
@@ -782,7 +791,7 @@ const checkMobileMsg = (req) => { @@ -782,7 +791,7 @@ const checkMobileMsg = (req) => {
782 code: 400, 791 code: 400,
783 message: '手机号为空', 792 message: '手机号为空',
784 data: '' 793 data: ''
785 - } 794 + };
786 return resqData; 795 return resqData;
787 } 796 }
788 if (code === '') { 797 if (code === '') {
@@ -790,7 +799,7 @@ const checkMobileMsg = (req) => { @@ -790,7 +799,7 @@ const checkMobileMsg = (req) => {
790 code: 400, 799 code: 400,
791 message: '验证码为空', 800 message: '验证码为空',
792 data: '' 801 data: ''
793 - } 802 + };
794 return resqData; 803 return resqData;
795 } 804 }
796 let mobileInfo = handleMobile(mobile); 805 let mobileInfo = handleMobile(mobile);
@@ -798,36 +807,39 @@ const checkMobileMsg = (req) => { @@ -798,36 +807,39 @@ const checkMobileMsg = (req) => {
798 resqData = yield accountApi.checkVerifyMsg(uid, mobileInfo.mobile, mobileInfo.area); 807 resqData = yield accountApi.checkVerifyMsg(uid, mobileInfo.mobile, mobileInfo.area);
799 808
800 if (resqData.code === 200) { 809 if (resqData.code === 200) {
801 - let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) + '_' + 810 + let ckCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) + '_' +
802 mobileInfo.mobile + mobileInfo.area + 'completeverify'); 811 mobileInfo.mobile + mobileInfo.area + 'completeverify');
803 812
804 - resqData.data = checkCode; 813 + resqData.data = ckCode;
805 } 814 }
806 return resqData; 815 return resqData;
807 })(); 816 })();
808 -}; 817 + };
  818 +
809 /** 819 /**
810 * 身份验证时,发送邮件-ajax 820 * 身份验证时,发送邮件-ajax
811 */ 821 */
812 -const sendEmail = (req) => { 822 + const sendEmail = (req) => {
813 return co(function*() { 823 return co(function*() {
814 let uid = req.body.uid, 824 let uid = req.body.uid,
815 checkType = req.body.checkType || 'userpwd', 825 checkType = req.body.checkType || 'userpwd',
816 email = req.body.email || '', 826 email = req.body.email || '',
817 resqData = {code: 400}; 827 resqData = {code: 400};
818 828
819 - let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +  
820 - '_' + email + checkType + 'completeverify'),  
821 - callback = 'home/account/' + checkType + '?step=2&checkCode=' + checkCode; //callback拼接于邮箱域名处; 829 + let ckCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
  830 + '_' + email + checkType + 'completeverify');
  831 +
  832 + let callback = 'home/account/' + checkType + '?step=2&checkCode=' + ckCode; // callback拼接于邮箱域名处;
822 833
823 resqData = yield accountApi.sendVerifyEmailForNext(email, callback); 834 resqData = yield accountApi.sendVerifyEmailForNext(email, callback);
824 return resqData; 835 return resqData;
825 })(); 836 })();
826 -}; 837 + };
  838 +
827 /** 839 /**
828 * 分-修改邮箱前,校验邮箱-ajax 840 * 分-修改邮箱前,校验邮箱-ajax
829 */ 841 */
830 -const checkEmail = (req) => { 842 + const checkEmail = (req) => {
831 return co(function*() { 843 return co(function*() {
832 let uid = req.body.uid, 844 let uid = req.body.uid,
833 email = req.body.email || '', 845 email = req.body.email || '',
@@ -836,7 +848,8 @@ const checkEmail = (req) => { @@ -836,7 +848,8 @@ const checkEmail = (req) => {
836 resqData = yield accountApi.checkVerifyEmail(uid, email); 848 resqData = yield accountApi.checkVerifyEmail(uid, email);
837 return resqData; 849 return resqData;
838 })(); 850 })();
839 -}; 851 + };
  852 +
840 /** 853 /**
841 * 修改密码 854 * 修改密码
842 */ 855 */
@@ -844,18 +857,19 @@ const checkEmail = (req) => { @@ -844,18 +857,19 @@ const checkEmail = (req) => {
844 return co(function*() { 857 return co(function*() {
845 let uid = req.body.uid, 858 let uid = req.body.uid,
846 newPwd = req.body.newPwd || '', 859 newPwd = req.body.newPwd || '',
847 - captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(); 860 + captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(),
848 resqData = {code: 400}; 861 resqData = {code: 400};
849 862
850 if (captchaCode && captchaCode !== req.session.captcha) { 863 if (captchaCode && captchaCode !== req.session.captcha) {
851 resqData.code = 400; 864 resqData.code = 400;
852 resqData.message = '图形验证码不正确'; 865 resqData.message = '图形验证码不正确';
853 - }else { 866 + } else {
854 resqData = yield accountApi.modifyPwd(uid, newPwd); 867 resqData = yield accountApi.modifyPwd(uid, newPwd);
855 } 868 }
856 return resqData; 869 return resqData;
857 })(); 870 })();
858 -}; 871 + };
  872 +
859 /** 873 /**
860 * 修改验证手机号 874 * 修改验证手机号
861 */ 875 */
@@ -871,7 +885,7 @@ const checkEmail = (req) => { @@ -871,7 +885,7 @@ const checkEmail = (req) => {
871 code: 400, 885 code: 400,
872 message: '手机号为空', 886 message: '手机号为空',
873 data: '' 887 data: ''
874 - } 888 + };
875 return resqData; 889 return resqData;
876 } 890 }
877 if (code === '') { 891 if (code === '') {
@@ -879,7 +893,7 @@ const checkEmail = (req) => { @@ -879,7 +893,7 @@ const checkEmail = (req) => {
879 code: 400, 893 code: 400,
880 message: '验证码为空', 894 message: '验证码为空',
881 data: '' 895 data: ''
882 - } 896 + };
883 return resqData; 897 return resqData;
884 } 898 }
885 let mobileInfo = handleMobile(mobile); 899 let mobileInfo = handleMobile(mobile);
@@ -888,20 +902,21 @@ const checkEmail = (req) => { @@ -888,20 +902,21 @@ const checkEmail = (req) => {
888 902
889 if (checkFlag.code === 200) { 903 if (checkFlag.code === 200) {
890 resqData = accountApi.modifyVerifyMobile(uid, mobileInfo.area, mobileInfo.mobile); 904 resqData = accountApi.modifyVerifyMobile(uid, mobileInfo.area, mobileInfo.mobile);
891 - }else { 905 + } else {
892 resqData = { 906 resqData = {
893 code: checkFlag.data, 907 code: checkFlag.data,
894 message: checkFlag.message, 908 message: checkFlag.message,
895 data: '' 909 data: ''
896 - } 910 + };
897 } 911 }
898 return resqData; 912 return resqData;
899 })(); 913 })();
900 -}; 914 + };
  915 +
901 /** 916 /**
902 * 分-检查手机号是否可修改-ajax 917 * 分-检查手机号是否可修改-ajax
903 */ 918 */
904 -const checkMobile = (req) => { 919 + const checkMobile = (req) => {
905 return co(function*() { 920 return co(function*() {
906 let uid = req.body.uid, 921 let uid = req.body.uid,
907 mobile = req.body.mobile || '', 922 mobile = req.body.mobile || '',
@@ -912,7 +927,8 @@ const checkMobile = (req) => { @@ -912,7 +927,8 @@ const checkMobile = (req) => {
912 resqData = yield accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area); 927 resqData = yield accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
913 return resqData; 928 return resqData;
914 })(); 929 })();
915 -}; 930 + };
  931 +
916 /** 932 /**
917 * 修改验证邮箱校验并发送邮件-ajax 933 * 修改验证邮箱校验并发送邮件-ajax
918 * 934 *
@@ -930,7 +946,8 @@ const checkMobile = (req) => { @@ -930,7 +946,8 @@ const checkMobile = (req) => {
930 } 946 }
931 return resqData; 947 return resqData;
932 })(); 948 })();
933 -}; 949 + };
  950 +
934 module.exports = { 951 module.exports = {
935 getAccountInfo, 952 getAccountInfo,
936 userPwd, 953 userPwd,