reset.page.js
2.23 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
/*
* @Author: Targaryen
* @Date: 2017-04-13 14:43:19
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-18 11:36:23
*/
/* ***************
* 密码重置
*****************/
const $ = require('yoho-jquery');
require('common');
let validatePWD = require('./password-check');
let tip = require('plugin/tip');
let $resetForm = $('.reset-form');
let $oldPasswordInput = $('#oldPassword');
let $newPasswordInput = $('#newPassword');
let $eye = $resetForm.find('.eye');
let $sureResetBtn = $('#sureResetBtn');
// 登录按钮状态切换
function switchLoginBtnStatus() {
let active = ($oldPasswordInput.val() && $newPasswordInput.val()) ? true : false;
$sureResetBtn.toggleClass('active', active);
}
$oldPasswordInput.bind('input', function() {
switchLoginBtnStatus();
});
$newPasswordInput.bind('input', function() {
switchLoginBtnStatus();
});
/**
* 密码显示隐藏
*/
$eye.on('click', function() {
if ($eye.hasClass('close')) {
$newPasswordInput.attr('type', 'text');
$eye.removeClass('close');
} else {
$newPasswordInput.attr('type', 'password');
$eye.addClass('close');
}
});
/**
* 提交密码重置
*/
$sureResetBtn.on('click', function() {
if (!$sureResetBtn.hasClass('active')) {
return false;
}
// 简单的密码校验
if (!$oldPasswordInput.val() || !$newPasswordInput.val()) {
tip.show('请输入旧密码和新密码');
return false;
}
if (!validatePWD($newPasswordInput.val())) {
tip.show('密码应为6-20位字母、数字的组合');
return false;
}
$.ajax({
type: 'post',
url: '/passport/password/reset',
data: {
oldPwd: $oldPasswordInput.val(),
newPwd: $newPasswordInput.val()
},
dataType: 'json',
success: function(result) {
tip.show(result.message);
let href = '/passport/password/resetsuccess';
if (result.code !== 200) {
href = '/passport/login';
}
setTimeout(function() {
window.location.href = href;
}, 500);
},
error: function() {
tip.show('系统异常!');
}
});
});