|
|
1
|
+/**
|
|
|
2
|
+ * 找回密码
|
|
|
3
|
+ * @author: xuqi<qi.xu@yoho.cn>
|
|
|
4
|
+ * @date: 2015/12/14
|
|
|
5
|
+ */
|
|
|
6
|
+
|
|
|
7
|
+var $ = require('yoho-jquery');
|
|
|
8
|
+
|
|
|
9
|
+var regx = require('../common/mail-phone-regx');
|
|
|
10
|
+
|
|
|
11
|
+var Captcha = require('../../plugins/captcha');
|
|
|
12
|
+
|
|
|
13
|
+var emailAc = require('../common/ac-email'); // 邮箱自动完成
|
|
|
14
|
+
|
|
|
15
|
+var emailReg = regx.emailRegx,
|
|
|
16
|
+ phoneRegx = regx.phoneRegx;
|
|
|
17
|
+
|
|
|
18
|
+var $cr = $('#country-code-hide'),
|
|
|
19
|
+ $phoneNum = $('#phone-num'),
|
|
|
20
|
+ $ca = $('#captcha'),
|
|
|
21
|
+ $ccList = $('#country-code-list'),
|
|
|
22
|
+ $cc = $('#country-code'),
|
|
|
23
|
+ $btn = $('#find-btn'),
|
|
|
24
|
+ $accErr = $('#account-err'),
|
|
|
25
|
+ caCount = 4, // 验证码位数
|
|
|
26
|
+ hasPh = false,
|
|
|
27
|
+ captcha = new Captcha('#captcha-img').init();
|
|
|
28
|
+
|
|
|
29
|
+require('../../simple-header');
|
|
|
30
|
+require('yoho-jquery-placeholder');
|
|
|
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
|
+ captcha.refresh();
|
|
|
52
|
+ return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
53
|
+ } else if (data.code === 405) {
|
|
|
54
|
+ captcha.showTip(data.message);
|
|
|
55
|
+ return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
56
|
+ }
|
|
|
57
|
+ });
|
|
|
58
|
+}
|
|
|
59
|
+
|
|
|
60
|
+function vaPn(v) {
|
|
|
61
|
+ var pass = true,
|
|
|
62
|
+ errTxt = '';
|
|
|
63
|
+
|
|
|
64
|
+ v = $.trim(v);
|
|
|
65
|
+ if (v !== '') {
|
|
|
66
|
+ if (/^[0-9]+$/.test(v)) {
|
|
|
67
|
+ if (phoneRegx[$cr.val()].test(v)) {
|
|
|
68
|
+ pass = true;
|
|
|
69
|
+ } else {
|
|
|
70
|
+ errTxt = '手机号码格式不正确, 请重新输入';
|
|
|
71
|
+ pass = false;
|
|
|
72
|
+ }
|
|
|
73
|
+ } else {
|
|
|
74
|
+ if (emailReg.test(v)) {
|
|
|
75
|
+ pass = true;
|
|
|
76
|
+ } else {
|
|
|
77
|
+ errTxt = '邮箱格式不正确, 请重新输入';
|
|
|
78
|
+ pass = false;
|
|
|
79
|
+ }
|
|
|
80
|
+ }
|
|
|
81
|
+ } else {
|
|
|
82
|
+ errTxt = '账户名不能为空';
|
|
|
83
|
+ pass = false;
|
|
|
84
|
+ }
|
|
|
85
|
+ hasPh = pass;
|
|
|
86
|
+
|
|
|
87
|
+ return {
|
|
|
88
|
+ pass: pass,
|
|
|
89
|
+ errTxt: errTxt
|
|
|
90
|
+ };
|
|
|
91
|
+}
|
|
|
92
|
+
|
|
|
93
|
+function validatePhone() {
|
|
|
94
|
+ var pnVa = vaPn($phoneNum.val());
|
|
|
95
|
+
|
|
|
96
|
+ if (pnVa.pass) {
|
|
|
97
|
+ $accErr.addClass('hide');
|
|
|
98
|
+ $phoneNum.removeClass('error');
|
|
|
99
|
+ } else {
|
|
|
100
|
+ $accErr.removeClass('hide').find('em').text(pnVa.errTxt);
|
|
|
101
|
+ $phoneNum.addClass('error');
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ return pnVa.pass;
|
|
|
105
|
+}
|
|
|
106
|
+
|
|
|
107
|
+emailAc($phoneNum, function() {
|
|
|
108
|
+ validatePhone();
|
|
|
109
|
+});
|
|
|
110
|
+
|
|
|
111
|
+$ca.attr('maxlength', caCount);
|
|
|
112
|
+
|
|
|
113
|
+// IE8 placeholder
|
|
|
114
|
+$('input').placeholder();
|
|
|
115
|
+
|
|
|
116
|
+$cc.on('click', function(e) {
|
|
|
117
|
+ e.stopPropagation();
|
|
|
118
|
+ if ($ccList.css('style') === 'block') {
|
|
|
119
|
+ $ccList.slideUp('fast');
|
|
|
120
|
+ } else {
|
|
|
121
|
+ $ccList.slideDown('fast');
|
|
|
122
|
+ }
|
|
|
123
|
+});
|
|
|
124
|
+
|
|
|
125
|
+$ccList.delegate('li', 'click', function(e) {
|
|
|
126
|
+ var $cur = $(this),
|
|
|
127
|
+ code = $cur.data('cc'),
|
|
|
128
|
+ pnVa;
|
|
|
129
|
+
|
|
|
130
|
+ e.stopPropagation();
|
|
|
131
|
+ $cr.val(code);
|
|
|
132
|
+ $cc.find('em').html($cur.text());
|
|
|
133
|
+
|
|
|
134
|
+ // 切换后验证手机号码
|
|
|
135
|
+ if ($.trim($phoneNum.val()) !== '') {
|
|
|
136
|
+ pnVa = vaPn($phoneNum.val());
|
|
|
137
|
+ if (hasPh) {
|
|
|
138
|
+ $accErr.addClass('hide');
|
|
|
139
|
+ $phoneNum.removeClass('error');
|
|
|
140
|
+ } else {
|
|
|
141
|
+ $accErr.removeClass('hide').text(pnVa.errTxt);
|
|
|
142
|
+ $phoneNum.addClass('error');
|
|
|
143
|
+ }
|
|
|
144
|
+ }
|
|
|
145
|
+ $ccList.slideUp('fast');
|
|
|
146
|
+});
|
|
|
147
|
+
|
|
|
148
|
+$(document).click(function() {
|
|
|
149
|
+ if ($ccList.css('display') === 'block') {
|
|
|
150
|
+ $ccList.slideUp();
|
|
|
151
|
+ }
|
|
|
152
|
+});
|
|
|
153
|
+
|
|
|
154
|
+$phoneNum.keyup(function() {
|
|
|
155
|
+ vaPn($.trim($(this).val()));
|
|
|
156
|
+}).focus(function() {
|
|
|
157
|
+ $(this).removeClass('error');
|
|
|
158
|
+
|
|
|
159
|
+ // focus隐藏错误提示
|
|
|
160
|
+ $accErr.addClass('hide');
|
|
|
161
|
+});
|
|
|
162
|
+
|
|
|
163
|
+// 下一步
|
|
|
164
|
+$btn.click(function(e) {
|
|
|
165
|
+ if (!validatePhone()) {
|
|
|
166
|
+ return;
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
|
169
|
+ if (!captcha.getResults()) {
|
|
|
170
|
+ captcha.showTip();
|
|
|
171
|
+ return;
|
|
|
172
|
+ }
|
|
|
173
|
+
|
|
|
174
|
+ if (/^[0-9]+$/.test($.trim($phoneNum.val()))) {
|
|
|
175
|
+ $('#find-form').attr('action', '/passport/back/mobile');
|
|
|
176
|
+ }
|
|
|
177
|
+
|
|
|
178
|
+ $('#captcha-value').val(captcha.getResults());
|
|
|
179
|
+
|
|
|
180
|
+ if (hasPh) {
|
|
|
181
|
+ authcode().then(function() {
|
|
|
182
|
+ $.post($('#back-form').attr('action'), {
|
|
|
183
|
+ phoneNum: $('#phone-num').val(),
|
|
|
184
|
+ area: $('#country-code-hide').val()
|
|
|
185
|
+ }).then(function(result) {
|
|
|
186
|
+ if (result.code === 200) {
|
|
|
187
|
+ window.jumpUrl(result.data.refer);
|
|
|
188
|
+ return;
|
|
|
189
|
+ }
|
|
|
190
|
+
|
|
|
191
|
+ if (result.code === 405) {
|
|
|
192
|
+ captcha.showTip(result.message);
|
|
|
193
|
+ $accErr.addClass('hide');
|
|
|
194
|
+ $phoneNum.removeClass('error');
|
|
|
195
|
+ return;
|
|
|
196
|
+ }
|
|
|
197
|
+
|
|
|
198
|
+ $accErr.removeClass('hide').find('em').text(result.message);
|
|
|
199
|
+ $phoneNum.addClass('error');
|
|
|
200
|
+ });
|
|
|
201
|
+ });
|
|
|
202
|
+ }
|
|
|
203
|
+
|
|
|
204
|
+ e.preventDefault();
|
|
|
205
|
+ return true;
|
|
|
206
|
+});
|
|
|
207
|
+
|
|
|
208
|
+captcha.onSuccess(function() {
|
|
|
209
|
+ $btn.triggerHandler('click');
|
|
|
210
|
+}); |