新增页面
有登陆过滤器 正式上线1.0
This commit is contained in:
@@ -7,6 +7,7 @@ import com.yutou.tools.utils.RedisTools;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -27,11 +28,13 @@ public class userController {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", -1);
|
||||
json.put("msg", "未登录");
|
||||
JSONArray array=new JSONArray();
|
||||
if(redisTools.get("bean")!=null){
|
||||
array=JSONArray.parseArray(redisTools.get("bean"));
|
||||
JSONArray array = new JSONArray();
|
||||
if (redisTools.get("ban") != null) {
|
||||
array = JSONArray.parseArray(redisTools.get("ban"));
|
||||
}
|
||||
if(array.contains(Tools.getRemoteAddress(request))){
|
||||
if (array.contains(Tools.getRemoteAddress(request))) {
|
||||
json.put("code", -2);
|
||||
json.put("msg", "未登录");
|
||||
System.out.println("IP已被封禁");
|
||||
return json.toJSONString();
|
||||
}
|
||||
@@ -39,7 +42,7 @@ public class userController {
|
||||
if (cookie == null) {
|
||||
return json.toJSONString();
|
||||
}
|
||||
if (redisTools.get(cookie.getValue()).equals("ok")) {
|
||||
if ("ok".equals(redisTools.get(cookie.getValue()))) {
|
||||
json.put("code", 0);
|
||||
json.put("msg", "登录成功");
|
||||
return json.toJSONString();
|
||||
@@ -52,31 +55,78 @@ public class userController {
|
||||
@RequestMapping("/login/sendCaptcha.do")
|
||||
@ResponseBody
|
||||
public String captcha(HttpServletRequest request) {
|
||||
int[] captcha = Tools.randomCommon(0, 9, 5);
|
||||
JSONArray array = new JSONArray();
|
||||
if (redisTools.get("ban") != null) {
|
||||
array = JSONArray.parseArray(redisTools.get("ban"));
|
||||
}
|
||||
if (array.contains(Tools.getRemoteAddress(request))) {
|
||||
|
||||
System.out.println("IP已被封禁");
|
||||
return "ERROR!";
|
||||
}
|
||||
int[] captcha = Tools.randomCommon(0, 9, 6);
|
||||
String cc = "";
|
||||
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);
|
||||
String url="http://tools.yutou233.cn/login/ban.do?token="+token;
|
||||
Tools.sendServer("管理后台登录验证码", "本次登录验证码为:" + cc
|
||||
+ ",登录IP:" + Tools.getRemoteAddress(request)
|
||||
+ ",非正常登录,封禁IP:http://www.baidu.com");
|
||||
+ ",非正常登录,封禁IP:"+url);
|
||||
return "ok";
|
||||
}
|
||||
@RequestMapping("/login/login.do")
|
||||
@RequestMapping("/login/ban.do")
|
||||
@ResponseBody
|
||||
public String login(HttpServletResponse response,String code){
|
||||
JSONObject json=new JSONObject();
|
||||
if(redisTools.get("login").equals(code.trim())){
|
||||
String uuid=UUID.randomUUID().toString();
|
||||
Tools.setCookie(response,"user",uuid.replace("-",""),30*24*60*60*1000);
|
||||
redisTools.set(uuid.replace("-",""),"ok",30*24*60*60*1000);
|
||||
json.put("code",0);
|
||||
json.put("msg","登录成功");
|
||||
public String banIp(String token){
|
||||
String ip=redisTools.get(token);
|
||||
if(ip!=null){
|
||||
JSONArray array = new JSONArray();
|
||||
if (redisTools.get("ban") != null) {
|
||||
array = JSONArray.parseArray(redisTools.get("bean"));
|
||||
}
|
||||
array.add(ip);
|
||||
redisTools.set("ban",array.toJSONString());
|
||||
return "已封禁";
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login/login.do", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String login(HttpServletResponse response, String code) {
|
||||
JSONObject json = new JSONObject();
|
||||
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);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "登录成功");
|
||||
return json.toJSONString();
|
||||
}
|
||||
json.put("code",-2);
|
||||
json.put("msg","登录安全码错误");
|
||||
return json.toJSONString();
|
||||
json.put("code", -2);
|
||||
json.put("msg", "登录安全码错误");
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login/logout.do", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String logout(HttpServletRequest request, HttpServletResponse response) {
|
||||
JSONObject json = new JSONObject();
|
||||
Cookie cookie = Tools.getCookie(request, "user");
|
||||
json.put("code", -1);
|
||||
json.put("msg", "退出失败");
|
||||
if (cookie != null) {
|
||||
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", "退出成功");
|
||||
}
|
||||
}
|
||||
return json.toJSONString();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user