提交 | 用户 | age
|
a6a76f
|
1 |
package com.yc.sdk.password.action; |
F |
2 |
|
176de8
|
3 |
import com.alibaba.fastjson.JSON; |
a6a76f
|
4 |
import com.google.gson.JsonArray; |
F |
5 |
import com.google.gson.JsonObject; |
|
6 |
import com.yc.action.BaseAction; |
|
7 |
import com.yc.action.execProc.ExecuteProcAction; |
|
8 |
import com.yc.action.login.LoginAction; |
484907
|
9 |
import com.yc.api.bean.PwdBean; |
F |
10 |
import com.yc.api.controller.ApiController; |
a6a76f
|
11 |
import com.yc.entity.DataSourceEntity; |
F |
12 |
import com.yc.entity.UserAccountEntity; |
|
13 |
import com.yc.exception.CallBackMessage; |
|
14 |
import com.yc.factory.FactoryBean; |
|
15 |
import com.yc.multiData.MultiDataSource; |
|
16 |
import com.yc.multiData.SpObserver; |
|
17 |
import com.yc.sdk.shopping.util.SettingKey; |
|
18 |
import com.yc.service.BaseService; |
|
19 |
import com.yc.service.build.type.T_22_Ifc; |
|
20 |
import com.yc.service.demo.DemoIfc; |
|
21 |
import com.yc.service.user.UserAccountServiceIfc; |
|
22 |
import com.yc.utils.SessionKey; |
d24ea3
|
23 |
import org.springframework.beans.factory.annotation.Autowired; |
F |
24 |
import org.springframework.dao.DataAccessException; |
|
25 |
import org.springframework.stereotype.Controller; |
|
26 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
27 |
|
|
28 |
import javax.servlet.http.HttpServletRequest; |
|
29 |
import javax.servlet.http.HttpServletResponse; |
|
30 |
import javax.servlet.http.HttpSession; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Map; |
a6a76f
|
34 |
|
F |
35 |
@Controller |
|
36 |
@RequestMapping("/changepwd.do") |
|
37 |
public class ChangePasswordAction extends BaseAction { |
|
38 |
@Autowired UserAccountServiceIfc userAccountService; |
|
39 |
@Autowired T_22_Ifc t22ifc ; |
|
40 |
@Autowired |
|
41 |
DemoIfc demoIfc; |
d24ea3
|
42 |
@Autowired |
484907
|
43 |
ApiController apiController; |
a6a76f
|
44 |
Map<String, DataSourceEntity> demoList = MultiDataSource.getDataSourceMaps(); |
F |
45 |
Map<String,Object> demoMap = new HashMap<String,Object>() ; |
|
46 |
/** |
|
47 |
* 限于用户自己修改密码 |
|
48 |
* @param request |
|
49 |
* @param response |
|
50 |
*/ |
|
51 |
@RequestMapping(params = "m=owner") |
|
52 |
public void ChangeOwnerPwd(HttpServletRequest request,HttpServletResponse response) { |
|
53 |
HttpSession session = request.getSession(); |
|
54 |
|
|
55 |
String hostUrl = SettingKey.getHostUrl(request) ; |
|
56 |
String wxQueryString = SettingKey.getQueryStringByWx(request); |
|
57 |
boolean isSuccess = false ; |
|
58 |
|
|
59 |
String userCode = request.getParameter("usercode") ; |
|
60 |
|
|
61 |
if (userCode == null && session.getAttribute(SessionKey.USERCODE) != null) { |
|
62 |
userCode = (String)session.getAttribute(SessionKey.USERCODE) ; |
|
63 |
} |
|
64 |
if (userCode == null && session.getAttribute(SessionKey.HRCODE)!=null ) { |
|
65 |
userCode = (String)session.getAttribute(SessionKey.HRCODE) ; |
|
66 |
} |
|
67 |
JsonObject json = new JsonObject(); |
|
68 |
JsonObject errJson = new JsonObject(); |
|
69 |
JsonArray array=new JsonArray(); |
176de8
|
70 |
CallBackMessage callBackMessage=new CallBackMessage(); |
a6a76f
|
71 |
String enterCode = request.getParameter("entercode") ; |
F |
72 |
String oldPasswordPlainText = request.getParameter("oldpwd") ; |
|
73 |
if (oldPasswordPlainText == null || "".equals(oldPasswordPlainText)) { |
176de8
|
74 |
//errJson.addProperty("oldpwd", "旧密码 必须输入!"); |
F |
75 |
//json.add("error", errJson); |
|
76 |
callBackMessage.sendErrorMessage("旧密码 必须输入!"); |
|
77 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
78 |
return; |
F |
79 |
} |
|
80 |
|
|
81 |
String passwordPlainText = request.getParameter("pwd") ; |
|
82 |
if (passwordPlainText == null || "".equals(passwordPlainText)) { |
176de8
|
83 |
//errJson.addProperty("pwd","新密码 必须输入!" ) ; |
F |
84 |
//json.add("error", errJson); |
|
85 |
//this.printJson(response, json.toString()); |
|
86 |
callBackMessage.sendErrorMessage("新密码 必须输入!"); |
|
87 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
88 |
return; |
F |
89 |
} |
|
90 |
|
|
91 |
if (passwordPlainText.indexOf("@") > 0 ) { |
176de8
|
92 |
// errJson.addProperty("pwd"," 新密码不能含有 @ 特殊字符,请重新录入!") ; |
F |
93 |
// json.add("error", errJson); |
|
94 |
// this.printJson(response, json.toString()); |
|
95 |
callBackMessage.sendErrorMessage("新密码不能含有 @ 特殊字符,请重新录入!"); |
|
96 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
97 |
return; |
F |
98 |
} |
|
99 |
|
|
100 |
String pwdconfirm = request.getParameter("pwdconfirm") ; |
|
101 |
if (pwdconfirm == null || "".equals(pwdconfirm)) { |
176de8
|
102 |
// errJson.addProperty("pwdconfirm", "确认新密码 必须输入!"); |
F |
103 |
// json.add("error", errJson); |
|
104 |
// this.printJson(response, json.toString()); |
|
105 |
callBackMessage.sendErrorMessage("确认新密码 必须输入!"); |
|
106 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
107 |
return; |
F |
108 |
} |
|
109 |
|
|
110 |
if (userCode.equals(passwordPlainText)) { |
176de8
|
111 |
// errJson.addProperty("pwd"," 新密码 不能与用户名相同!") ; |
F |
112 |
// json.add("error", errJson); |
|
113 |
// this.printJson(response, json.toString()); |
|
114 |
callBackMessage.sendErrorMessage("新密码 不能与用户名相同!"); |
|
115 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
116 |
return; |
F |
117 |
} |
|
118 |
|
|
119 |
if ( ! passwordPlainText.equals(pwdconfirm)) { |
176de8
|
120 |
// errJson.addProperty("pwdconfirm", "【新密码】与【确认新密码】必须相同"); |
F |
121 |
// json.add("error", errJson); |
|
122 |
// this.printJson(response, json.toString()); |
|
123 |
callBackMessage.sendErrorMessage("【新密码】与【确认新密码】必须相同"); |
|
124 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
125 |
return; |
F |
126 |
} |
|
127 |
String success = "修改密码成功" ; |
|
128 |
//String dbId = Maintaince.getDatabaseId(request); |
|
129 |
try { |
|
130 |
|
|
131 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; |
|
132 |
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源 |
|
133 |
|
|
134 |
UserAccountEntity userAccount = userAccountService.getUserInfoByUserCode(userCode); |
|
135 |
if (userAccount == null) { |
176de8
|
136 |
// errJson.addProperty("pwd", " 用户[" + userCode + "]不存在或已被停用,不允许修改密码[dbid:" +dataSourceEntity.getDbId() +"]!"); |
F |
137 |
// json.add("error", errJson); |
|
138 |
// this.printJson(response, json.toString()); |
|
139 |
callBackMessage.sendErrorMessage( " 用户[" + userCode + "]不存在或已被停用,不允许修改密码[dbid:" +dataSourceEntity.getDbId() +"]!"); |
|
140 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
141 |
return; |
F |
142 |
} |
|
143 |
|
|
144 |
Integer pwdLength = userAccount.getPwdLength() ; |
|
145 |
if (pwdLength != null && !pwdLength.equals(0) && passwordPlainText.length() < pwdLength.intValue()) { |
176de8
|
146 |
// errJson.addProperty("pwd", "新密码太短,必须至少录入 " + pwdLength + " 字符!"); |
F |
147 |
// json.add("error", errJson); |
|
148 |
// this.printJson(response, json.toString()); |
|
149 |
|
|
150 |
callBackMessage.sendErrorMessage("新密码太短,必须至少录入 " + pwdLength + " 字符!"); |
|
151 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
152 |
return; |
F |
153 |
} |
|
154 |
String oldPassword = ChangePassword.getDecryptPassword((String) userAccount.getPassword()) ; |
|
155 |
if (!oldPasswordPlainText.equals(oldPassword)) { |
176de8
|
156 |
// errJson.addProperty("oldpwd", "旧密码不正确!"); |
F |
157 |
// json.add("error", errJson); |
|
158 |
// this.printJson(response, json.toString()); |
|
159 |
|
|
160 |
callBackMessage.sendErrorMessage("旧密码不正确!"); |
|
161 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
162 |
return; |
F |
163 |
} |
|
164 |
|
|
165 |
|
484907
|
166 |
|
a6a76f
|
167 |
if ( userAccountService.checkPasswordComplexity(passwordPlainText)) { |
176de8
|
168 |
// errJson.addProperty("pwd", "新密码过于简单,建议:数字+字母,请重新录入!"); |
F |
169 |
// json.add("error", errJson); |
|
170 |
// this.printJson(response, json.toString()); |
|
171 |
|
|
172 |
callBackMessage.sendErrorMessage("新密码过于简单,建议:数字+字母,请重新录入!"); |
|
173 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
174 |
return; |
F |
175 |
} |
484907
|
176 |
|
25115d
|
177 |
// if ( userAccountService.checkPasswordHistory(userCode, passwordPlainText)) { |
J |
178 |
// errJson.addProperty("pwd", "不能使用一年内使用过的密码!" ); |
|
179 |
// json.add("error", errJson); |
|
180 |
// this.printJson(response, json.toString()); |
|
181 |
// return; |
|
182 |
// } |
a6a76f
|
183 |
|
F |
184 |
|
176de8
|
185 |
// Set<Entry<String, JsonElement>> it = errJson.entrySet(); |
F |
186 |
// if (!it.isEmpty() && it.size() != 0) { |
|
187 |
// json.add("error", errJson); |
|
188 |
// this.printJson(response, json.toString()); |
|
189 |
// |
|
190 |
// return; |
|
191 |
// } |
|
192 |
// |
a6a76f
|
193 |
String password = ChangePassword.getEncryptPassword(passwordPlainText) ; |
F |
194 |
|
|
195 |
//保存新密码 |
484907
|
196 |
PwdBean pwdBean=new PwdBean(); |
F |
197 |
pwdBean.setTel(userAccount.getTel()); |
|
198 |
pwdBean.setNewPwd(password); |
|
199 |
JsonObject jsonObject = apiController.allInModifyUserPwd(pwdBean); |
|
200 |
success=jsonObject.get("status").getAsString(); |
a6a76f
|
201 |
}catch (DataAccessException e ) { |
F |
202 |
e.printStackTrace(); |
176de8
|
203 |
// success = "修改密码失败,原因:" + e.getCause().getMessage() ; |
F |
204 |
// JsonObject item = new JsonObject(); |
|
205 |
// item.addProperty("messagetxt",e.getCause().getMessage()); |
|
206 |
// array.add(item); |
|
207 |
// json.add("warning", array); |
|
208 |
// json.addProperty("success","修改密码失败" ); |
|
209 |
// |
|
210 |
// this.printJson(response, json.toString()); |
|
211 |
|
|
212 |
callBackMessage.sendErrorMessage("修改密码失败,原因:" + e.getCause().getMessage()); |
|
213 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
214 |
return ; |
F |
215 |
}catch (Exception e) { |
|
216 |
e.printStackTrace(); |
176de8
|
217 |
// success = "修改密码失败,原因:" + e.getMessage() ; |
F |
218 |
// JsonObject item = new JsonObject(); |
|
219 |
// item.addProperty("messagetxt",e.getMessage()); |
|
220 |
// array.add(item); |
|
221 |
// json.add("warning", array); |
|
222 |
// json.addProperty("success","修改密码失败" ); |
|
223 |
// this.printJson(response, json.toString()); |
|
224 |
|
|
225 |
callBackMessage.sendErrorMessage("修改密码失败,原因:" + e.getCause().getMessage()); |
|
226 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
227 |
return ; |
F |
228 |
}finally { |
|
229 |
SpObserver.setDBtoInstance(); |
|
230 |
} |
|
231 |
|
|
232 |
String redirect = hostUrl + "/password/changepwdsuccess.jsp"+(wxQueryString == null||"".equals(wxQueryString)?"":"?" + wxQueryString); |
176de8
|
233 |
// json.add("warning", array); |
F |
234 |
// json.addProperty("success",success ); |
|
235 |
// json.addProperty("redirect",redirect); |
|
236 |
|
|
237 |
callBackMessage.setMemo(success).setRedirect(redirect); |
|
238 |
callBackMessage.sendSuccessMessageByDefault(); |
|
239 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
240 |
return ; |
484907
|
241 |
|
a6a76f
|
242 |
} |
F |
243 |
|
|
244 |
/** |
|
245 |
* 管理员为用户修改随机密码 |
|
246 |
* @param request |
|
247 |
* @param response |
|
248 |
*/ |
|
249 |
@RequestMapping(params = "m=other") |
|
250 |
public void ChangeOtherPwd(HttpServletRequest request,HttpServletResponse response) { |
|
251 |
HttpSession session = request.getSession(); |
|
252 |
String formid = request.getParameter("formid"); |
|
253 |
CallBackMessage callBackMessage=new CallBackMessage(); |
|
254 |
if (formid == null) return; |
|
255 |
try { |
|
256 |
if (! ExecuteProcAction.hasPermisson( formid, request)) { |
176de8
|
257 |
this.printJson(response, callBackMessage.sendErrorMessage("抱歉!您没有执行" + formid + "功能号的权限.")); |
a6a76f
|
258 |
return; |
F |
259 |
} |
|
260 |
} catch (Exception e) { |
176de8
|
261 |
this.printJson(response, callBackMessage.sendErrorMessage("抱歉!您没有执行" + formid + "功能号的权限.")); |
a6a76f
|
262 |
return; |
F |
263 |
} |
|
264 |
|
|
265 |
String success = "" ; |
|
266 |
|
|
267 |
//String dbId = Maintaince.getDatabaseId(request); |
|
268 |
String userCode = null; |
|
269 |
Map<String,String> map = null ; |
|
270 |
try { |
|
271 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; |
|
272 |
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源 |
|
273 |
//获取 参数集 map |
|
274 |
map = t22ifc.getParamMap(request); |
|
275 |
}catch (Exception e) { |
|
276 |
e.printStackTrace(); |
176de8
|
277 |
this.printJson(response,callBackMessage.sendErrorMessage(e.getCause()!=null? e.getCause().getMessage():e.getMessage())); |
a6a76f
|
278 |
return ; |
F |
279 |
}finally { |
|
280 |
SpObserver.setDBtoInstance(); |
|
281 |
} |
|
282 |
|
|
283 |
try { |
|
284 |
if (map != null) { |
|
285 |
userCode = map.get("usercode") ; |
|
286 |
} |
|
287 |
}catch (Exception e) { |
|
288 |
e.printStackTrace(); |
|
289 |
success = "修改密码失败,原因:" +(e.getCause()!=null?e.getCause().getMessage(): e.getMessage()) ; |
176de8
|
290 |
this.printJson(response, callBackMessage.sendErrorMessage(success)); |
a6a76f
|
291 |
return ; |
F |
292 |
} |
484907
|
293 |
String enterCode = (session.getAttribute(SessionKey.HRCODE) == null ? "" : (String)session.getAttribute(SessionKey.HRCODE)); |
a6a76f
|
294 |
try { |
F |
295 |
|
|
296 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; |
|
297 |
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源 |
|
298 |
|
|
299 |
UserAccountEntity userAccount = userAccountService.getUserInfoByUserCode(userCode); |
|
300 |
if (userAccount == null) { |
176de8
|
301 |
this.printJson(response, callBackMessage.sendErrorMessage(" 用户[" + userCode + "]不存在或已被停用,不允许修改密码[dbid:" +dataSourceEntity.getDbId() +"] !")); |
a6a76f
|
302 |
return; |
F |
303 |
} |
|
304 |
String randomPassword = ChangePassword.getRandomPlainText() ; |
|
305 |
boolean hasUsed = userAccountService.checkPasswordHistory(userCode, randomPassword) ; |
|
306 |
|
|
307 |
//用循环的目的是防止生成 1 年内使用过的重复密码 |
|
308 |
while (true) { |
|
309 |
if (hasUsed) { |
|
310 |
randomPassword = ChangePassword.getRandomPlainText() ; |
|
311 |
hasUsed = userAccountService.checkPasswordHistory(userCode, randomPassword) ; |
|
312 |
continue ; |
|
313 |
}else { |
484907
|
314 |
String result=null; |
a6a76f
|
315 |
String password = ChangePassword.getEncryptPassword( randomPassword) ; |
F |
316 |
//保存新密码 |
484907
|
317 |
PwdBean pwdBean=new PwdBean(); |
F |
318 |
pwdBean.setTel(userAccount.getTel()); |
|
319 |
pwdBean.setNewPwd(password); |
|
320 |
JsonObject jsonObject = apiController.allInModifyUserPwd(pwdBean); |
|
321 |
result=jsonObject.get("status").getAsString(); |
|
322 |
if (result!=null) { |
a6a76f
|
323 |
success = "用户【"+userAccount.getUserName()+"】密码修改成功,请记住新密码【"+randomPassword + "】"; |
F |
324 |
} else { |
|
325 |
success = "用户【"+userAccount.getUserName()+"】密码修改失败!" ; |
|
326 |
} |
|
327 |
break ; |
|
328 |
} |
|
329 |
|
|
330 |
} |
176de8
|
331 |
callBackMessage.setMemo(success); |
F |
332 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
333 |
return ; |
484907
|
334 |
|
a6a76f
|
335 |
}catch (DataAccessException e ) { |
F |
336 |
e.printStackTrace(); |
|
337 |
success = callBackMessage.sendErrorMessage("修改密码失败,原因:" + e.getCause()!=null? e.getCause().getMessage():e.getMessage() ); |
176de8
|
338 |
this.printJson(response, success); |
a6a76f
|
339 |
return ; |
F |
340 |
}catch (Exception e) { |
|
341 |
e.printStackTrace(); |
|
342 |
success = callBackMessage.sendErrorMessage("修改密码失败,原因:" +e.getCause()!=null? e.getCause().getMessage():e.getMessage() ); |
176de8
|
343 |
this.printJson(response, success); |
a6a76f
|
344 |
return ; |
F |
345 |
}finally { |
|
346 |
SpObserver.setDBtoInstance(); |
|
347 |
} |
|
348 |
|
|
349 |
} |
|
350 |
|
|
351 |
/** |
|
352 |
* 将密码明文改为密文 |
|
353 |
* @param request |
|
354 |
* @param response |
|
355 |
*/ |
|
356 |
@RequestMapping(params = "m=encryptpwd") |
|
357 |
public void ChangePlainTextToPwd(HttpServletRequest request,HttpServletResponse response) { |
|
358 |
HttpSession session = request.getSession(); |
|
359 |
String enterCode = request.getParameter("usercode") ; |
|
360 |
demoMap.clear(); |
|
361 |
if (enterCode == null && session.getAttribute(SessionKey.USERCODE) != null) { |
|
362 |
enterCode = (String)session.getAttribute(SessionKey.USERCODE) ; |
|
363 |
} |
|
364 |
if (enterCode == null && session.getAttribute(SessionKey.HRCODE)!=null ) { |
|
365 |
enterCode = (String)session.getAttribute(SessionKey.HRCODE) ; |
|
366 |
} |
176de8
|
367 |
CallBackMessage callBackMessage=new CallBackMessage(); |
a6a76f
|
368 |
String success = "" ; |
F |
369 |
try { |
|
370 |
boolean isContinue = true ; |
|
371 |
while (isContinue ) { |
|
372 |
DataSourceEntity dataSourceEntity = getDbSource() ; |
|
373 |
|
|
374 |
if (dataSourceEntity == null) { |
|
375 |
isContinue = false ; |
|
376 |
break ; |
|
377 |
} |
|
378 |
|
|
379 |
try { |
|
380 |
SpObserver.setDBtoInstance("_"+ dataSourceEntity.getDbId());//切换数据源 |
|
381 |
int changeSuccess = 0 ; |
|
382 |
List<UserAccountEntity> userList = userAccountService.getUserInfos() ; |
|
383 |
for (int i = 0 ;userList != null && i < userList.size();i++) { |
|
384 |
UserAccountEntity userAccount = userList.get(i) ; |
|
385 |
|
|
386 |
//密码长度小于 30 位的则认为是没有加密的密码 |
|
387 |
if (userAccount != null && userAccount.getPassword()!= null |
|
388 |
&& userAccount.getPassword().length()<30 && ChangePassword.isEncryptPassword) { |
|
389 |
String password = ChangePassword.getEncryptPassword(userAccount.getPassword()) ; |
|
390 |
//保存新密码 |
484907
|
391 |
PwdBean pwdBean=new PwdBean(); |
F |
392 |
pwdBean.setTel(userAccount.getTel()); |
|
393 |
pwdBean.setNewPwd(password); |
|
394 |
JsonObject jsonObject = apiController.allInModifyUserPwd(pwdBean); |
|
395 |
String result=jsonObject.get("status").getAsString(); |
|
396 |
if (result!=null) { |
a6a76f
|
397 |
changeSuccess ++ ; |
F |
398 |
}else{ |
|
399 |
success += "<br/>数据源id为" +dataSourceEntity.getDbId()+"【" + dataSourceEntity.getSystemID() +"】,用户【"+userAccount.getUserName()+"】密码加密失败"; |
|
400 |
} |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
success += "<br/>数据源id为" +dataSourceEntity.getDbId()+"【" + dataSourceEntity.getSystemID() +"】,共有 " + (userList != null?userList.size():0) + "个用户,已成功加密"+ changeSuccess + " 个用户" ; |
|
405 |
|
|
406 |
}catch(Exception e){ |
|
407 |
e.printStackTrace(); |
|
408 |
success += "<br/>正在更新数据源id为" +dataSourceEntity.getDbId()+"【" + dataSourceEntity.getSystemID() + |
|
409 |
"】账号密码加密时出错( ChangePassword )," + this.getClass()+",错误消息为:"+ (e.getCause() !=null?e.getCause().getMessage(): e.getMessage()); |
176de8
|
410 |
this.printJson(response, callBackMessage.sendErrorMessage(success)); |
a6a76f
|
411 |
return ; |
F |
412 |
}finally { |
|
413 |
SpObserver.setDBtoInstance(); |
|
414 |
} |
|
415 |
} |
|
416 |
}catch(Exception e) { |
|
417 |
e.printStackTrace(); |
|
418 |
success += "<br/>修改密码失败,原因:" + e.getMessage() ; |
176de8
|
419 |
this.printJson(response, callBackMessage.sendErrorMessage(success)); |
a6a76f
|
420 |
return ; |
F |
421 |
} |
|
422 |
|
|
423 |
try { |
|
424 |
demoMap.clear(); |
|
425 |
SpObserver.setDBtoDemo();//切换数据源 |
|
426 |
boolean isContinue = true ; |
|
427 |
while (isContinue ) { |
|
428 |
DataSourceEntity dataSourceEntity = getDbSource() ; |
|
429 |
|
|
430 |
if (dataSourceEntity == null) { |
|
431 |
isContinue = false ; |
|
432 |
break ; |
|
433 |
} |
|
434 |
if (dataSourceEntity.getPassword()!=null && dataSourceEntity.getPassword().length() < 30) { |
|
435 |
String password = ChangePassword.getEncryptPassword(dataSourceEntity.getPassword()) ; //加密密码 |
|
436 |
dataSourceEntity.setPassword(password); |
|
437 |
demoIfc.updateDemo( dataSourceEntity) ; |
|
438 |
} |
|
439 |
|
|
440 |
} |
|
441 |
String sql = " set nocount on ; select UserId,Password from gProfile " ; |
|
442 |
BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); |
|
443 |
List<Map<String,Object>> list = baseService.getSimpleJdbcTemplate().queryForList(sql) ; |
|
444 |
for (int i = 0 ;list != null && i < list.size();i++) { |
|
445 |
Integer userId = (Integer) list.get(i).get("UserId") ; |
|
446 |
String pwd = (String) list.get(i).get("Password") ; |
|
447 |
|
|
448 |
if (pwd != null && pwd.length() < 30) { |
|
449 |
String password = ChangePassword.getEncryptPassword(pwd) ; //加密密码 |
|
450 |
String sql2 = "set nocount on ; update gProfile set password=? where UserId=?;select @@rowcount;"; |
|
451 |
|
|
452 |
int result = baseService.getSimpleJdbcTemplate().queryForObject(sql2, Integer.class, password,userId); |
|
453 |
} |
|
454 |
} |
|
455 |
|
|
456 |
|
|
457 |
}catch(Exception e) { |
|
458 |
e.printStackTrace(); |
|
459 |
success += "<br/>加密密码失败,原因:" + e.getMessage() ; |
176de8
|
460 |
this.printJson(response, callBackMessage.sendErrorMessage(success)); |
a6a76f
|
461 |
return ; |
F |
462 |
}finally { |
|
463 |
SpObserver.setDBtoInstance(); |
|
464 |
} |
176de8
|
465 |
callBackMessage.setMemo(success).sendSuccessMessageByDefault(); |
F |
466 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
467 |
return ; |
F |
468 |
|
|
469 |
} |
|
470 |
|
|
471 |
/** |
|
472 |
* 将密码密文改为明文 |
|
473 |
* @param request |
|
474 |
* @param response |
|
475 |
*/ |
|
476 |
@RequestMapping(params = "m=decryptpwd") |
|
477 |
public void ChangePwdToPlainText(HttpServletRequest request,HttpServletResponse response) { |
|
478 |
HttpSession session = request.getSession(); |
|
479 |
String enterCode = request.getParameter("usercode") ; |
|
480 |
demoMap.clear(); |
|
481 |
if (enterCode == null && session.getAttribute(SessionKey.USERCODE) != null) { |
|
482 |
enterCode = (String)session.getAttribute(SessionKey.USERCODE) ; |
|
483 |
} |
|
484 |
if (enterCode == null && session.getAttribute(SessionKey.HRCODE)!=null ) { |
|
485 |
enterCode = (String)session.getAttribute(SessionKey.HRCODE) ; |
|
486 |
} |
|
487 |
|
|
488 |
String success = "" ; |
176de8
|
489 |
CallBackMessage callBackMessage=new CallBackMessage(); |
a6a76f
|
490 |
try { |
F |
491 |
boolean isContinue = true ; |
|
492 |
while (isContinue ) { |
|
493 |
DataSourceEntity dataSourceEntity = getDbSource() ; |
|
494 |
|
|
495 |
if (dataSourceEntity == null) { |
|
496 |
isContinue = false ; |
|
497 |
break ; |
|
498 |
} |
|
499 |
|
|
500 |
try { |
|
501 |
SpObserver.setDBtoInstance("_"+ dataSourceEntity.getDbId());//切换数据源 |
|
502 |
int changeSuccess = 0 ; |
|
503 |
List<UserAccountEntity> userList = userAccountService.getUserInfos() ; |
|
504 |
for (int i = 0 ;userList != null && i < userList.size();i++) { |
|
505 |
UserAccountEntity userAccount = userList.get(i) ; |
|
506 |
|
|
507 |
//密码长度大于 30 位的则认为是加密的密码 |
|
508 |
if (userAccount != null && userAccount.getPassword()!= null |
|
509 |
&& userAccount.getPassword().length()>30 && ChangePassword.isEncryptPassword) { |
|
510 |
try { |
|
511 |
String password = ChangePassword.getDecryptPassword(userAccount.getPassword()) ; //还原密码为明文 |
|
512 |
//保存新密码 |
484907
|
513 |
PwdBean pwdBean=new PwdBean(); |
F |
514 |
pwdBean.setTel(userAccount.getTel()); |
|
515 |
pwdBean.setNewPwd(password); |
|
516 |
JsonObject jsonObject = apiController.allInModifyUserPwd(pwdBean); |
|
517 |
String result=jsonObject.get("status").getAsString(); |
|
518 |
if (result!=null) { |
a6a76f
|
519 |
changeSuccess ++ ; |
F |
520 |
}else{ |
|
521 |
success += "<br/>数据源id为" +dataSourceEntity.getDbId()+"【" + dataSourceEntity.getSystemID() +"】,用户【"+userAccount.getUserName()+"】密码加密失败"; |
|
522 |
} |
|
523 |
}catch(Exception e) { |
|
524 |
System.out.println("解密用户密码出错了,用户名:"+ userAccount.getUserCode()); |
|
525 |
throw e ; |
|
526 |
} |
|
527 |
} |
|
528 |
} |
|
529 |
|
|
530 |
success += "<br/>数据源id为" +dataSourceEntity.getDbId()+"【" + dataSourceEntity.getSystemID() +"】,共有 " + (userList != null?userList.size():0) + "个用户,已成功解密"+ changeSuccess + " 个用户" ; |
|
531 |
|
|
532 |
}catch(Exception e){ |
|
533 |
e.printStackTrace(); |
|
534 |
success += "<br/>正在更新数据源id为" +dataSourceEntity.getDbId()+"【" + dataSourceEntity.getSystemID() + |
|
535 |
"】账号密码解密时出错( ChangePassword )," + this.getClass()+",错误消息为:"+e.getMessage(); |
176de8
|
536 |
this.printJson(response, callBackMessage.sendErrorMessage(success)); |
a6a76f
|
537 |
return ; |
F |
538 |
}finally { |
|
539 |
SpObserver.setDBtoInstance(); |
|
540 |
} |
|
541 |
} |
|
542 |
}catch(Exception e) { |
|
543 |
e.printStackTrace(); |
|
544 |
success += "<br/>修改密码失败,原因:" + e.getMessage() ; |
176de8
|
545 |
this.printJson(response, callBackMessage.sendErrorMessage(success)); |
a6a76f
|
546 |
return ; |
F |
547 |
} |
|
548 |
try { |
|
549 |
demoMap.clear(); |
|
550 |
SpObserver.setDBtoDemo();//切换数据源 |
|
551 |
boolean isContinue = true ; |
|
552 |
while (isContinue ) { |
|
553 |
DataSourceEntity dataSourceEntity = getDbSource() ; |
|
554 |
|
|
555 |
if (dataSourceEntity == null) { |
|
556 |
isContinue = false ; |
|
557 |
break ; |
|
558 |
} |
|
559 |
if (dataSourceEntity.getPassword()!=null && dataSourceEntity.getPassword().length() > 30) { |
|
560 |
String password = ChangePassword.getDecryptPassword(dataSourceEntity.getPassword()) ; //还原密码为明文 |
|
561 |
dataSourceEntity.setPassword(password); |
|
562 |
demoIfc.updateDemo( dataSourceEntity) ; |
|
563 |
} |
|
564 |
|
|
565 |
} |
|
566 |
String sql = " set nocount on ; select UserId,Password from gProfile " ; |
|
567 |
BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); |
|
568 |
List<Map<String,Object>> list = baseService.getSimpleJdbcTemplate().queryForList(sql) ; |
|
569 |
for (int i = 0 ;list != null && i < list.size();i++) { |
|
570 |
Integer userId = (Integer) list.get(i).get("UserId") ; |
|
571 |
String pwd = (String) list.get(i).get("Password") ; |
|
572 |
|
|
573 |
if (pwd != null && pwd.length() > 30) { |
|
574 |
String password = ChangePassword.getDecryptPassword(pwd) ; //还原密码为明文 |
|
575 |
String sql2 = "set nocount on ; update gProfile set password=? where UserId=?;select @@rowcount;"; |
|
576 |
|
|
577 |
int result = baseService.getSimpleJdbcTemplate().queryForObject(sql2, Integer.class, password,userId); |
|
578 |
} |
|
579 |
} |
|
580 |
|
|
581 |
|
|
582 |
}catch(Exception e) { |
|
583 |
e.printStackTrace(); |
|
584 |
success += "<br/>修改密码失败,原因:" + e.getMessage() ; |
176de8
|
585 |
this.printJson(response, callBackMessage.sendErrorMessage(success)); |
a6a76f
|
586 |
return ; |
F |
587 |
}finally { |
|
588 |
SpObserver.setDBtoInstance(); |
|
589 |
} |
176de8
|
590 |
callBackMessage.setMemo(success).sendSuccessMessageByDefault(); |
F |
591 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
592 |
return ; |
F |
593 |
|
|
594 |
} |
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
/** |
|
599 |
* 同步取数据源 |
|
600 |
* @return |
|
601 |
*/ |
|
602 |
synchronized public DataSourceEntity getDbSource() { |
|
603 |
if (demoList == null || demoList.size() == 0) { |
|
604 |
return null ; |
|
605 |
} |
|
606 |
for (Map.Entry<String, DataSourceEntity> entry : demoList.entrySet()) { |
|
607 |
DataSourceEntity dataSourceEntity = entry.getValue(); |
|
608 |
|
|
609 |
|
|
610 |
if (demoMap.get(dataSourceEntity.getDbId()+"") != null ) { |
|
611 |
continue ; |
|
612 |
}else { |
|
613 |
demoMap.put(dataSourceEntity.getDbId()+"",dataSourceEntity.getDbId()) ; |
|
614 |
return dataSourceEntity; |
|
615 |
|
|
616 |
} |
|
617 |
} |
|
618 |
|
|
619 |
return null ; |
|
620 |
} |
|
621 |
/** |
|
622 |
* 切换成userid指定的用户,作自动登录,用作查看用户权限设置是否正确之用 |
|
623 |
* @param request |
|
624 |
* @param response |
|
625 |
*/ |
|
626 |
@RequestMapping(params = "m=changeID") |
|
627 |
public void Change2OtherUserID(HttpServletRequest request,HttpServletResponse response) { |
|
628 |
HttpSession session = request.getSession(); |
|
629 |
JsonObject json = new JsonObject(); |
|
630 |
JsonObject errJson = new JsonObject(); |
|
631 |
String usercode=request.getParameter("param"); |
176de8
|
632 |
CallBackMessage callBackMessage=new CallBackMessage(); |
a6a76f
|
633 |
try { |
F |
634 |
|
|
635 |
String dbid=(String) session.getAttribute(SessionKey.DATA_BASE_ID); |
|
636 |
SpObserver.setDBtoInstance("_"+dbid); |
|
637 |
if ("".equals(usercode) ){ |
176de8
|
638 |
// errJson.addProperty("userid"," 用户id不能为空!") ; |
F |
639 |
// json.add("error", errJson); |
|
640 |
// this.printJson(response, json.toString()); |
|
641 |
|
|
642 |
this.printJson(response, callBackMessage.sendErrorMessage(" 用户id不能为空!")); |
a6a76f
|
643 |
return; |
F |
644 |
} |
|
645 |
//调用登录接口 |
|
646 |
request.setAttribute("isch_userid", true); |
|
647 |
request.setAttribute("account", usercode); |
|
648 |
request.setAttribute("dataName", dbid); |
|
649 |
request.setAttribute("isone", dbid); |
|
650 |
LoginAction login=(LoginAction) FactoryBean.getBean("loginAction"); |
|
651 |
String info=login.login(request, response); |
176de8
|
652 |
callBackMessage.setMemo(info); |
F |
653 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
654 |
}finally { |
F |
655 |
SpObserver.setDBtoInstance(); |
|
656 |
} |
|
657 |
} |
|
658 |
} |