validate.js
4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* [个人中心]个人设置-第一步身份验证
* @author: jiangmin
* @date: 2016/07/14
*/
var $imgCaptchaInput = $('#captcha');
var dialog = require('../../plugins/dialog');
var _alert = dialog.Alert;
var types = location.pathname.split('/');
var type = types[types.length - 1];// 界面操作类型
/**
* 手机号码验证
*/
var second = 60;
var $sms = $('#send-code');// 发送短信验证码按钮
// 发送短信后倒计时显示
var disableSMSBtn = function() {
second -= 1;
if (second < 0) {
second = 60;
$sms.removeClass('progress').removeClass('disable').text('获取短信验证码');
} else {
$sms.add('progress');
$sms.text(second + '秒后可重新操作');
window.setTimeout(disableSMSBtn, 1000);
}
};
require('yoho-jquery-placeholder');
$('[placeholder]').placeholder();
// 发送手机验证码
$sms.click(function() {
var mobile = $('#real-mobile').val();
var area = $('#country-code').text();
if ($(this).hasClass('disable')) {
return;
}
$sms.addClass('disable');
$.ajax({
type: 'POST',
url: '/me/account/sendMobileMsg',
dataType: 'json',
data: {
mobile: mobile,
area: area
},
success: function(data) {
if (data.code !== 200) {
new _alert(data.message).show();
$sms.removeClass('disable');
} else {
disableSMSBtn();
}
}
});
});
// 手机验证第一步提交
$('#mobile-step1').click(function() {
var code = $('#msg-code').val().trim();
var mobile = $('#real-mobile').val();
var area = '+86';
$.ajax({
type: 'POST',
url: '/me/setting/step1/mobile',
data: {
code: code,
mobile: mobile,
area: area
},
success: function(data) {
if (data.code === 200) {
location.href = '/me/setting/step2/' + type + '?checkCode=' + $('#checkCode').val();
} else {
// location.href = '/me/setting/step2/' + type + "?checkCode=" + $("#checkCode").val();
new _alert('验证码不正确!').show();
$('#msg-code').val('');
}
}
});
});
/**
* 密码校验
*/
// 换图形验证码
$('.change-captcha').click(function() {
var time = new Date();
var $captchaImg = $('.captcha-img');
var captchaImgSrc = $captchaImg.attr('src').split('?')[0];
$captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
});
// 校验图片验证码
$imgCaptchaInput.blur(function() {
$.ajax({
type: 'POST',
url: '/passport/images/check',
data: {
verifyCode: $imgCaptchaInput.val()
},
success: function(data) {
if (data.code === 200) {
$imgCaptchaInput.parent().find('.tips-success').addClass('ok').show();
$imgCaptchaInput.parent().find('.tips-error').removeClass('notok').hide();
} else {
$imgCaptchaInput.parent().find('.tips-success').removeClass('ok').hide();
$imgCaptchaInput.parent().find('.tips-error').addClass('notok').show();
}
}
});
});
// 第一步提交
$('#pwd-step1').click(function() {
var password = $('#verifyPwd').val();
if ($('.notok').length === 0) {
$.ajax({
type: 'POST',
url: '/me/setting/step1/password',
data: {
password: password
},
success: function(data) {
if (data.code === 200) {
location.href = '/me/setting/step2/' + type + '?checkCode=' + $('#checkCode').val();
} else {
new _alert('登录密码校验错误!').show();
}
}
});
}
});
/**
* 邮箱验证
*/
$('#email-step1').click(function() {
if ($('.notok').length === 0) {
$.ajax({
type: 'POST',
url: '/me/setting/step1/email',
data: {
email: $('#real-email').val()
},
success: function(data) {
// todo 发送邮件
if (data.code === 200) {
$('.operate1').hide();
$('.operate2').show();
$('.footer-tips').eq(0).hide();
$('.footer-tips').eq(2).show();
} else {
new _alert(data.message).show();
}
}
});
}
});