password.js
3.9 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
/**
* 注册-密码
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/8
*/
var $ = require('yoho-jquery');
var $pwd = $('#pwd'),
$pwdLint = $('.pwd-lint'),
$pwdLintTxt = $pwdLint.find('.pwd-lint-txt'),
$btnSure = $('#btn-sure');
var api = require('../api');
var tip = require('plugin/tip');
var validatePWD = require('../password-check');
var trim = $.trim;
var showErrTip = tip.show;
var qs;
require('common');
api.bindEyesEvt({
status: 'open' // 默认眼睛打开
});
$pwd.bind('input', function() {
var val = $.trim(this.value);
var bool = validatePWD(val, function(res) {
$pwdLint.css({visibility: res.valid ? 'hidden' : 'visible'});
if (!res.valid) {
$pwdLintTxt.text(res.msg);
}
});
$btnSure.toggleClass('disable', !bool);
});
qs = window.queryString;
if (qs.selected && qs.selected === 'N') {
$('.pitch').removeClass('select').html('');
}
if (qs.pwd) {
$pwd.val(qs.pwd);
if (trim($pwd.val()) === '') {
$btnSure.addClass('disable');
} else {
$btnSure.removeClass('disable');
}
}
$('.pitch').on('click', function() {
if ($('.pitch').hasClass('select')) {
$(this).removeClass('select');
$(this).html('');
} else {
$(this).addClass('select');
$(this).html('');
}
});
function setPassword() {
$btnSure.addClass('disable');
return $.ajax({
type: 'POST',
url: '/passport/reg/setpassword',
data: {
password: trim($pwd.val()),
phoneNum: $('#phone-num').val(),
areaCode: $('#area-code').val(),
smsCode: $('#sms-code').val(),
token: $('#token').val()
},
success: function(data) {
var res = data.data;
if (data.code === 200) {
showErrTip('注册成功');
// 统计代码:用于统计从哪个渠道注册成功的
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_REGISTER_SUCCESS_L',
ud: window.getUid(),
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')] || 1,
UNION_TYPE: window.queryString.union_type || window.cookie('unionTypeYas') || false
})
}, true);
}
setTimeout(function() {
location.href = res.href;
}, 1500);
} else {
$btnSure.removeClass('disable');
showErrTip(data.message);
}
},
error: function(data) {
$btnSure.removeClass('disable');
if (data && data.responseJSON && data.responseJSON.message) {
showErrTip(data.message);
}
}
});
}
$btnSure.on('touchstart', function() {
var pwd = trim($pwd.val());
if ($btnSure.hasClass('disable')) {
return;
}
if (!validatePWD(pwd)) {
showErrTip('密码6-20位,请重新输入');
} else {
if ($('.pitch').hasClass('select')) {
setPassword();
} else {
$('.prompt').show();
$('.ensure').on('click', function() {
$('.prompt').hide();
$('.pitch').addClass('select');
$('.pitch').html('');
setPassword();
});
$('.deny').on('click', function() {
location.href = '//m.yohobuy.com/passport/agreement' + window.location.search + '&pwd=' + pwd;
});
}
}
});
$('.agreement-detail').on('click', function() {
$(this).attr('href', '//m.yohobuy.com/passport/agreement' + window.location.search);
});
// 如果有值, 立刻校验
if ($pwd.val()) {
$pwd.triggerHandler('input');
}