third-pwd.js
3.28 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
/**
* 第三方绑定重设密码
* @author: TaoHuang
* @date: 2016/7/12
*/
var $ = require('yoho-jquery');
var pwdRegx = require('../common/mail-phone-regx').pwdValidateRegx;
var $passwordInput = $('#pwd'),
$repasswordInput = $('#repwd');
var $sourceType = $('#sourceType');
var $openId = $('#openId');
var $mobile = $('#mobile');
var $area = $('#area');
var $next = $('#next');
var EventProxy = require('yoho-eventproxy');
var ep = new EventProxy();
require('yoho-jquery-placeholder');
function errTip(ele, msg) {
var $errTip = ele.next('.tips');
var $errMsg = $errTip.find('.content');
$errMsg.text(msg);
return $errTip.removeClass('hide');
}
function hideTip(ele) {
return ele.next('.tips').addClass('hide');
}
// 确保二次密码输入正确
ep.tail('pwd', 'repwd', function(pwd, repwd) {
if (pwd && repwd) {
$next.removeClass('disable');
} else {
$next.addClass('disable');
}
});
$passwordInput.on('keyup blur', function() {
var length = $passwordInput.val().length;
$passwordInput.removeClass('focus');
if (length === 0) {
errTip($passwordInput, '请输入密码');
ep.emit('pwd', false);
return;
}
if (length < 6 || length > 20) {
errTip($passwordInput, '密码只支持 6-20 位字符,建议字母+数字的组合');
ep.emit('pwd', false);
return;
}
if (!pwdRegx.test($passwordInput.val())) {
errTip($passwordInput, '密码只支持 6-20 位字符,建议字母+数字的组合');
ep.emit('pwd', false);
return;
}
ep.emit('pwd', true);
}).on('focus', function() {
hideTip($passwordInput);
$passwordInput.addClass('focus');
});
$repasswordInput.on('keyup blur', function() {
var length = $repasswordInput.val().length;
$repasswordInput.removeClass('focus');
if (length === 0) {
errTip($repasswordInput, '请再次输入密码');
ep.emit('repwd', false);
return;
}
if ($passwordInput.val() !== $repasswordInput.val()) {
errTip($repasswordInput, '两次输入的密码不一致,请重新输入');
ep.emit('repwd', false);
return;
}
ep.emit('repwd', true);
}).on('focus', function() {
hideTip($repasswordInput);
$repasswordInput.addClass('focus');
});
// 下一步
function nextPage() {
$.ajax({
type: 'POST',
url: '/passport/autouserinfo/bindmobile',
data: {
openId: $openId.val(),
sourceType: $sourceType.val(),
mobile: $mobile.val(),
area: $area.val(),
password: $passwordInput.val()
}
}).then(function(result) {
if (result.code === 200) {
window.location.href = result.data.refer;
} else {
errTip($next, result.message);
}
});
}
$('[placeholder]').placeholder();
$next.on('click', function() {
if ($next.hasClass('disable')) {
return;
}
if ($passwordInput.val() !== $repasswordInput.val()) {
errTip($repasswordInput, '两次输入的密码不一致,请重新输入');
return;
}
nextPage();
});
ep.on('repwd', function(repwdAuth) {
if (repwdAuth) {
hideTip();
}
});
ep.on('pwd', function(pwdAuth) {
if (pwdAuth) {
hideTip();
}
});