|
|
@@ -116,26 +116,27 @@ public class UserController {
|
|
|
|
|
|
/**
|
|
|
* 修改用户密码
|
|
|
- *
|
|
|
- * @param password 用户输入密码
|
|
|
+ * @param session 获取session
|
|
|
+ * @param password 旧密码
|
|
|
+ * @param newPassword 新密码
|
|
|
+ * @param secLevel 密码强度
|
|
|
+ * @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
|
|
|
- public ResponseEntity<String> updatePassword(final HttpSession session, final String password, final String newPassword,final Short secLevel) {
|
|
|
+ public ResponseEntity<String> updatePassword(final HttpSession session, final String password, final String newPassword, final Short secLevel) {
|
|
|
if (password.equals(newPassword)) {
|
|
|
throw new IllegalOperatorException("新密码与旧密码相同");
|
|
|
}
|
|
|
- if(newPassword.length()<8 || newPassword.matches("^[0-9]*$") || newPassword.matches("^[A-Za-z]*$")){
|
|
|
- throw new IllegalOperatorException("密码强度不够,请重新输入");
|
|
|
- }
|
|
|
- if(newPassword.length()>20){
|
|
|
- throw new IllegalOperatorException("密码超过20位,请重新输入");
|
|
|
+ String middlLevelReg = "^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$";
|
|
|
+ if (!newPassword.matches(middlLevelReg)) {
|
|
|
+ throw new IllegalOperatorException("密码格式有误,请重新输入");
|
|
|
}
|
|
|
User sysUser = SystemSession.getUser();
|
|
|
User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
|
|
|
if (!StringUtils.isEmpty(newPassword)) {
|
|
|
user.setPwdSecLevel(secLevel);
|
|
|
user = userService.updatePassword(user, password, newPassword);
|
|
|
- if(sysUser.getEnterprise()!=null){
|
|
|
+ if (sysUser.getEnterprise() != null) {
|
|
|
user.setCurrentEnterprise(sysUser.getEnterprise().getUu());
|
|
|
}
|
|
|
session.setAttribute("user", user);
|
|
|
@@ -176,7 +177,7 @@ public class UserController {
|
|
|
User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
|
|
|
Long checkTime = (Long)session.getAttribute("checkTime");
|
|
|
if (!StringUtils.isEmpty(checkTime)){
|
|
|
- Long nowTime = new Date().getTime();
|
|
|
+ Long nowTime = System.currentTimeMillis();
|
|
|
if((nowTime-checkTime)<60 * 1000){
|
|
|
throw new IllegalOperatorException("验证码发送频繁...");
|
|
|
}
|
|
|
@@ -186,14 +187,14 @@ public class UserController {
|
|
|
if (pageToken == null || pageToken.equals("")) {
|
|
|
throw new IllegalOperatorException("页面信息获取失败!");
|
|
|
}
|
|
|
- //发送邮件
|
|
|
+ // 发送邮件
|
|
|
ModelMap data = new ModelMap();
|
|
|
String checkCode = String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
|
|
|
data.put("checkcode", checkCode);
|
|
|
try {
|
|
|
mailService.send("a4c45a22-436a-430c-9667-4edfd7d04a27", newUserEmail, data);
|
|
|
session.setAttribute("checkCode", checkCode);
|
|
|
- session.setAttribute("checkTime", new Date().getTime());
|
|
|
+ session.setAttribute("checkTime", System.currentTimeMillis());
|
|
|
session.setAttribute("newUserEmail",newUserEmail);
|
|
|
assert logger != null;
|
|
|
logger.log("用户信息", "发送用户邮箱地址,UU:" + user.getUserUU());
|
|
|
@@ -217,22 +218,22 @@ public class UserController {
|
|
|
Map<String,Object> result = new HashMap<String,Object>();
|
|
|
if (!StringUtils.isEmpty(checkCode) && !StringUtils.isEmpty(newUserEmail)) {
|
|
|
Long checkTime = (Long) session.getAttribute("checkTime");
|
|
|
- Long nowTime = new Date().getTime();
|
|
|
+ Long nowTime = System.currentTimeMillis();
|
|
|
String _checkCode = (String) session.getAttribute("checkCode");
|
|
|
String _newUserEmail = (String) session.getAttribute("newUserEmail");
|
|
|
- //验证码失效
|
|
|
+ // 验证码失效
|
|
|
if((nowTime-checkTime)>10 * 60 * 1000 || _checkCode == null) {
|
|
|
result.put("status", 2);
|
|
|
result.put("message", "验证码失效");
|
|
|
return result;
|
|
|
}
|
|
|
- //验证码错误
|
|
|
+ // 验证码错误
|
|
|
if (!_checkCode.equals(checkCode) || !_newUserEmail.equals(newUserEmail)) {
|
|
|
result.put("status", 0);
|
|
|
result.put("message", "验证码错误");
|
|
|
return result;
|
|
|
}
|
|
|
- //验证码正确
|
|
|
+ // 验证码正确
|
|
|
if (_checkCode.equals(checkCode)) {
|
|
|
result.put("status", 1);
|
|
|
result.put("message", "验证码正确");
|
|
|
@@ -256,7 +257,7 @@ public class UserController {
|
|
|
if (userEmail!=null && userEmail.equals(newUserEmail)) {
|
|
|
throw new IllegalOperatorException("新邮箱地址与旧邮箱地址相同");
|
|
|
}
|
|
|
- //正则校验邮箱地址
|
|
|
+ // 正则校验邮箱地址
|
|
|
if(!newUserEmail.matches("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+")){
|
|
|
throw new IllegalOperatorException("新邮箱地址格式不正确");
|
|
|
}
|
|
|
@@ -322,13 +323,13 @@ public class UserController {
|
|
|
User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
|
|
|
Long checkTime = (Long)session.getAttribute("telCheckTime");
|
|
|
if (!StringUtils.isEmpty(checkTime)){
|
|
|
- Long nowTime = new Date().getTime();
|
|
|
+ Long nowTime = System.currentTimeMillis();
|
|
|
if((nowTime-checkTime)<60 * 1000){
|
|
|
throw new IllegalOperatorException("验证码发送频繁...");
|
|
|
}
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(newUserTel)) {
|
|
|
- //页面Token校验
|
|
|
+ // 页面Token校验
|
|
|
String pageToken = (String) session.getAttribute("pageToken");
|
|
|
if (pageToken == null || pageToken.equals("")) {
|
|
|
throw new IllegalOperatorException("页面信息获取失败!");
|
|
|
@@ -337,7 +338,7 @@ public class UserController {
|
|
|
try {
|
|
|
smsService.send("1eba04ae-f3d9-4105-ad32-0196309fabb3", newUserTel, new Object[] {checkCode});
|
|
|
session.setAttribute("telCheckCode", checkCode);
|
|
|
- session.setAttribute("telCheckTime", new Date().getTime());
|
|
|
+ session.setAttribute("telCheckTime", System.currentTimeMillis());
|
|
|
session.setAttribute("newUserTel", newUserTel);
|
|
|
assert logger != null;
|
|
|
logger.log("用户信息", "发送手机验证码,UU:" + user.getUserUU());
|
|
|
@@ -360,22 +361,22 @@ public class UserController {
|
|
|
Map<String, Object> result = new HashMap<String, Object>();
|
|
|
if (!StringUtils.isEmpty(telCheckCode) && !StringUtils.isEmpty(newUserTel)) {
|
|
|
Long checkTime = (Long) session.getAttribute("telCheckTime");
|
|
|
- Long nowTime = new Date().getTime();
|
|
|
+ Long nowTime = System.currentTimeMillis();
|
|
|
String _checkCode = (String) session.getAttribute("telCheckCode");
|
|
|
String _newUserTel = (String) session.getAttribute("newUserTel");
|
|
|
- //验证码失效
|
|
|
+ // 验证码失效
|
|
|
if ((nowTime - checkTime) > 10 * 60 * 1000 || _checkCode == null) {
|
|
|
result.put("status", 2);
|
|
|
result.put("message", "验证码失效");
|
|
|
return result;
|
|
|
}
|
|
|
- //验证码错误
|
|
|
+ // 验证码错误
|
|
|
if (!_checkCode.equals(telCheckCode) || !_newUserTel.equals(newUserTel)) {
|
|
|
result.put("status",0);
|
|
|
result.put("message", "验证码错误");
|
|
|
return result;
|
|
|
}
|
|
|
- //验证码正确
|
|
|
+ // 验证码正确
|
|
|
if (_checkCode.equals(telCheckCode)) {
|
|
|
result.put("status", 1);
|
|
|
result.put("message", "验证码正确");
|
|
|
@@ -399,11 +400,11 @@ public class UserController {
|
|
|
if (userTel.equals(newUserTel)) {
|
|
|
throw new IllegalOperatorException("新手机号与旧手机号相同");
|
|
|
}
|
|
|
- //手机号码正则表达式校验
|
|
|
+ // 手机号码正则表达式校验
|
|
|
if(!newUserTel.matches("^[0-9]{8,11}$")){
|
|
|
throw new IllegalOperatorException("新手机号格式不正确...");
|
|
|
}
|
|
|
- //防止用户非法操作
|
|
|
+ // 防止用户非法操作
|
|
|
String _checkCode = (String) session.getAttribute("telCheckCode");
|
|
|
if(!_checkCode.equals(telCheckCode)){
|
|
|
throw new IllegalOperatorException("验证码错误");
|
|
|
@@ -418,6 +419,7 @@ public class UserController {
|
|
|
if (!userService.isTelUseable(newUserTel)) {
|
|
|
throw new IllegalOperatorException("手机号不可用...");
|
|
|
}
|
|
|
+ user.setUserTel(newUserTel);
|
|
|
user = userService.updateUserTel(userTel,newUserTel,user.getUserUU());
|
|
|
if(sysUser.getEnterprise()!=null){
|
|
|
user.setCurrentEnterprise(sysUser.getEnterprise().getUu());
|
|
|
@@ -481,7 +483,7 @@ public class UserController {
|
|
|
if (userPay != null && userPay.equals(newUserPay)) {
|
|
|
throw new IllegalOperatorException("新密码与旧密码相同");
|
|
|
}
|
|
|
- //新密码正则校验
|
|
|
+ // 新密码正则校验
|
|
|
if(!newUserPay.matches("^\\d{6}$")){
|
|
|
throw new IllegalOperatorException("新密码格式不正确...");
|
|
|
}
|