Commit 6753e606 by zt

修改

parent f7650884
......@@ -8,3 +8,5 @@ redis.maxWaitMillis=10000
redis.testOnBorrow=true
redis.testOnReturn=true
redis.dbIndex=3
ipWithinSeconds=3600
ipLimitTimes=25
\ No newline at end of file
package com.ejweb.core.util;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
/**
* @author zangtao
*/
public class PropertiesUtils {
private static Properties properties ;
/**
* 获取配置文件中配置信息
*/
static { }
public static Properties getProperties(){
if (properties == null){
properties = new Properties();
try {
properties.load(new InputStreamReader(PropertiesUtils.class.getClassLoader().getResourceAsStream("redis.properties"),"UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
}
return properties;
}
}
......@@ -18,6 +18,23 @@ public class RedisUtils {
private JedisPool jedisPool;
/**
* 删除key
*
* @param key
* @param indexDb
* @return
*/
public long del(String key, int indexDb) {
Jedis jedis = jedisPool.getResource();
jedis.select(indexDb);
long s = jedis.del(key);
if (null != jedis && null != jedisPool) {
returnResource(jedisPool, jedis);
}
return s;
}
/**
* 通过key获取储存在redis中的value
* 并释放连接
*
......
......@@ -9,6 +9,8 @@ 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.PropertiesUtils;
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;
......@@ -55,6 +57,11 @@ public class UserController {
@Autowired
private HuaweiInterfaseService huaweiInterfaseService;
@Autowired
private RedisUtils redisUtils;
/**
* 根据用户CODE查询用户信息
*
......@@ -126,19 +133,40 @@ public class UserController {
*/
@ResponseBody
@RequestMapping("/login")
public ResponseBean login(HttpServletRequest request, RequestBean requestBean) {
public ResponseBean login(HttpServletRequest request, RequestBean requestBean,String userIp) {
//获取redis的库
int indexDb = Integer.valueOf(PropertiesUtils.getProperties().get("redis.dbIndex").toString());
//ip受限时间与次数
int ipWithinSeconds = Integer.valueOf(PropertiesUtils.getProperties().get("ipWithinSeconds").toString());
int ipLimitTimes = Integer.valueOf(PropertiesUtils.getProperties().get("ipLimitTimes").toString());
long startTime = System.nanoTime();
ResponseBean responseBean = new ResponseBean();
String message = userService.validate(requestBean);
LoginBean loginBean = requestBean.getObjectBean(LoginBean.class);
message = userService.validate(loginBean);
if (message == null) {
//todo 在查用户名数据库之前先查一下数据库 ip限制,如果有ip限制,则直接返回
if(true){
responseBean.setStatus(ErrorCode.STATUS_CODE_4102);
responseBean.setMessage("IP受限!");
}
LoginUserEntity userEntity = userService.findUserByLoginName(loginBean);
if(userEntity == null){// 查询不到用户信息
// 查询不到用户信息
if(userEntity == null){
if(redisUtils.get(userIp,indexDb) == null){
redisUtils.set(userIp,1,indexDb);
}else {
redisUtils.incr(userIp,indexDb);
if (Integer.valueOf(redisUtils.get(userIp,indexDb)) >= ipLimitTimes ){
//todo 存入数据库清除key
redisUtils.del(userIp,indexDb);
}
}
responseBean.setStatus(ErrorCode.STATUS_CODE_4102);
responseBean.setMessage("用户名不存在");
long endTime = System.nanoTime();
long duration = endTime - startTime;
LOG.debug("[UserController login][STATUS_CODE_4102]总共用时:"+Util.getDurationTime(duration));
......
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