Commit 3613b61a by zhangyu

登陆修改

parent 49d72078
......@@ -25,6 +25,7 @@
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:ejweb.properties</value>
<value>classpath:redis.properties</value>
</list>
</property>
</bean>
......
......@@ -41,6 +41,21 @@ public class RedisUtils {
return value;
}
public Long del(String key, int indexDb) {
Jedis jedis = null;
Long value = null;
try {
jedis = jedisPool.getResource();
jedis.select(indexDb);
value = jedis.del(key);
} catch (Exception e) {
log.error(e.getMessage());
} finally {
returnResource(jedisPool, jedis);
}
return value;
}
/**
* 通过key 对value进行加值+1操作,当value不是int类型时会返回错误,当key不存在是则value为1
*
......@@ -75,9 +90,11 @@ public class RedisUtils {
try {
jedis = jedisPool.getResource();
jedis.select(indexDb);
Long expireTime = jedis.pttl(key);
Integer expireTime =jedis.ttl(key).intValue();
res = jedis.incr(key);
jedis.expireAt(key, expireTime);
// jedis.expireAt(key, expireTime);
res = jedis.expire(key, expireTime);
} catch (Exception e) {
log.error(e.getMessage());
} finally {
......@@ -156,4 +173,5 @@ public class RedisUtils {
jedisPool.returnResource(jedis);
}
}
}
}
\ No newline at end of file
package com.ejweb.modules.route.bean;
import java.util.List;
import java.util.Map;
import com.ejweb.core.base.GenericBean;
import org.hibernate.validator.constraints.NotEmpty;
import com.ejweb.core.base.GenericBean;
import java.util.List;
import java.util.Map;
public class VerifyStatusBean extends GenericBean {
......
......@@ -9,6 +9,7 @@ import com.ejweb.core.conf.GConstants;
import com.ejweb.core.fetcher.FetchEntity;
import com.ejweb.core.fetcher.HCFetcher;
import com.ejweb.core.util.IdWorker;
import com.ejweb.core.util.RedisUtils;
import com.ejweb.core.util.Util;
import com.ejweb.modules.im.service.HuaweiInterfaseService;
import com.ejweb.modules.mobile.verify.entity.MobileVerifyEntity;
......@@ -24,6 +25,7 @@ import com.jdair.util.http.client.HTTPClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
......@@ -36,6 +38,7 @@ import java.net.URLDecoder;
import java.util.*;
@Controller
@RequestMapping("/api/user")
public class UserController {
......@@ -49,7 +52,10 @@ public class UserController {
@Autowired
private MobileVerifyService mobileVerifyService;
@Value("${redis.dbIndex}")
private int indexDb;
@Autowired
private RedisUtils RedisUtils;
@Autowired
private UserRolesService userRolesService;
......@@ -131,13 +137,31 @@ public class UserController {
ResponseBean responseBean = new ResponseBean();
String message = userService.validate(requestBean);
LoginBean loginBean = requestBean.getObjectBean(LoginBean.class);
int a = indexDb;
String s = RedisUtils.get(loginBean.getLoginName(), indexDb);
if (null!=s && Integer.parseInt(s) >=6 ){
RedisUtils.expire("black_username"+loginBean.getLoginName(),300,indexDb);
responseBean.setStatus(ErrorCode.STATUS_CODE_4101);
responseBean.setMessage("该帐号已禁止登录");
return responseBean;
}
if (StringUtils.isEmpty(s)){
RedisUtils.set(loginBean.getLoginName(),1,indexDb);
RedisUtils.expire(loginBean.getLoginName(),360,indexDb);
RedisUtils.incrNotResetExpireTime(loginBean.getLoginName(),indexDb);
}else {
RedisUtils.incrNotResetExpireTime(loginBean.getLoginName(),indexDb);
}
message = userService.validate(loginBean);
if (message == null) {
LoginUserEntity userEntity = userService.findUserByLoginName(loginBean);
if(userEntity == null){// 查询不到用户信息
responseBean.setStatus(ErrorCode.STATUS_CODE_4102);
responseBean.setMessage("用户名不存在");
responseBean.setMessage("用户名或密码错误");
long endTime = System.nanoTime();
long duration = endTime - startTime;
......@@ -175,8 +199,8 @@ public class UserController {
}
if (passwordError){
responseBean.setStatus(ErrorCode.STATUS_CODE_4103);
responseBean.setMessage("用户名密码不匹配!");
responseBean.setMessage("用户名或密码错误");
long endTime = System.nanoTime();
long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4103]总共用时:"+Util.getDurationTime(duration));
......@@ -185,7 +209,7 @@ public class UserController {
if(StringUtils.isNotBlank(loginBean.getVerifyCode())){// 校验码登录
MobileVerifyEntity entity = mobileVerifyService.getVerifyCode(loginBean.getLoginName(), loginBean.getVerifyCode());
if(entity == null){// 校验码不存在
RedisUtils.del(loginBean.getLoginName(),indexDb);
responseBean.setStatus(ErrorCode.STATUS_CODE_4104);
responseBean.setMessage("校验码错误");
......@@ -194,7 +218,7 @@ public class UserController {
LOG.debug("[UserController login][STATUS_CODE_4104]总共用时:"+Util.getDurationTime(duration));
return responseBean;
} else if(entity.getExpireTime().getTime()>System.currentTimeMillis()){// 校验码已经失效
RedisUtils.del(loginBean.getLoginName(),indexDb);
responseBean.setStatus(ErrorCode.STATUS_CODE_4105);
responseBean.setMessage("校验码已失效");
......@@ -210,7 +234,7 @@ public class UserController {
// loginInfo.setUserId(userEntity.getId());
// loginInfo.setLoginDate(new Date());
// loginInfo.setLoginIp(clientip);
RedisUtils.del(loginBean.getLoginName(),indexDb);
UserLoginLogEntity deviceInfoEntity = new UserLoginLogEntity();
deviceInfoEntity.setUserId(userEntity.getId());
......
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