Commit 239c0628 by java-李谡

添加redis方法

parent 524509ec
......@@ -146,21 +146,23 @@ public class UserController {
LoginBean loginBean = requestBean.getObjectBean(LoginBean.class);
String message = userService.validate(loginBean);
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) {
LoginIpInfo loginIpInfo = userService.findByIp(userIp);
String redisUsername = redisUtils.get(loginBean.getLoginName(), indexDb);
if (loginIpInfo != null) {
responseBean.setStatus(ErrorCode.STATUS_CODE_4102);
System.out.println("IP地址已被锁定");
responseBean.setMessage("IP地址已被锁定");
long endTime = System.nanoTime();
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;
}
String blackUsername = redisUtils.get("black_username:" + loginBean.getLoginName(), indexDb);
boolean sealup = false;
if (null != redisUsername && Integer.parseInt(redisUsername) >= 5 && StringUtils.isEmpty(blackUsername)) {
System.out.println("加入黑名单");
redisUtils.set("black_username:" + loginBean.getLoginName(), 1, indexDb);
redisUtils.expire("black_username:" + loginBean.getLoginName(), userSealUpSeconds, indexDb);
sealup = true;
......@@ -169,6 +171,7 @@ public class UserController {
}
if (sealup) {
System.out.println("该帐号已禁止登录");
responseBean.setStatus(ErrorCode.STATUS_CODE_4101);
responseBean.setMessage("该帐号已禁止登录");
checkIpLimit(userIp);
......@@ -190,7 +193,7 @@ public class UserController {
responseBean.setMessage("账户或密码错误");
long endTime = System.nanoTime();
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;
// 用户被查封
} else if (GConstants.NO.equals(userEntity.getLoginFlag())) {
......@@ -200,7 +203,7 @@ public class UserController {
checkIpLimit(userIp);
long endTime = System.nanoTime();
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;
//不是内部联系人 通讯录联系人不允许登陆
} else if (!"2".equals(userEntity.getUserType()) && !"4".equals(userEntity.getUserType()) && !"6".equals(userEntity.getUserType())) {
......@@ -210,7 +213,7 @@ public class UserController {
checkIpLimit(userIp);
long endTime = System.nanoTime();
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;
}
boolean passwordError = false;
......@@ -226,18 +229,21 @@ public class UserController {
}
if (passwordError) {
responseBean.setStatus(ErrorCode.STATUS_CODE_4103);
System.out.println("账户或密码错误");
responseBean.setMessage("账户或密码错误");
// 用户信息redis初始时间 增加value值
if (StringUtils.isEmpty(redisUsername)) {
System.out.println("账户错误初始化");
redisUtils.set(loginBean.getLoginName(), 1, indexDb);
redisUtils.expire(loginBean.getLoginName(), userOverdueSeconds, indexDb);
} else {
System.out.println("账户错误加1");
redisUtils.incrNotResetExpireTime(loginBean.getLoginName(), indexDb);
}
checkIpLimit(userIp);
long endTime = System.nanoTime();
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;
} else {
// 校验码登录
......@@ -252,7 +258,7 @@ public class UserController {
checkIpLimit(userIp);
long endTime = System.nanoTime();
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;
// 校验码已经失效
} else if (entity.getExpireTime().getTime() > System.currentTimeMillis()) {
......@@ -263,7 +269,7 @@ public class UserController {
checkIpLimit(userIp);
long endTime = System.nanoTime();
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;
}
// 修改验证码使用状态
......@@ -1046,10 +1052,12 @@ public class UserController {
private void checkIpLimit(String userIp) {
//如果redis没有key
if (redisUtils.get(userIp, indexDb) == null) {
System.out.println("ip错误初始化");
redisUtils.set(userIp, 1, indexDb);
//设置过期时间
redisUtils.expire(userIp, ipWithinSeconds, indexDb);
} else {
System.out.println("ip错误自增");
//如果存在key
redisUtils.incrNotResetExpireTime(userIp, indexDb);
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