Commit 239c0628 by java-李谡

添加redis方法

parent 524509ec
...@@ -146,21 +146,23 @@ public class UserController { ...@@ -146,21 +146,23 @@ public class UserController {
LoginBean loginBean = requestBean.getObjectBean(LoginBean.class); LoginBean loginBean = requestBean.getObjectBean(LoginBean.class);
String message = userService.validate(loginBean); String message = userService.validate(loginBean);
String userIp = StringUtils.isEmpty(loginBean.getClientip()) ? Util.getOnlineIP(request) : loginBean.getClientip(); String userIp = StringUtils.isEmpty(loginBean.getClientip()) ? Util.getOnlineIP(request) : loginBean.getClientip();
LOG.debug("[UserController login IP]" + userIp); System.out.println("[UserController login IP]" + userIp);
if (message == null) { if (message == null) {
LoginIpInfo loginIpInfo = userService.findByIp(userIp); LoginIpInfo loginIpInfo = userService.findByIp(userIp);
String redisUsername = redisUtils.get(loginBean.getLoginName(), indexDb); String redisUsername = redisUtils.get(loginBean.getLoginName(), indexDb);
if (loginIpInfo != null) { if (loginIpInfo != null) {
responseBean.setStatus(ErrorCode.STATUS_CODE_4102); responseBean.setStatus(ErrorCode.STATUS_CODE_4102);
System.out.println("IP地址已被锁定");
responseBean.setMessage("IP地址已被锁定"); responseBean.setMessage("IP地址已被锁定");
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4102]总共用时:" + Util.getDurationTime(duration)); System.out.println("[UserController login][STATUS_CODE_4102]总共用时:" + Util.getDurationTime(duration));
return responseBean; return responseBean;
} }
String blackUsername = redisUtils.get("black_username:" + loginBean.getLoginName(), indexDb); String blackUsername = redisUtils.get("black_username:" + loginBean.getLoginName(), indexDb);
boolean sealup = false; boolean sealup = false;
if (null != redisUsername && Integer.parseInt(redisUsername) >= 5 && StringUtils.isEmpty(blackUsername)) { if (null != redisUsername && Integer.parseInt(redisUsername) >= 5 && StringUtils.isEmpty(blackUsername)) {
System.out.println("加入黑名单");
redisUtils.set("black_username:" + loginBean.getLoginName(), 1, indexDb); redisUtils.set("black_username:" + loginBean.getLoginName(), 1, indexDb);
redisUtils.expire("black_username:" + loginBean.getLoginName(), userSealUpSeconds, indexDb); redisUtils.expire("black_username:" + loginBean.getLoginName(), userSealUpSeconds, indexDb);
sealup = true; sealup = true;
...@@ -169,6 +171,7 @@ public class UserController { ...@@ -169,6 +171,7 @@ public class UserController {
} }
if (sealup) { if (sealup) {
System.out.println("该帐号已禁止登录");
responseBean.setStatus(ErrorCode.STATUS_CODE_4101); responseBean.setStatus(ErrorCode.STATUS_CODE_4101);
responseBean.setMessage("该帐号已禁止登录"); responseBean.setMessage("该帐号已禁止登录");
checkIpLimit(userIp); checkIpLimit(userIp);
...@@ -190,7 +193,7 @@ public class UserController { ...@@ -190,7 +193,7 @@ public class UserController {
responseBean.setMessage("账户或密码错误"); responseBean.setMessage("账户或密码错误");
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4102]总共用时:" + Util.getDurationTime(duration)); LOG.info("[UserController login][STATUS_CODE_4102]总共用时:" + Util.getDurationTime(duration));
return responseBean; return responseBean;
// 用户被查封 // 用户被查封
} else if (GConstants.NO.equals(userEntity.getLoginFlag())) { } else if (GConstants.NO.equals(userEntity.getLoginFlag())) {
...@@ -200,7 +203,7 @@ public class UserController { ...@@ -200,7 +203,7 @@ public class UserController {
checkIpLimit(userIp); checkIpLimit(userIp);
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4101]总共用时:" + Util.getDurationTime(duration)); LOG.info("[UserController login][STATUS_CODE_4101]总共用时:" + Util.getDurationTime(duration));
return responseBean; return responseBean;
//不是内部联系人 通讯录联系人不允许登陆 //不是内部联系人 通讯录联系人不允许登陆
} else if (!"2".equals(userEntity.getUserType()) && !"4".equals(userEntity.getUserType()) && !"6".equals(userEntity.getUserType())) { } else if (!"2".equals(userEntity.getUserType()) && !"4".equals(userEntity.getUserType()) && !"6".equals(userEntity.getUserType())) {
...@@ -210,7 +213,7 @@ public class UserController { ...@@ -210,7 +213,7 @@ public class UserController {
checkIpLimit(userIp); checkIpLimit(userIp);
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4101]总共用时:" + Util.getDurationTime(duration)); LOG.info("[UserController login][STATUS_CODE_4101]总共用时:" + Util.getDurationTime(duration));
return responseBean; return responseBean;
} }
boolean passwordError = false; boolean passwordError = false;
...@@ -226,18 +229,21 @@ public class UserController { ...@@ -226,18 +229,21 @@ public class UserController {
} }
if (passwordError) { if (passwordError) {
responseBean.setStatus(ErrorCode.STATUS_CODE_4103); responseBean.setStatus(ErrorCode.STATUS_CODE_4103);
System.out.println("账户或密码错误");
responseBean.setMessage("账户或密码错误"); responseBean.setMessage("账户或密码错误");
// 用户信息redis初始时间 增加value值 // 用户信息redis初始时间 增加value值
if (StringUtils.isEmpty(redisUsername)) { if (StringUtils.isEmpty(redisUsername)) {
System.out.println("账户错误初始化");
redisUtils.set(loginBean.getLoginName(), 1, indexDb); redisUtils.set(loginBean.getLoginName(), 1, indexDb);
redisUtils.expire(loginBean.getLoginName(), userOverdueSeconds, indexDb); redisUtils.expire(loginBean.getLoginName(), userOverdueSeconds, indexDb);
} else { } else {
System.out.println("账户错误加1");
redisUtils.incrNotResetExpireTime(loginBean.getLoginName(), indexDb); redisUtils.incrNotResetExpireTime(loginBean.getLoginName(), indexDb);
} }
checkIpLimit(userIp); checkIpLimit(userIp);
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4103]总共用时:" + Util.getDurationTime(duration)); LOG.info("[UserController login][STATUS_CODE_4103]总共用时:" + Util.getDurationTime(duration));
return responseBean; return responseBean;
} else { } else {
// 校验码登录 // 校验码登录
...@@ -252,7 +258,7 @@ public class UserController { ...@@ -252,7 +258,7 @@ public class UserController {
checkIpLimit(userIp); checkIpLimit(userIp);
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4104]总共用时:" + Util.getDurationTime(duration)); LOG.info("[UserController login][STATUS_CODE_4104]总共用时:" + Util.getDurationTime(duration));
return responseBean; return responseBean;
// 校验码已经失效 // 校验码已经失效
} else if (entity.getExpireTime().getTime() > System.currentTimeMillis()) { } else if (entity.getExpireTime().getTime() > System.currentTimeMillis()) {
...@@ -263,7 +269,7 @@ public class UserController { ...@@ -263,7 +269,7 @@ public class UserController {
checkIpLimit(userIp); checkIpLimit(userIp);
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4105]总共用时:" + Util.getDurationTime(duration)); LOG.info("[UserController login][STATUS_CODE_4105]总共用时:" + Util.getDurationTime(duration));
return responseBean; return responseBean;
} }
// 修改验证码使用状态 // 修改验证码使用状态
...@@ -1046,10 +1052,12 @@ public class UserController { ...@@ -1046,10 +1052,12 @@ public class UserController {
private void checkIpLimit(String userIp) { private void checkIpLimit(String userIp) {
//如果redis没有key //如果redis没有key
if (redisUtils.get(userIp, indexDb) == null) { if (redisUtils.get(userIp, indexDb) == null) {
System.out.println("ip错误初始化");
redisUtils.set(userIp, 1, indexDb); redisUtils.set(userIp, 1, indexDb);
//设置过期时间 //设置过期时间
redisUtils.expire(userIp, ipWithinSeconds, indexDb); redisUtils.expire(userIp, ipWithinSeconds, indexDb);
} else { } else {
System.out.println("ip错误自增");
//如果存在key //如果存在key
redisUtils.incrNotResetExpireTime(userIp, indexDb); redisUtils.incrNotResetExpireTime(userIp, indexDb);
if (Integer.valueOf(redisUtils.get(userIp, indexDb)) >= ipLimitTimes) { if (Integer.valueOf(redisUtils.get(userIp, indexDb)) >= ipLimitTimes) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment