|
|
|
@ -62,28 +62,24 @@ public class LoginController {
|
|
|
|
|
return "loginDir/login";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "login", method = RequestMethod.POST)
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public Msg login(Power_User powerUser, HttpServletResponse response, HttpServletRequest request, Model model) throws Exception {
|
|
|
|
|
Jedis redis = JedisPoolUtil.getJedisPoolInstance().getResource();
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
String userPwd = powerUser.getUserPwd();
|
|
|
|
|
String userName = powerUser.getUserName();
|
|
|
|
|
String userInfo = redis.get(userName);
|
|
|
|
|
//用来记录错误的次数
|
|
|
|
|
String errorPwsCount = "0";
|
|
|
|
|
//没有这个id的话新建一个
|
|
|
|
|
if (userInfo == null) {
|
|
|
|
|
redis.set(userName, errorPwsCount);
|
|
|
|
|
}
|
|
|
|
|
//获取已经记录错误次数
|
|
|
|
|
int i = Integer.parseInt(redis.get(userName));
|
|
|
|
|
//小于5可以继续登录,大于5
|
|
|
|
|
if (i < 5) {
|
|
|
|
|
//判断是否在可登录时间内
|
|
|
|
|
Power_Log unlockDate = logService.getUnlockDate(powerUser.getUserName());
|
|
|
|
|
//不等于空说明账号次数过多被锁定
|
|
|
|
|
if (unlockDate!=null){
|
|
|
|
|
return Msg.failUnlockUser(unlockDate.getUnlockDate());
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
Power_UserVo user = powerUserService.findPowerUserByUserNameAndUserPwd(powerUser);
|
|
|
|
|
//添加进操作日志
|
|
|
|
|
Power_Log log = new Power_Log();
|
|
|
|
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
if (user != null) {
|
|
|
|
|
//如处于登录状态,先清除缓存
|
|
|
|
|
//CacheManager.removeCacheByObject(user);
|
|
|
|
@ -99,7 +95,6 @@ public class LoginController {
|
|
|
|
|
String token = UUID.randomUUID().toString();
|
|
|
|
|
ActionScopeUtils.setSessionAttribute("token", token, Integer.valueOf(String.valueOf(TOKEN_EXPIRE_TIME)) / 1000);
|
|
|
|
|
//设置用户登录次数缓存
|
|
|
|
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
CacheManager.addloginUserCount(fmt.format(new Date()), user.getUserName());
|
|
|
|
|
CacheManager.addExcCount("noExc");
|
|
|
|
|
List<Power_Menu> list = null;
|
|
|
|
@ -137,6 +132,15 @@ public class LoginController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
user.setRemark(power_depts.toString());
|
|
|
|
|
StringBuilder powerCodes= new StringBuilder();
|
|
|
|
|
for (int c = 0; c < power_depts1.size(); c++) {
|
|
|
|
|
if (c < power_depts1.size() - 1) {
|
|
|
|
|
powerCodes.append(power_depts1.get(c).getDeptCode()).append(",");
|
|
|
|
|
} else {
|
|
|
|
|
powerCodes.append(power_depts1.get(c).getDeptCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
user.setUserTel(powerCodes.toString());
|
|
|
|
|
StringBuilder power_depts3 = new StringBuilder();
|
|
|
|
|
if (user.getDeptIdQuality() != null) {
|
|
|
|
|
List<Power_Dept> power_depts2 = power_deptService.selectByPrimaryKeys(user.getDeptIdQuality());
|
|
|
|
@ -154,8 +158,6 @@ public class LoginController {
|
|
|
|
|
ActionScopeUtils.setSessionAttribute("CURRENT_USER", user, Integer.valueOf(String.valueOf(TOKEN_EXPIRE_TIME)) / 1000);
|
|
|
|
|
String reg = "^(?![A-Za-z]+$)(?![A-Z\\d]+$)(?![A-Z\\W]+$)(?![a-z\\d]+$)(?![a-z\\W]+$)(?![\\d\\W]+$)\\S{8,20}$";
|
|
|
|
|
boolean msg = userPwd.matches(reg);
|
|
|
|
|
redis.del(userName);
|
|
|
|
|
JedisPoolUtil.close(redis);
|
|
|
|
|
if (msg == false) {
|
|
|
|
|
String url = "http://" + SERVER_IP + ":" + SERVER_PORT + "/power" + "/font/updatePassword";
|
|
|
|
|
return Msg.success().add("url", url);
|
|
|
|
@ -180,10 +182,13 @@ public class LoginController {
|
|
|
|
|
log.setLogTitle("登录");
|
|
|
|
|
log.setLogContent("用户密码错误");
|
|
|
|
|
log.setRemark("已错误【" + wrongNum + "】次");
|
|
|
|
|
//如果错误次数=5添加锁定时间
|
|
|
|
|
if (wrongNum == 5) {
|
|
|
|
|
SimpleDateFormat UnlockFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
log.setUnlockDate(UnlockFmt.format(new Date().getTime()+ 15*60*1000));
|
|
|
|
|
}
|
|
|
|
|
logService.insert(log);
|
|
|
|
|
request.setAttribute("msg", "用户名或密码不正确");
|
|
|
|
|
redis.incr(userName);
|
|
|
|
|
JedisPoolUtil.close(redis);
|
|
|
|
|
return Msg.failUser();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -191,30 +196,15 @@ public class LoginController {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
CacheManager.addExcCount("exc");
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
//失败次数大于五时锁十五分钟
|
|
|
|
|
redis.setex(userName, 900, i + "");
|
|
|
|
|
JedisPoolUtil.close(redis);
|
|
|
|
|
return Msg.failUser2();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}finally {
|
|
|
|
|
JedisPoolUtil.close(redis);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping("refuse")
|
|
|
|
|
public String refuse() {
|
|
|
|
|
return "refuse";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取session所剩时间
|
|
|
|
|
@RequestMapping(value = "getSessionRemainingTime", method = RequestMethod.GET, produces = {"text/json;charset=UTF-8"})
|
|
|
|
|
@ResponseBody
|
|
|
|
|