diff --git a/src/main/java/com/yutou/tools/Tools/PasswordManager.java b/src/main/java/com/yutou/tools/Tools/PasswordManager.java index 4b9f98d..e2e0ec0 100644 --- a/src/main/java/com/yutou/tools/Tools/PasswordManager.java +++ b/src/main/java/com/yutou/tools/Tools/PasswordManager.java @@ -8,6 +8,7 @@ import com.yutou.tools.mybatis.model.ToolsPassword; import com.yutou.tools.mybatis.model.ToolsPasswordExample; import com.yutou.tools.mybatis.model.ToolsPasswordType; import com.yutou.tools.mybatis.model.ToolsPasswordTypeExample; +import com.yutou.tools.other.tools; import com.yutou.tools.utils.AESTools; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; @@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.List; @Controller @@ -26,13 +28,16 @@ public class PasswordManager { ToolsPasswordDao passwordDao; @Resource ToolsPasswordTypeDao passwordTypeDao; + @Resource + tools tls; @ResponseBody @RequestMapping(value = "get/list.do",method = RequestMethod.GET) - public String getPasswordList(String type){ + public String getPasswordList(HttpServletRequest request,String type){ JSONObject json=new JSONObject(); + int id=tls.getUid(request); ToolsPasswordExample example=new ToolsPasswordExample(); - example.createCriteria().andTypeEqualTo(Integer.parseInt(type)); + example.createCriteria().andTypeEqualTo(Integer.parseInt(type)).andUidEqualTo(id); List passwords=passwordDao.selectByExample(example); for (ToolsPassword password : passwords) { password.setPassword("*****"); @@ -44,18 +49,47 @@ public class PasswordManager { } @ResponseBody @RequestMapping(value = "get/password.do",method = RequestMethod.GET) - public String getPassword(String id){ + public String getPassword(HttpServletRequest request,String id){ JSONObject json=new JSONObject(); - ToolsPassword password=passwordDao.selectByPrimaryKey(Integer.parseInt(id)); + int uid=tls.getUid(request); + ToolsPasswordExample example=new ToolsPasswordExample(); + example.createCriteria().andIdEqualTo(Integer.parseInt(id)).andUidEqualTo(uid); + ToolsPassword password=passwordDao.selectByExample(example).get(0); json.put("code",0); json.put("data",AESTools.decrypt(password.getPassword())); return json.toJSONString(); } @ResponseBody - @RequestMapping(value = "type/get/list.do",method = RequestMethod.GET) - public String getPasswordType(){ + @RequestMapping(value = "get/all.do",method = RequestMethod.GET) + public String getAllPassword(HttpServletRequest request){ JSONObject json=new JSONObject(); - List toolsPasswordTypes=passwordTypeDao.selectByExample(new ToolsPasswordTypeExample()); + JSONArray array=new JSONArray(); + int uid=tls.getUid(request); + if(uid==-1){ + return ""; + } + ToolsPasswordExample example=new ToolsPasswordExample(); + example.createCriteria().andUidEqualTo(uid); + List list=passwordDao.selectByExample(example); + for (ToolsPassword password : list) { + JSONObject item=new JSONObject(); + item.put("account",password.getUsername()); + item.put("title",password.getTitle()); + item.put("password",AESTools.decrypt(password.getPassword())); + array.add(item); + } + json.put("code",0); + json.put("data",array); + return json.toJSONString(); + } + @ResponseBody + @RequestMapping(value = "type/get/list.do",method = RequestMethod.GET) + public String getPasswordType(HttpServletRequest request){ + JSONObject json=new JSONObject(); + int uid=tls.getUid(request); + ToolsPasswordTypeExample example=new ToolsPasswordTypeExample(); + example.createCriteria().andUidEqualTo(uid); + List toolsPasswordTypes=passwordTypeDao.selectByExample(example); json.put("code",0); json.put("msg","ok"); json.put("data", JSONArray.toJSON(toolsPasswordTypes)); @@ -63,11 +97,13 @@ public class PasswordManager { } @ResponseBody @RequestMapping(value = "type/set/add.do",method = RequestMethod.POST) - public String addPasswordType(String type){ + public String addPasswordType(HttpServletRequest request,String type){ JSONObject json=new JSONObject(); try{ + int uid=tls.getUid(request); ToolsPasswordType passwordType=new ToolsPasswordType(); passwordType.setTitle(type); + passwordType.setUid(uid); int code=passwordTypeDao.insert(passwordType); json.put("code",0); json.put("msg","修改结果:"+code); @@ -80,7 +116,7 @@ public class PasswordManager { } @ResponseBody @RequestMapping(value = "set/add.do",method = RequestMethod.POST) - public String addPassword(String title,String username,String password,String url,String info,String type){ + public String addPassword(HttpServletRequest request,String title,String username,String password,String url,String info,String type){ JSONObject json=new JSONObject(); try{ if(StringUtils.isEmpty(title)||StringUtils.isEmpty(username)||StringUtils.isEmpty(password)||StringUtils.isEmpty(type)){ @@ -88,11 +124,13 @@ public class PasswordManager { json.put("msg","有参数为空"); return json.toJSONString(); } + int uid=tls.getUid(request); ToolsPassword toolsPassword=new ToolsPassword(); toolsPassword.setTitle(title); toolsPassword.setUsername(username); toolsPassword.setPassword(AESTools.encrypt(password)); toolsPassword.setType(Integer.parseInt(type)); + toolsPassword.setUid(uid); if(url!=null){ toolsPassword.setUrl(url); } @@ -111,10 +149,14 @@ public class PasswordManager { } @ResponseBody @RequestMapping(value = "set/update.do",method = RequestMethod.POST) - public String updatePassword(String title,String username,String password,String url,String info,String id){ + public String updatePassword(HttpServletRequest request,String title,String username,String password,String url,String info,String id){ JSONObject json=new JSONObject(); try{ - ToolsPassword toolsPassword=passwordDao.selectByPrimaryKey(Integer.parseInt(id)); + int uid=tls.getUid(request); + ToolsPasswordExample example=new ToolsPasswordExample(); + example.createCriteria().andIdEqualTo(Integer.parseInt(id)).andUidEqualTo(uid); + + ToolsPassword toolsPassword=passwordDao.selectByExample(example).get(0); if(!StringUtils.isEmpty(title)){ toolsPassword.setTitle(title); } @@ -142,10 +184,13 @@ public class PasswordManager { } @ResponseBody @RequestMapping(value = "type/set/update.do",method = RequestMethod.POST) - public String updatePasswordType(String type,String id){ + public String updatePasswordType(HttpServletRequest request,String type,String id){ JSONObject json=new JSONObject(); try { - ToolsPasswordType passwordType=passwordTypeDao.selectByPrimaryKey(Integer.parseInt(id)); + int uid=tls.getUid(request); + ToolsPasswordTypeExample example=new ToolsPasswordTypeExample(); + example.createCriteria().andUidEqualTo(uid).andIdEqualTo(Integer.parseInt(id)); + ToolsPasswordType passwordType=passwordTypeDao.selectByExample(example).get(0); if(!StringUtils.isEmpty(type)){ passwordType.setTitle(type); } @@ -161,10 +206,13 @@ public class PasswordManager { } @ResponseBody @RequestMapping(value = "set/remove.do",method = RequestMethod.POST) - public String removePassword(String id){ + public String removePassword(HttpServletRequest request,String id){ JSONObject json=new JSONObject(); try { - int code=passwordDao.deleteByPrimaryKey(Integer.parseInt(id)); + int uid=tls.getUid(request); + ToolsPasswordExample example=new ToolsPasswordExample(); + example.createCriteria().andUidEqualTo(uid).andIdEqualTo(Integer.parseInt(id)); + int code=passwordDao.deleteByExample(example); json.put("code",0); json.put("msg","删除结果:"+code); }catch (Exception e){ @@ -176,11 +224,12 @@ public class PasswordManager { } @ResponseBody @RequestMapping(value = "type/set/remove.do",method = RequestMethod.POST) - public String removePasswordType(String id){ + public String removePasswordType(HttpServletRequest request,String id){ JSONObject json=new JSONObject(); try { + int uid=tls.getUid(request); ToolsPasswordExample example=new ToolsPasswordExample(); - example.createCriteria().andTypeEqualTo(Integer.parseInt(id)); + example.createCriteria().andTypeEqualTo(Integer.parseInt(id)).andUidEqualTo(uid); int passwordCode=passwordDao.deleteByExample(example); System.out.println("删除结果:"+passwordCode); int code=passwordTypeDao.deleteByPrimaryKey(Integer.parseInt(id)); diff --git a/src/main/java/com/yutou/tools/mybatis/model/ToolsPassword.java b/src/main/java/com/yutou/tools/mybatis/model/ToolsPassword.java index 073d3a1..5fcbfc8 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/ToolsPassword.java +++ b/src/main/java/com/yutou/tools/mybatis/model/ToolsPassword.java @@ -23,5 +23,7 @@ public class ToolsPassword implements Serializable { private Integer type; + private Integer uid; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordExample.java b/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordExample.java index 721ba32..4bc244a 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordExample.java +++ b/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordExample.java @@ -573,6 +573,66 @@ public class ToolsPasswordExample { addCriterion("`type` not between", value1, value2, "type"); return (Criteria) this; } + + public Criteria andUidIsNull() { + addCriterion("`uid` is null"); + return (Criteria) this; + } + + public Criteria andUidIsNotNull() { + addCriterion("`uid` is not null"); + return (Criteria) this; + } + + public Criteria andUidEqualTo(Integer value) { + addCriterion("`uid` =", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidNotEqualTo(Integer value) { + addCriterion("`uid` <>", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidGreaterThan(Integer value) { + addCriterion("`uid` >", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidGreaterThanOrEqualTo(Integer value) { + addCriterion("`uid` >=", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidLessThan(Integer value) { + addCriterion("`uid` <", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidLessThanOrEqualTo(Integer value) { + addCriterion("`uid` <=", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidIn(List values) { + addCriterion("`uid` in", values, "uid"); + return (Criteria) this; + } + + public Criteria andUidNotIn(List values) { + addCriterion("`uid` not in", values, "uid"); + return (Criteria) this; + } + + public Criteria andUidBetween(Integer value1, Integer value2) { + addCriterion("`uid` between", value1, value2, "uid"); + return (Criteria) this; + } + + public Criteria andUidNotBetween(Integer value1, Integer value2) { + addCriterion("`uid` not between", value1, value2, "uid"); + return (Criteria) this; + } } /** diff --git a/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordType.java b/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordType.java index 69a3dcd..d773cb5 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordType.java +++ b/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordType.java @@ -11,6 +11,8 @@ import lombok.Data; public class ToolsPasswordType implements Serializable { private Integer id; + private Integer uid; + private String title; private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordTypeExample.java b/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordTypeExample.java index 776e05b..cedf40c 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordTypeExample.java +++ b/src/main/java/com/yutou/tools/mybatis/model/ToolsPasswordTypeExample.java @@ -164,6 +164,66 @@ public class ToolsPasswordTypeExample { return (Criteria) this; } + public Criteria andUidIsNull() { + addCriterion("`uid` is null"); + return (Criteria) this; + } + + public Criteria andUidIsNotNull() { + addCriterion("`uid` is not null"); + return (Criteria) this; + } + + public Criteria andUidEqualTo(Integer value) { + addCriterion("`uid` =", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidNotEqualTo(Integer value) { + addCriterion("`uid` <>", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidGreaterThan(Integer value) { + addCriterion("`uid` >", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidGreaterThanOrEqualTo(Integer value) { + addCriterion("`uid` >=", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidLessThan(Integer value) { + addCriterion("`uid` <", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidLessThanOrEqualTo(Integer value) { + addCriterion("`uid` <=", value, "uid"); + return (Criteria) this; + } + + public Criteria andUidIn(List values) { + addCriterion("`uid` in", values, "uid"); + return (Criteria) this; + } + + public Criteria andUidNotIn(List values) { + addCriterion("`uid` not in", values, "uid"); + return (Criteria) this; + } + + public Criteria andUidBetween(Integer value1, Integer value2) { + addCriterion("`uid` between", value1, value2, "uid"); + return (Criteria) this; + } + + public Criteria andUidNotBetween(Integer value1, Integer value2) { + addCriterion("`uid` not between", value1, value2, "uid"); + return (Criteria) this; + } + public Criteria andTitleIsNull() { addCriterion("title is null"); return (Criteria) this; diff --git a/src/main/java/com/yutou/tools/other/tools.java b/src/main/java/com/yutou/tools/other/tools.java index 337137d..98952e4 100644 --- a/src/main/java/com/yutou/tools/other/tools.java +++ b/src/main/java/com/yutou/tools/other/tools.java @@ -3,22 +3,31 @@ package com.yutou.tools.other; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.yutou.tools.ToolsApplication; +import com.yutou.tools.mybatis.dao.UKeyDao; +import com.yutou.tools.mybatis.model.UKey; +import com.yutou.tools.mybatis.model.UKeyExample; import com.yutou.tools.utils.QQBotManager; import com.yutou.tools.utils.RedisTools; import com.yutou.tools.utils.Tools; import org.springframework.stereotype.Controller; +import org.springframework.util.StringUtils; 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; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.Enumeration; +import java.util.List; @Controller public class tools { + @Resource + UKeyDao keyDao; + @ResponseBody @RequestMapping(value = "tools/get.do") public String getJs(HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -74,7 +83,7 @@ public class tools { } JSONObject json = new JSONObject(); json.put("code", 0); - json.put("method",request.getMethod()); + json.put("method", request.getMethod()); json.put("address", Tools.getRemoteAddress(request)); json.put("UA", request.getHeader("User-Agent")); json.put("addressUrl", request.getPathInfo()); @@ -83,7 +92,7 @@ public class tools { json.put("header", header); //Tools.sendServer("打印请求", json.toJSONString()); try { - switch (RedisTools.get("request")){ + switch (RedisTools.get("request")) { case "success": return "success"; case "-999": @@ -92,8 +101,8 @@ public class tools { default: return RedisTools.get("request"); } - }catch (Exception e){ - // e.printStackTrace(); + } catch (Exception e) { + // e.printStackTrace(); } return json.toJSONString(); @@ -115,4 +124,22 @@ public class tools { } return RedisTools.get("request"); } + + public int getUid(HttpServletRequest request) { + String token = request.getParameter("token"); + Cookie cookie = Tools.getCookie(request, "user"); + if (StringUtils.isEmpty(token) && cookie != null) { + if ("ok".equals(RedisTools.get(cookie.getValue()))) { + return 1; + } + } + UKeyExample example = new UKeyExample(); + example.createCriteria().andKeyEqualTo(token); + List list = keyDao.selectByExample(example); + if (list != null && !list.isEmpty()) { + UKey key = list.get(0); + return key.getId(); + } + return -1; + } } diff --git a/src/main/resources/mapper/ToolsPasswordDao.xml b/src/main/resources/mapper/ToolsPasswordDao.xml index 09b6471..fe62d79 100644 --- a/src/main/resources/mapper/ToolsPasswordDao.xml +++ b/src/main/resources/mapper/ToolsPasswordDao.xml @@ -9,6 +9,7 @@ + @@ -69,7 +70,7 @@ - id, title, username, `password`, url, info, `type` + id, title, username, `password`, url, info, `type`, `uid` @@ -180,6 +189,9 @@ `type` = #{record.type,jdbcType=INTEGER}, + + `uid` = #{record.uid,jdbcType=INTEGER}, + @@ -193,7 +205,8 @@ `password` = #{record.password,jdbcType=VARCHAR}, url = #{record.url,jdbcType=VARCHAR}, info = #{record.info,jdbcType=VARCHAR}, - `type` = #{record.type,jdbcType=INTEGER} + `type` = #{record.type,jdbcType=INTEGER}, + `uid` = #{record.uid,jdbcType=INTEGER} @@ -219,6 +232,9 @@ `type` = #{type,jdbcType=INTEGER}, + + `uid` = #{uid,jdbcType=INTEGER}, + where id = #{id,jdbcType=INTEGER} @@ -229,7 +245,8 @@ `password` = #{password,jdbcType=VARCHAR}, url = #{url,jdbcType=VARCHAR}, info = #{info,jdbcType=VARCHAR}, - `type` = #{type,jdbcType=INTEGER} + `type` = #{type,jdbcType=INTEGER}, + `uid` = #{uid,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} \ No newline at end of file diff --git a/src/main/resources/mapper/ToolsPasswordTypeDao.xml b/src/main/resources/mapper/ToolsPasswordTypeDao.xml index 94b2828..e5f927d 100644 --- a/src/main/resources/mapper/ToolsPasswordTypeDao.xml +++ b/src/main/resources/mapper/ToolsPasswordTypeDao.xml @@ -3,6 +3,7 @@ + @@ -64,7 +65,7 @@ - id, title + id, `uid`, title