更换了Redis的库

新增了对机器人的操作(redis)
This commit is contained in:
2020-05-27 14:40:25 +08:00
parent 2a06117ec7
commit d247235ca5
10 changed files with 239 additions and 137 deletions

View File

@@ -19,8 +19,6 @@ import java.util.UUID;
@Controller
public class userController {
@Resource
RedisTools redisTools;
@RequestMapping("/login/check.do")
@ResponseBody
@@ -29,8 +27,8 @@ public class userController {
json.put("code", -1);
json.put("msg", "未登录");
JSONArray array = new JSONArray();
if (redisTools.get("ban") != null) {
array = JSONArray.parseArray(redisTools.get("ban"));
if (RedisTools.get("ban") != null) {
array = JSONArray.parseArray(RedisTools.get("ban"));
}
if (array.contains(Tools.getRemoteAddress(request))) {
json.put("code", -2);
@@ -42,7 +40,7 @@ public class userController {
if (cookie == null) {
return json.toJSONString();
}
if ("ok".equals(redisTools.get(cookie.getValue()))) {
if ("ok".equals(RedisTools.get(cookie.getValue()))) {
json.put("code", 0);
json.put("msg", "登录成功");
return json.toJSONString();
@@ -56,8 +54,8 @@ public class userController {
@ResponseBody
public String captcha(HttpServletRequest request) {
JSONArray array = new JSONArray();
if (redisTools.get("ban") != null) {
array = JSONArray.parseArray(redisTools.get("ban"));
if (RedisTools.get("ban") != null) {
array = JSONArray.parseArray(RedisTools.get("ban"));
}
if (array.contains(Tools.getRemoteAddress(request))) {
@@ -69,9 +67,9 @@ public class userController {
for (int value : captcha) {
cc += value;
}
redisTools.set("login", cc, 5 * 60 * 1000);
RedisTools.set("login", cc, 5 * 60 * 1000);
String token=UUID.randomUUID().toString().replace("-","");
redisTools.set(token,Tools.getRemoteAddress(request),10 * 60 * 1000);
RedisTools.set(token,Tools.getRemoteAddress(request),10 * 60 * 1000);
String url="http://tools.yutou233.cn/login/ban.do?token="+token;
Tools.sendServer("管理后台登录验证码", "本次登录验证码为:" + cc
+ ",登录IP:" + Tools.getRemoteAddress(request)
@@ -81,14 +79,14 @@ public class userController {
@RequestMapping("/login/ban.do")
@ResponseBody
public String banIp(String token){
String ip=redisTools.get(token);
String ip=RedisTools.get(token);
if(ip!=null){
JSONArray array = new JSONArray();
if (redisTools.get("ban") != null) {
array = JSONArray.parseArray(redisTools.get("bean"));
if (RedisTools.get("ban") != null) {
array = JSONArray.parseArray(RedisTools.get("bean"));
}
array.add(ip);
redisTools.set("ban",array.toJSONString());
RedisTools.set("ban",array.toJSONString());
return "已封禁";
}
return "ERROR";
@@ -98,10 +96,10 @@ public class userController {
@ResponseBody
public String login(HttpServletResponse response, String code) {
JSONObject json = new JSONObject();
if (redisTools.get("login").equals(code.trim())) {
if (RedisTools.get("login").equals(code.trim())) {
String uuid = UUID.randomUUID().toString();
Tools.setCookie(response, "user", uuid.replace("-", ""), 30 * 24 * 60 * 60);
redisTools.set(uuid.replace("-", ""), "ok", 30 * 24 * 60 * 60);
RedisTools.set(uuid.replace("-", ""), "ok", 30 * 24 * 60 * 60);
json.put("code", 0);
json.put("msg", "登录成功");
return json.toJSONString();
@@ -119,8 +117,8 @@ public class userController {
json.put("code", -1);
json.put("msg", "退出失败");
if (cookie != null) {
if ("ok".equals(redisTools.get(cookie.getValue()))) {
redisTools.set(cookie.getValue(), "ok", 1);
if ("ok".equals(RedisTools.get(cookie.getValue()))) {
RedisTools.set(cookie.getValue(), "ok", 1);
Tools.deleteCookie(request, response, "user");
json.put("code", 0);
json.put("msg", "退出成功");