security.js
9.32 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
(function () {
"use strict";
var encryptPassword = function (password)
//noinspection JSHint
{
//noinspection JSHint
return hex_md5(password);
};
angular.module("xn.page", ["ui.bootstrap.carousel"])
.config(["xnValidatorProvider", function (xnValidatorProvider) {
xnValidatorProvider.setRules({
account: {
required: "输入的用户名不能为空!",
pattern: "用户名只能必须输入英文字母、数字、下划线和点,并且以字母开头!"
},
tenantNumber: {
required: "企业靓号必须选择!",
pattern: "企业靓号应该是数字!"
},
password: {
required: "密码不能为空!"
},
oldPassword: {
required: "原密码不能为空!"
},
newPassword: {
required: "新密码不能为空!",
pattern: "密码只能输入英文字母、数字和下划线,并且以字母开头!",
minlength: "密码长度不能小于6个字符!",
maxlength: "密码长度不能大于20个字符!"
},
confirmPassword: {
required: "确认新密码不能为空!",
repeat: "两次密码输入要相同!"
},
forgetEmail: {
required: "请输入邮箱地址!"
}
});
}])
/**
* 登录控制器
*/
.controller("LoginCtrl", ["$scope", "$window", "$http", "SecurityService",
function ($scope, $window, $http, SecurityService) {
//800001是默认猫空的编号,TODO 将来应去除
$scope.signin = {account: "", password: "", tenantNumber: "800001"};
/**
* 登录方法
*/
$scope.doLogin = function () {
var btn = $("#btnSubmit");
btn.button("loading");
var hashPassword = encryptPassword($scope.signin.password);
//此处构建专门的request是为了不将原始password传输,安全考虑
var request = {
"account": $scope.signin.account,
"password": hashPassword,
"tenantNumber": $scope.signin.tenantNumber
};
SecurityService.login(request).success(
function (data) {
if (data.errors === null || data.errors.length > 0) {
//noinspection JSHint
$scope["loginForm"].$errors.push(data.errors[0].message);
btn.button("reset");
} else {
$window.location.href = "/index.htm";
}
}
);
};
//幻灯片
$scope.myInterval = 2000;
var slides = $scope.slides = [];
$scope.addSlide = function() {
var newWidth = "login_flash_" + slides.length+".png";
slides.push({
image: "/home/images/public/" + newWidth,
text:["云平台化方式","信息化服务","打造","开创"][slides.length % 4],
content: ["门槛低 花钱少","陪伴您一起成长","电子商务环境下的商业模式","连锁门店的管理与服务"][slides.length % 4]
});
};
for (var i=0; i<4; i++) {
$scope.addSlide();
}
}])
.controller("LogoutCtrl", ["$scope", "$window", "$http", "SecurityService",
function ($scope, $window, $http, SecurityService) {
$scope.success=false;
$scope.doLogout = function() {
SecurityService.logout().success(
function() {
$scope.success=true;
}
);
};
$scope.doLogout();
}])
/**
* 密码忘记控制器
*/
.controller("ForgetCtrl", ["$scope", "$http", "$timeout", "SecurityService",
function ($scope, $http, $timeout, SecurityService) {
$scope.forget = {tenantNumber: "", account: ""};
$scope.success = false;
//数据提交
$scope.doForget = function () {
var btn = $("#btnSubmit").button("loading");
SecurityService.doForget($scope.forget).success(
function (data) {
if (data.errors === null || data.errors.length > 0) {
//noinspection JSHint
$scope["forgetForm"].$errors.push(data.errors[0].message);
btn.button("reset");
} else {
$scope.success = true;
btn.button("reset");
}
}
);
};
}])
/**
* 重置密码控制器
*/
.controller("ResetCtrl", ["$scope", "$http", "$timeout", "$location", "SecurityService", "toolsService",
function ($scope, $http, $timeout, $location, SecurityService, toolsService) {
$scope.reset = {};
$scope.stepIndex = 0;
$scope.verification =
{code: toolsService.parameter("code", $location.absUrl()),
tenantId: toolsService.parameter("tenant", $location.absUrl())
};
SecurityService.checkVerification($scope.verification).success(
function (data) {
if (data.errors === null || data.errors.length > 0) {
console.log("验证码错误");
$scope.stepIndex = 0;
} else {
if (data.isVerificated === false) {
$scope.stepIndex = 0;
}
else {
$scope.stepIndex = 1;
}
}
}
);
$scope.doReset = function () {
var btn = $("#btnSubmit").button("loading");
var req = {
tenantId: $scope.verification.tenantId,
code: $scope.verification.code,
loginPassword: encryptPassword($scope.reset.newPassword)
};
SecurityService.resetPassword(req).success(
function (data) {
if (data.errors === null || data.errors.length > 0) {
//noinspection JSHint
$scope["resetForm"].$errors.push(data.errors[0].message);
btn.button("reset");
} else {
$scope.stepIndex = 2;
btn.button("reset");
}
}
);
};
}])
/**
* 修改密码控制器
*/
.controller("ChangeCtrl", ["$scope", "$http", "$timeout", "SecurityService",
function ($scope, $http, $timeout, SecurityService) {
$scope.success = false;
$scope.change = {
"oldPassword": "",
"newPassword": ""
};
$scope.doChange = function () {
var req = {
"loginPassword": encryptPassword($scope.change.newPassword),
"confirmPassword":encryptPassword($scope.change.confirmPassword),
"oldLoginPassword": encryptPassword($scope.change.oldPassword)
};
// 判断输入的新密码是否一致
if(req.confirmPassword == req.loginPassword) {
var btn = $("#btnSubmit").button("loading");
SecurityService.doChange(req).success(
function (data) {
if (data.errors == null || data.errors.length > 0) {
//noinspection JSHint
$scope["changeForm"].$errors.push(data.errors[0].message);
btn.button("reset");
} else {
$scope.success = true;
btn.button("reset");
}
}
);
} else {
$scope["changeForm"].$errors.push("密码不一致");
}
};
}]);
})();