|
@@ -10,6 +10,7 @@ |
|
@@ -10,6 +10,7 @@ |
10
|
const _ = require('lodash');
|
10
|
const _ = require('lodash');
|
11
|
const crypto = global.yoho.crypto;
|
11
|
const crypto = global.yoho.crypto;
|
12
|
const accountApi = require('./account-api');
|
12
|
const accountApi = require('./account-api');
|
|
|
13
|
+ const userApi = require('./user-api');
|
13
|
const headerModel = require('../../../doraemon/models/header');
|
14
|
const headerModel = require('../../../doraemon/models/header');
|
14
|
|
15
|
|
15
|
// 时间转换为时间戳
|
16
|
// 时间转换为时间戳
|
|
@@ -23,6 +24,26 @@ |
|
@@ -23,6 +24,26 @@ |
23
|
|
24
|
|
24
|
return parseInt(now.getTime() / 1000, 10);
|
25
|
return parseInt(now.getTime() / 1000, 10);
|
25
|
}
|
26
|
}
|
|
|
27
|
+ /**
|
|
|
28
|
+ * 根据输入的mobile获取area
|
|
|
29
|
+ * @param type $mobile
|
|
|
30
|
+ * @return int
|
|
|
31
|
+ */
|
|
|
32
|
+ function handleMobile(mobile) {
|
|
|
33
|
+ let res = {};
|
|
|
34
|
+
|
|
|
35
|
+ //国际号
|
|
|
36
|
+ if (mobile.indexOf("-") > 0) {
|
|
|
37
|
+ let areaTmp = mobile.split("-");
|
|
|
38
|
+
|
|
|
39
|
+ res.area = areaTmp[0];
|
|
|
40
|
+ res.mobile = areaTmp[1];
|
|
|
41
|
+ }else {
|
|
|
42
|
+ res.area = 86;
|
|
|
43
|
+ res.mobile = mobile;
|
|
|
44
|
+ }
|
|
|
45
|
+ return res;
|
|
|
46
|
+ }
|
26
|
|
47
|
|
27
|
/**
|
48
|
/**
|
28
|
* 获得标题文案
|
49
|
* 获得标题文案
|
|
@@ -73,7 +94,7 @@ |
|
@@ -73,7 +94,7 @@ |
73
|
}], formData2 = [{// 只验证手机号
|
94
|
}], formData2 = [{// 只验证手机号
|
74
|
inputTxt: '已验证的手机号',
|
95
|
inputTxt: '已验证的手机号',
|
75
|
isVerify: true,
|
96
|
isVerify: true,
|
76
|
- verifyAccount: data.mobile.slice(0, 2) + '****' + data.email.slice(6),
|
97
|
+ verifyAccount: data.mobile.slice(0, 3) + '****' + data.email.slice(7),
|
77
|
realAccount: data.mobile
|
98
|
realAccount: data.mobile
|
78
|
}], formData3 = [{// 只验证邮箱
|
99
|
}], formData3 = [{// 只验证邮箱
|
79
|
inputTxt: '已验证邮箱',
|
100
|
inputTxt: '已验证邮箱',
|
|
@@ -559,37 +580,374 @@ |
|
@@ -559,37 +580,374 @@ |
559
|
/**
|
580
|
/**
|
560
|
* 个人中心-邮箱验证身份-邮件发送成功过渡页
|
581
|
* 个人中心-邮箱验证身份-邮件发送成功过渡页
|
561
|
*/
|
582
|
*/
|
562
|
- // const sendEmailSuccess = (req, res, channel) => {
|
583
|
+ const sendEmailSuccess = (req, res, channel) => {
|
|
|
584
|
+ return co(function*() {
|
|
|
585
|
+ let checkType = req.body.checkType || 'userpwd',
|
|
|
586
|
+ email = req.body.email || '',
|
|
|
587
|
+ emailDomain = '',
|
|
|
588
|
+ type = req.body.email || 1;//1:身份验证 2:修改邮箱
|
|
|
589
|
+
|
|
|
590
|
+ let headerData = yield headerModel.requestHeaderData(channel);
|
|
|
591
|
+ // 验证信息
|
|
|
592
|
+ let verifyInfo = yield auditCheckStatus(uid, 'mobile', step);
|
|
|
593
|
+
|
|
|
594
|
+ if (!verifyInfo.status) {
|
|
|
595
|
+ return {
|
|
|
596
|
+ headerData: headerData,
|
|
|
597
|
+ meValidatePage: true
|
|
|
598
|
+ };
|
|
|
599
|
+ }
|
|
|
600
|
+ emailDomain = 'http://' + ((email.split[1] === 'gmail.com') ?
|
|
|
601
|
+ 'mail.google.com' : 'mail.' + email.split[1]);
|
|
|
602
|
+ let data = {
|
|
|
603
|
+ subTitle: verifyInfo.subTitle,
|
|
|
604
|
+ enTitle: verifyInfo.enTitle,
|
|
|
605
|
+ progressCur: (type === 1) ? 'progress1' : 'progress2',
|
|
|
606
|
+ progress: [
|
|
|
607
|
+ {
|
|
|
608
|
+ progressName: '1.验证身份'
|
|
|
609
|
+ },
|
|
|
610
|
+ {
|
|
|
611
|
+ progressName: '2.' + verifyInfo.subTitle
|
|
|
612
|
+ },
|
|
|
613
|
+ {
|
|
|
614
|
+ progressName: '3.完成'
|
|
|
615
|
+ }
|
|
|
616
|
+ ],
|
|
|
617
|
+ returnInfo: true,
|
|
|
618
|
+ sendEmail: {
|
|
|
619
|
+ emailInfo: email.slice(0, 2) + '****' + email.slice(6),
|
|
|
620
|
+ emailUrl: emailDomain
|
|
|
621
|
+ }
|
|
|
622
|
+ };
|
|
|
623
|
+
|
|
|
624
|
+ if (type === 1) {
|
|
|
625
|
+ data.progress[0].iscur = true;
|
|
|
626
|
+ }
|
|
|
627
|
+ else {
|
|
|
628
|
+ data.progress[1].iscur = true;
|
|
|
629
|
+ }
|
563
|
|
630
|
|
564
|
- // };
|
631
|
+ let resqData = {meValidatePage: true};
|
565
|
|
632
|
|
|
|
633
|
+ resqData[verifyInfo.pageKey] = data;
|
|
|
634
|
+ return resqData;
|
566
|
|
635
|
|
|
|
636
|
+ })();
|
|
|
637
|
+ };
|
|
|
638
|
+/**
|
|
|
639
|
+ * 点击邮箱验证链接方法--修改验证邮箱
|
|
|
640
|
+ */
|
|
|
641
|
+ const mailResult = (req, res) => {
|
|
|
642
|
+ return co(function*() {
|
|
|
643
|
+ let code = req.body.code;
|
|
|
644
|
+
|
|
|
645
|
+ let check = yield accountApi.checkEmailCode(code);
|
|
|
646
|
+
|
|
|
647
|
+ if (check.code === 200) {
|
|
|
648
|
+ let data = yield accountApi.modifyVerifyEmail(code);
|
|
|
649
|
+
|
|
|
650
|
+ if (data.code === 200) {
|
|
|
651
|
+ res.redirect(helpers.urlFormat('/home/account/email',
|
|
|
652
|
+ {step: 3,success: true}));
|
|
|
653
|
+ }
|
|
|
654
|
+ }
|
|
|
655
|
+
|
|
|
656
|
+ res.redirect(helpers.urlFormat('/home/account/email',
|
|
|
657
|
+ {step: 3,success: false}));
|
|
|
658
|
+
|
|
|
659
|
+ })();
|
|
|
660
|
+};
|
|
|
661
|
+/**
|
|
|
662
|
+ * 身份验证-登录密码验证Ajax
|
|
|
663
|
+ */
|
|
|
664
|
+const verifyPassword = (req) => {
|
|
|
665
|
+ return co(function*() {
|
|
|
666
|
+ let password = _.trim(req.body.password || ''),
|
|
|
667
|
+ uid = req.uid,
|
|
|
668
|
+ captchaCode = _.trim(req.body.verifyCode || '').toLowerCase();
|
|
|
669
|
+
|
|
|
670
|
+ if (captchaCode && captchaCode !== req.session.captcha) {
|
|
|
671
|
+ return {
|
|
|
672
|
+ code: 400,
|
|
|
673
|
+ message:'图形验证码不正确'
|
|
|
674
|
+ }
|
|
|
675
|
+ }
|
|
|
676
|
+ let data = yield accountApi.verifyPwd(uid, password);
|
|
|
677
|
+
|
|
|
678
|
+ if (data.code == 200) {
|
|
|
679
|
+ let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
|
|
|
680
|
+ '_' + password + captchaCode + 'completeverify');
|
|
|
681
|
+
|
|
|
682
|
+ data.data = checkCode;
|
|
|
683
|
+ }
|
|
|
684
|
+ return data;
|
|
|
685
|
+ })();
|
|
|
686
|
+};
|
|
|
687
|
+/**
|
|
|
688
|
+ * 分-验证密码正确性-ajax
|
|
|
689
|
+ */
|
|
|
690
|
+ const checkPassword = (req) => {
|
|
|
691
|
+ return co(function*() {
|
|
|
692
|
+ let password = _.trim(req.body.password || ''),
|
|
|
693
|
+ uid = req.uid,
|
|
|
694
|
+ resqData = {code: 400};
|
|
|
695
|
+
|
|
|
696
|
+ resqData = yield accountApi.verifyPwd(uid, password);
|
|
|
697
|
+
|
|
|
698
|
+ return resqData;
|
|
|
699
|
+ })();
|
|
|
700
|
+ };
|
567
|
/**
|
701
|
/**
|
568
|
* 分-验证图形验证码-ajax
|
702
|
* 分-验证图形验证码-ajax
|
569
|
*/
|
703
|
*/
|
570
|
const checkVerifyCode = (req) => {
|
704
|
const checkVerifyCode = (req) => {
|
571
|
- let code = _.trim(req.body.verifyCode || ''),
|
705
|
+ let captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(),
|
572
|
resqData = {};
|
706
|
resqData = {};
|
573
|
|
707
|
|
574
|
- // captchaCode = code.toLowerCase(),
|
|
|
575
|
-
|
|
|
576
|
- // if (!PassportModel::verifyCode($captchaCode)) {
|
|
|
577
|
- // resqData.code = 400;
|
|
|
578
|
- // resqData.message = '图形验证码不正确';
|
|
|
579
|
- // }
|
|
|
580
|
- // else {
|
708
|
+ if (captchaCode && captchaCode !== req.session.captcha) {
|
|
|
709
|
+ resqData.code = 400;
|
|
|
710
|
+ resqData.message = '图形验证码不正确';
|
|
|
711
|
+ }else {
|
581
|
resqData.code = code;
|
712
|
resqData.code = code;
|
582
|
resqData.message = '';
|
713
|
resqData.message = '';
|
|
|
714
|
+ }
|
|
|
715
|
+
|
|
|
716
|
+ return resqData;
|
|
|
717
|
+ };
|
|
|
718
|
+ /**
|
|
|
719
|
+ * 手机身份验证-校验手机号
|
|
|
720
|
+ */
|
|
|
721
|
+ const identityMobile = (req) => {
|
|
|
722
|
+ return co(function*() {
|
|
|
723
|
+ let mobile = req.body.mobile || '',
|
|
|
724
|
+ resqData = {code: 400},
|
|
|
725
|
+ uid = req.uid,
|
|
|
726
|
+ check = false,
|
|
|
727
|
+ userId;
|
|
|
728
|
+
|
|
|
729
|
+ let mobileInfo = handleMobile(mobile);
|
|
|
730
|
+
|
|
|
731
|
+ let userInfo = yield userApi.getUserInfoByMobile(area, mobile);
|
583
|
|
732
|
|
584
|
- // }
|
733
|
+ userId = 'uid' in userInfo.data ? userInfo.data.uid : 0;
|
|
|
734
|
+ if (userId === uid) {
|
|
|
735
|
+ check = true;
|
|
|
736
|
+ }
|
|
|
737
|
+
|
|
|
738
|
+ if (check) {
|
|
|
739
|
+ resqData = {
|
|
|
740
|
+ code: 200,
|
|
|
741
|
+ message: '',
|
|
|
742
|
+ data: ''
|
|
|
743
|
+ }
|
|
|
744
|
+ }else {
|
|
|
745
|
+ resqData = {
|
|
|
746
|
+ code: 400,
|
|
|
747
|
+ message: '手机号错误',
|
|
|
748
|
+ data: ''
|
|
|
749
|
+ }
|
|
|
750
|
+ }
|
|
|
751
|
+ return resqData;
|
|
|
752
|
+ })();
|
|
|
753
|
+ };
|
|
|
754
|
+/**
|
|
|
755
|
+ * 向验证手机号发送短信-ajax
|
|
|
756
|
+ */
|
|
|
757
|
+ const sendMobileMsg = (req) => {
|
|
|
758
|
+ return co(function*() {
|
|
|
759
|
+ let mobile = req.body.mobile || '',
|
|
|
760
|
+ resqData = {code: 400},
|
|
|
761
|
+ uid = req.uid;
|
|
|
762
|
+
|
|
|
763
|
+ let mobileInfo = handleMobile(mobile);
|
|
|
764
|
+
|
|
|
765
|
+ resqData = yield accountApi.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area);
|
585
|
|
766
|
|
586
|
return resqData;
|
767
|
return resqData;
|
|
|
768
|
+ })();
|
587
|
};
|
769
|
};
|
|
|
770
|
+/**
|
|
|
771
|
+ * 校验短信验证码-ajax
|
|
|
772
|
+ */
|
|
|
773
|
+const checkMobileMsg = (req) => {
|
|
|
774
|
+ return co(function*() {
|
|
|
775
|
+ let mobile = req.body.mobile || '',
|
|
|
776
|
+ code = req.body.code || '',
|
|
|
777
|
+ uid = req.uid,
|
|
|
778
|
+ resqData;
|
|
|
779
|
+
|
|
|
780
|
+ if (mobile === '') {
|
|
|
781
|
+ resqData = {
|
|
|
782
|
+ code: 400,
|
|
|
783
|
+ message: '手机号为空',
|
|
|
784
|
+ data: ''
|
|
|
785
|
+ }
|
|
|
786
|
+ return resqData;
|
|
|
787
|
+ }
|
|
|
788
|
+ if (code === '') {
|
|
|
789
|
+ resqData = {
|
|
|
790
|
+ code: 400,
|
|
|
791
|
+ message: '验证码为空',
|
|
|
792
|
+ data: ''
|
|
|
793
|
+ }
|
|
|
794
|
+ return resqData;
|
|
|
795
|
+ }
|
|
|
796
|
+ let mobileInfo = handleMobile(mobile);
|
|
|
797
|
+
|
|
|
798
|
+ resqData = yield accountApi.checkVerifyMsg(uid, mobileInfo.mobile, mobileInfo.area);
|
|
|
799
|
+
|
|
|
800
|
+ if (resqData.code === 200) {
|
|
|
801
|
+ let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) + '_' +
|
|
|
802
|
+ mobileInfo.mobile + mobileInfo.area + 'completeverify');
|
|
|
803
|
+
|
|
|
804
|
+ resqData.data = checkCode;
|
|
|
805
|
+ }
|
|
|
806
|
+ return resqData;
|
|
|
807
|
+ })();
|
|
|
808
|
+};
|
|
|
809
|
+/**
|
|
|
810
|
+ * 身份验证时,发送邮件-ajax
|
|
|
811
|
+ */
|
|
|
812
|
+const sendEmail = (req) => {
|
|
|
813
|
+ return co(function*() {
|
|
|
814
|
+ let uid = req.body.uid,
|
|
|
815
|
+ checkType = req.body.checkType || 'userpwd',
|
|
|
816
|
+ email = req.body.email || '',
|
|
|
817
|
+ resqData = {code: 400};
|
|
|
818
|
+
|
|
|
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拼接于邮箱域名处;
|
|
|
822
|
+
|
|
|
823
|
+ resqData = yield accountApi.sendVerifyEmailForNext(email, callback);
|
|
|
824
|
+ return resqData;
|
|
|
825
|
+ })();
|
|
|
826
|
+};
|
|
|
827
|
+/**
|
|
|
828
|
+ * 分-修改邮箱前,校验邮箱-ajax
|
|
|
829
|
+ */
|
|
|
830
|
+const checkEmail = (req) => {
|
|
|
831
|
+ return co(function*() {
|
|
|
832
|
+ let uid = req.body.uid,
|
|
|
833
|
+ email = req.body.email || '',
|
|
|
834
|
+ resqData = {code: 400};
|
588
|
|
835
|
|
|
|
836
|
+ resqData = yield accountApi.checkVerifyEmail(uid, email);
|
|
|
837
|
+ return resqData;
|
|
|
838
|
+ })();
|
|
|
839
|
+};
|
|
|
840
|
+/**
|
|
|
841
|
+ * 修改密码
|
|
|
842
|
+ */
|
|
|
843
|
+ const modifyPwd = (req) => {
|
|
|
844
|
+ return co(function*() {
|
|
|
845
|
+ let uid = req.body.uid,
|
|
|
846
|
+ newPwd = req.body.newPwd || '',
|
|
|
847
|
+ captchaCode = _.trim(req.body.verifyCode || '').toLowerCase();
|
|
|
848
|
+ resqData = {code: 400};
|
|
|
849
|
+
|
|
|
850
|
+ if (captchaCode && captchaCode !== req.session.captcha) {
|
|
|
851
|
+ resqData.code = 400;
|
|
|
852
|
+ resqData.message = '图形验证码不正确';
|
|
|
853
|
+ }else {
|
|
|
854
|
+ resqData = yield accountApi.modifyPwd(uid, newPwd);
|
|
|
855
|
+ }
|
|
|
856
|
+ return resqData;
|
|
|
857
|
+ })();
|
|
|
858
|
+};
|
|
|
859
|
+/**
|
|
|
860
|
+ * 修改验证手机号
|
|
|
861
|
+ */
|
|
|
862
|
+ const modifyMobile = (req) => {
|
|
|
863
|
+ return co(function*() {
|
|
|
864
|
+ let mobile = req.body.mobile || '',
|
|
|
865
|
+ code = req.body.code || '',
|
|
|
866
|
+ uid = req.uid,
|
|
|
867
|
+ resqData = {code: 400};
|
|
|
868
|
+
|
|
|
869
|
+ if (mobile === '') {
|
|
|
870
|
+ resqData = {
|
|
|
871
|
+ code: 400,
|
|
|
872
|
+ message: '手机号为空',
|
|
|
873
|
+ data: ''
|
|
|
874
|
+ }
|
|
|
875
|
+ return resqData;
|
|
|
876
|
+ }
|
|
|
877
|
+ if (code === '') {
|
|
|
878
|
+ resqData = {
|
|
|
879
|
+ code: 400,
|
|
|
880
|
+ message: '验证码为空',
|
|
|
881
|
+ data: ''
|
|
|
882
|
+ }
|
|
|
883
|
+ return resqData;
|
|
|
884
|
+ }
|
|
|
885
|
+ let mobileInfo = handleMobile(mobile);
|
|
|
886
|
+
|
|
|
887
|
+ let checkFlag = accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
|
|
|
888
|
+
|
|
|
889
|
+ if (checkFlag.code === 200) {
|
|
|
890
|
+ resqData = accountApi.modifyVerifyMobile(uid, mobileInfo.area, mobileInfo.mobile);
|
|
|
891
|
+ }else {
|
|
|
892
|
+ resqData = {
|
|
|
893
|
+ code: checkFlag.data,
|
|
|
894
|
+ message: checkFlag.message,
|
|
|
895
|
+ data: ''
|
|
|
896
|
+ }
|
|
|
897
|
+ }
|
|
|
898
|
+ return resqData;
|
|
|
899
|
+ })();
|
|
|
900
|
+};
|
|
|
901
|
+/**
|
|
|
902
|
+ * 分-检查手机号是否可修改-ajax
|
|
|
903
|
+ */
|
|
|
904
|
+const checkMobile = (req) => {
|
|
|
905
|
+ return co(function*() {
|
|
|
906
|
+ let uid = req.body.uid,
|
|
|
907
|
+ mobile = req.body.mobile || '',
|
|
|
908
|
+ resqData = {code: 400};
|
|
|
909
|
+
|
|
|
910
|
+ let mobileInfo = handleMobile(mobile);
|
|
|
911
|
+
|
|
|
912
|
+ resqData = yield accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
|
|
|
913
|
+ return resqData;
|
|
|
914
|
+ })();
|
|
|
915
|
+};
|
|
|
916
|
+/**
|
|
|
917
|
+ * 修改验证邮箱校验并发送邮件-ajax
|
|
|
918
|
+ *
|
|
|
919
|
+ */
|
|
|
920
|
+ const modifyEmail = (req) => {
|
|
|
921
|
+ return co(function*() {
|
|
|
922
|
+ let uid = req.body.uid,
|
|
|
923
|
+ email = req.body.email || '',
|
|
|
924
|
+ resqData = {code: 400};
|
|
|
925
|
+
|
|
|
926
|
+ let check = yield accountApi.checkVerifyEmail(uid, email);
|
|
|
927
|
+
|
|
|
928
|
+ if (check.code === 200) {
|
|
|
929
|
+ resqData = accountApi.sendVerifyEmail(uid, email);
|
|
|
930
|
+ }
|
|
|
931
|
+ return resqData;
|
|
|
932
|
+ })();
|
|
|
933
|
+};
|
589
|
module.exports = {
|
934
|
module.exports = {
|
590
|
getAccountInfo,
|
935
|
getAccountInfo,
|
591
|
userPwd,
|
936
|
userPwd,
|
592
|
userEmail,
|
937
|
userEmail,
|
593
|
userMobile,
|
938
|
userMobile,
|
594
|
- checkVerifyCode
|
939
|
+ sendEmailSuccess,
|
|
|
940
|
+ mailResult,
|
|
|
941
|
+ verifyPassword,
|
|
|
942
|
+ checkPassword,
|
|
|
943
|
+ checkVerifyCode,
|
|
|
944
|
+ identityMobile,
|
|
|
945
|
+ sendMobileMsg,
|
|
|
946
|
+ checkMobileMsg,
|
|
|
947
|
+ sendEmail,
|
|
|
948
|
+ checkEmail,
|
|
|
949
|
+ checkMobile,
|
|
|
950
|
+ modifyEmail,
|
|
|
951
|
+ modifyMobile,
|
|
|
952
|
+ modifyPwd
|
595
|
}; |
953
|
}; |