login-new.js
6.8 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
const $ = require('yoho-jquery');
const $captcha = $('#js-img-check');
const tip = require('plugin/tip');
const Modal2 = require('plugin/modal2');
const showErrTip = tip.show;
const api = require('../api');
const trim = $.trim;
const Validate = require('plugin/validata');
const cookie = require('yoho-cookie');
const validate = new Validate($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
class Login {
constructor() {
this.view = {
loginBtn: $('#loginBtn'),
clearUsrname: $('#clearUsrname'),
usernameInput: $('input[name=username]'),
passwordInput: $('input[name=password]'),
passwordEyeIcon: $('#passwordEyeIcon'),
eyeClose: $('.eye-close'),
eyeOpen: $('.eye-open'),
getPswrdBtn: $('#getPswrdBtn'),
getPasswordBox: $('.get-password-box'),
showYohoFamilyTip: $('#showYohoFamilyTip')
};
this.view.loginBtn.on('click', this.login.bind(this));
this.view.clearUsrname.on('click', this.clearUsrname.bind(this));
this.view.passwordEyeIcon.on('click', this.passwordShowStatus.bind(this));
this.view.getPswrdBtn.on('click', this.showGetPasswordBox.bind(this));
this.view.getPasswordBox.on('click', this.hiddenGetPasswordBox.bind(this));
this.view.showYohoFamilyTip.on('click', this.showYohoFamilyTip.bind(this));
this.view.usernameInput.bind('input', this.changeBtnStatus.bind(this, 'username'));
this.view.passwordInput.bind('input', this.changeBtnStatus.bind(this));
if ($captcha.data('userverify')) {
validate.init();
}
}
/**
* 输入监听,改变按钮状态
* which
*/
changeBtnStatus(which) {
if (which === 'username') {
// 清除按钮
if (this.view.usernameInput.val()) {
this.view.clearUsrname.removeClass('hide');
} else {
this.view.clearUsrname.addClass('hide');
}
}
// 登录按钮
if (this.view.usernameInput.val() && this.view.passwordInput.val()) {
this.view.loginBtn.removeClass('disable');
} else {
this.view.loginBtn.addClass('disable');
}
}
/**
* 展示弹窗
*/
showYohoFamilyTip() {
Modal2.alert('Yoho!Family账号可登录YOHO!旗下所有应用(含:Yoho!Buy有货、Yoho!Now、mars、BLK、Yoho!Store)');
}
/**
* 登录
*/
login() {
if (this.view.loginBtn.hasClass('disable')) {
return;
}
let acc = trim(this.view.usernameInput.val()),
pwd = trim(this.view.passwordInput.val());
// 验证账号(数字或者邮箱)和密码合理性
if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) {
let params = {
account: acc,
password: pwd,
isskip: window.queryString.isskip
};
validate.getResults().then((result) => {
this.view.loginBtn.text('正在登录...').addClass('disable');
$.extend(params, result);
// auth
this.loginAuth(params, acc);
}, () => {});
} else {
showErrTip('账号或密码有错误,请重新输入');
this.view.loginBtn.text('登录').removeClass('disable');
}
}
loginAuth(params, acc) {
$.ajax({
type: 'POST',
url: '/passport/login/auth',
data: params,
success: (data) => {
let res,
LOGI_TYPE;
if (acc.indexOf('@') > 0) {
LOGI_TYPE = 8;
} else {
LOGI_TYPE = 5;
}
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_MY_LOGIN_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
LOGI_TYPE: LOGI_TYPE
})
}, true);
}
validate && validate.type === 2 && validate.refresh();
if (data.code === 200) {
res = data.data;
showErrTip('登录成功');
location.href = res.href;
this.view.loginBtn.text('登录成功');
} else if (data.code === 4189) {
cookie.set('_loginJumpUrl', $('input[name=username]').val());
showErrTip('您的账号存在安全隐患需要进行身份验证');
setTimeout(() => {
location.href = data.url;
}, 2500);
} else if (data.code === 510 || data.code === 50004) {
location.href = data.url;
} else {
$captcha.data('userverify', data.captchaShow);
if (data.captchaShow) {
if (validate.atWorking) {
((data.changeCaptcha && validate.type !== 2) && validate.refresh());
} else {
validate.init();
}
}
showErrTip(data.message);
this.resetForm();
}
return data;
},
error: () => {
showErrTip('网络断开连接啦~');
validate && validate.refresh();
},
complete: () => {
this.view.loginBtn.text('登录').removeClass('disable');
}
});
}
resetForm() {
this.view.loginBtn.text('登录').addClass('disable');
}
/**
* 清除输入的用户名
*/
clearUsrname() {
this.view.usernameInput.val('');
this.view.clearUsrname.addClass('hide');
}
/**
* 隐藏显示密码
*/
passwordShowStatus() {
if (this.view.eyeOpen.hasClass('hide')) {
this.view.passwordInput.attr('type', 'text');
this.view.eyeClose.addClass('hide');
this.view.eyeOpen.removeClass('hide');
} else {
this.view.passwordInput.attr('type', 'password');
this.view.eyeOpen.addClass('hide');
this.view.eyeClose.removeClass('hide');
}
}
/**
* 显示找回密码遮罩
*/
showGetPasswordBox() {
this.view.getPasswordBox.removeClass('hide');
}
/**
* 隐藏找回密码遮罩
*/
hiddenGetPasswordBox() {
this.view.getPasswordBox.addClass('hide');
return false;
}
}
module.exports = Login;