修复Android登录状态会混乱的bug

ship/type.do接口取消登录验证
新增Filter拦截器,打印请求和参数
System.out改成Log.i
This commit is contained in:
Yutousama 2020-04-08 17:40:18 +08:00
parent ad332a80cf
commit 89346de453
19 changed files with 84 additions and 38 deletions

View File

@ -161,7 +161,7 @@
try { try {
var pw = json.data.user.power; var pw = json.data.user.power;
if (pw == '') { if (pw === '') {
location.reload(); location.reload();
return; return;
} }

View File

@ -10,7 +10,7 @@
</parent> </parent>
<groupId>com.yutou.jianrmod</groupId> <groupId>com.yutou.jianrmod</groupId>
<artifactId>servicer</artifactId> <artifactId>servicer</artifactId>
<version>2.0.1-release</version> <version>2.0.2-release</version>
<name>servicer</name> <name>servicer</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>

View File

@ -3,6 +3,7 @@ package com.yutou.Data;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yutou.utlis.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -74,7 +75,7 @@ public class Ship {
return ship; return ship;
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
System.out.println(json.toString()); Log.i(json.toString());
System.exit(0); System.exit(0);
} }
return null; return null;

View File

@ -5,6 +5,7 @@ import java.util.Date;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.yutou.utlis.Log;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -28,7 +29,7 @@ public class CDNController {
public String ballback(HttpServletRequest request, String hash, String key, String bucket, String fsize, public String ballback(HttpServletRequest request, String hash, String key, String bucket, String fsize,
String uuid, String uToken,String qToken) { String uuid, String uToken,String qToken) {
try { try {
System.out.println("七牛云回调:"); Log.i("七牛云回调:");
Tools.PrintfHttpServletRequest(request); Tools.PrintfHttpServletRequest(request);
if (qToken == null) { if (qToken == null) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();

View File

@ -107,12 +107,6 @@ public class AndroidMapController {
@RequestMapping("/android/ship/type.do") @RequestMapping("/android/ship/type.do")
public String getShipType(HttpServletRequest request){ public String getShipType(HttpServletRequest request){
JSONObject json=new JSONObject(); JSONObject json=new JSONObject();
if(Tools.getUidOfToken(request)<=0){
json.put("msg",UserEnum.LOGIN_NOT_LOGIN.msg);
json.put("code", UserEnum.LOGIN_NOT_LOGIN.code);
return json.toString();
}
List<ZsShipType> list=mapNodeService.selectAllShipType(); List<ZsShipType> list=mapNodeService.selectAllShipType();
json.put("count",list.size()); json.put("count",list.size());
json.put("data", JSONArray.toJSON(list)); json.put("data", JSONArray.toJSON(list));

View File

@ -9,6 +9,7 @@ import com.yutou.maptop.Bean.UserTeam;
import com.yutou.maptop.services.MapTopService; import com.yutou.maptop.services.MapTopService;
import com.yutou.maptop.services.UserTeamService; import com.yutou.maptop.services.UserTeamService;
import com.yutou.utlis.JianrDataTools; import com.yutou.utlis.JianrDataTools;
import com.yutou.utlis.Log;
import com.yutou.utlis.Tools; import com.yutou.utlis.Tools;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -61,7 +62,7 @@ public class MapTopController {
map.setMapNode(JianrDataTools.getMapNode(gameInfoLog.getExt())); map.setMapNode(JianrDataTools.getMapNode(gameInfoLog.getExt()));
map.setShipTeam(JianrDataTools.getShip(JSONObject.parseObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TYPE)); map.setShipTeam(JianrDataTools.getShip(JSONObject.parseObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TYPE));
int id=mapTopService.insertMapTop(map); int id=mapTopService.insertMapTop(map);
System.out.println(">>>>>>ID="+id+" ---> "+JSONObject.parseObject(gameInfoLog.getExt()).getInteger("n")+" "+gameInfoLog.getId()); Log.i(">>>>>>ID="+id+" ---> "+JSONObject.parseObject(gameInfoLog.getExt()).getInteger("n")+" "+gameInfoLog.getId());
UserTeam team=new UserTeam(); UserTeam team=new UserTeam();
team.setMid(id); team.setMid(id);
team.setMapNode(map.getMapNode()); team.setMapNode(map.getMapNode());

View File

@ -9,6 +9,7 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.yutou.utlis.Log;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -77,7 +78,7 @@ public class WebLoginController {
request.getSession().setAttribute("power", 100); request.getSession().setAttribute("power", 100);
break; break;
} }
System.out.println(json.toString()); Log.i(json.toString());
return json.toString(); return json.toString();
} }
@ -85,7 +86,7 @@ public class WebLoginController {
@ResponseBody @ResponseBody
public String reg(HttpServletRequest request,String uname,String pass,String name) { public String reg(HttpServletRequest request,String uname,String pass,String name) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
System.out.println("注册请求"); Log.i("注册请求");
Tools.PrintfHttpServletRequest(request); Tools.PrintfHttpServletRequest(request);
try { try {
uname=new String(uname.getBytes(), StandardCharsets.UTF_8); uname=new String(uname.getBytes(), StandardCharsets.UTF_8);
@ -120,7 +121,6 @@ public class WebLoginController {
String referer=request.getHeader("referer"); String referer=request.getHeader("referer");
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
try { try {
System.out.println( RedisUtlis.get(Tools.getCookie(request,"login")));
String ujson = RedisUtlis.get(Tools.getCookie(request,"login")); String ujson = RedisUtlis.get(Tools.getCookie(request,"login"));
JSONObject reJson=new JSONObject(ujson); JSONObject reJson=new JSONObject(ujson);
udata = reJson.getInt("uid"); udata = reJson.getInt("uid");

View File

@ -6,6 +6,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.yutou.utlis.Log;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -35,7 +36,7 @@ public class WebPermissionController {
JSONObject json=new JSONObject(); JSONObject json=new JSONObject();
JSONArray array=new JSONArray(); JSONArray array=new JSONArray();
User user=userService.getUser(Tools.getUserId(request)); User user=userService.getUser(Tools.getUserId(request));
System.out.println(user); Log.i(user);
for (UGroup group : list) { for (UGroup group : list) {
JSONObject tmp=new JSONObject(); JSONObject tmp=new JSONObject();
tmp.put("permission", group.getTitle()); tmp.put("permission", group.getTitle());

View File

@ -12,6 +12,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.yutou.utlis.*;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -27,10 +28,6 @@ import com.yutou.mybatis.UUserdata;
import com.yutou.mybatis.User; import com.yutou.mybatis.User;
import com.yutou.services.ModService; import com.yutou.services.ModService;
import com.yutou.services.UserService; import com.yutou.services.UserService;
import com.yutou.utlis.EmailTools;
import com.yutou.utlis.RedisUtlis;
import com.yutou.utlis.ServiceStaticValue;
import com.yutou.utlis.Tools;
@Controller @Controller
@RequestMapping("/user") @RequestMapping("/user")
@ -66,12 +63,16 @@ public class WebUserController {
JSONObject userdata = new JSONObject(); JSONObject userdata = new JSONObject();
try { try {
String ujson = RedisUtlis.get(Tools.getCookie(request,"login")); String ujson = RedisUtlis.get(Tools.getCookie(request,"login"));
JSONObject json=new JSONObject(ujson); if(ujson==null){
int uid = json.getInt("uid"); userdata.put("code", UserEnum.LOGIN_NOT_LOGIN.code);
userdata.put("msg", UserEnum.LOGIN_SUCCESS.code); userdata.put("msg", UserEnum.LOGIN_NOT_LOGIN.msg);
userdata.put("message", "ok"); }else {
userdata.put("data", userService.getUserData(uid).getJSONObject("data")); JSONObject json = new JSONObject(ujson);
int uid = json.getInt("uid");
userdata.put("msg", UserEnum.LOGIN_SUCCESS.code);
userdata.put("message", "ok");
userdata.put("data", userService.getUserData(uid).getJSONObject("data"));
}
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
userdata.put("code", UserEnum.LOGIN_NOT_LOGIN.code); userdata.put("code", UserEnum.LOGIN_NOT_LOGIN.code);
@ -152,7 +153,7 @@ public class WebUserController {
try { try {
String ujson =RedisUtlis.get(Tools.getCookie(request,"login")); String ujson =RedisUtlis.get(Tools.getCookie(request,"login"));
JSONObject reJson=new JSONObject(ujson); JSONObject reJson=new JSONObject(ujson);
System.out.println(ujson); Log.i(ujson);
int uid_ =reJson.getInt("uid"); int uid_ =reJson.getInt("uid");
if(!Tools.StringIsEmpty(uid)) { if(!Tools.StringIsEmpty(uid)) {
try { try {

View File

@ -9,6 +9,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.yutou.utlis.Log;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -172,7 +173,7 @@ public class AdminUserController {
public boolean isAdmin(HttpServletRequest request) { public boolean isAdmin(HttpServletRequest request) {
int uid=Tools.getUserId(request); int uid=Tools.getUserId(request);
User user=userService.getUser(uid); User user=userService.getUser(uid);
System.out.println(user); Log.i(user);
if(user.getPower()<powerService.getGroup(POWER.ADMIN,null).getPermission()) { if(user.getPower()<powerService.getGroup(POWER.ADMIN,null).getPermission()) {
return false; return false;
} }

View File

@ -59,7 +59,15 @@ public class SystemController {
if(uid_==0){ if(uid_==0){
uid_=Tools.getUserId(request); uid_=Tools.getUserId(request);
} }
if (uid_ == 0) { int androidUId=-1;
try {
androidUId=Integer.parseInt(request.getParameter("uid"));
}catch (Exception e){
if(request.getParameter("sysinfo").equals("web")){
androidUId=uid_;
}
}
if (uid_ == 0||uid_!=androidUId) {
json.put("code", UserEnum.LOGIN_NOT_LOGIN.code); json.put("code", UserEnum.LOGIN_NOT_LOGIN.code);
json.put("msg", UserEnum.LOGIN_NOT_LOGIN.msg); json.put("msg", UserEnum.LOGIN_NOT_LOGIN.msg);
return json.toString(); return json.toString();

View File

@ -144,6 +144,7 @@ public class UserController {
@ResponseBody @ResponseBody
public String logout(HttpServletRequest request, String uid, String token) { public String logout(HttpServletRequest request, String uid, String token) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
Log.i(token);
if (Tools.getUidOfToken(request)>0) { if (Tools.getUidOfToken(request)>0) {
json.put("msg", "注销成功"); json.put("msg", "注销成功");
json.put("code", UserEnum.LOGIN_SUCCESS.code); json.put("code", UserEnum.LOGIN_SUCCESS.code);

View File

@ -19,6 +19,7 @@ import javax.mail.Transport;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import com.yutou.utlis.Log;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
public class ulit { public class ulit {
@ -189,7 +190,7 @@ public class ulit {
return false; return false;
} }
public static void deleteMod(String modPath){ public static void deleteMod(String modPath){
System.out.println("删除:"+modPath); Log.i("删除:"+modPath);
File files=new File(modPath); File files=new File(modPath);
if(files.exists()) if(files.exists())
delete(files); delete(files);

View File

@ -6,6 +6,7 @@ import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.yutou.utlis.Log;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -73,7 +74,7 @@ public class ModServiceimpl implements ModService {
public int upload(JSONObject json) { public int upload(JSONObject json) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
try { try {
System.out.println("提交数据库:"+json.toString()); Log.i("提交数据库:"+json.toString());
TMod mod = JSON.parseObject(json.toString(), TMod.class); TMod mod = JSON.parseObject(json.toString(), TMod.class);
mod.setCreatetime(System.currentTimeMillis()); mod.setCreatetime(System.currentTimeMillis());
mod.setIcon(json.getString("icon")); mod.setIcon(json.getString("icon"));

View File

@ -0,0 +1,24 @@
package com.yutou.utlis;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@Component
@WebFilter
public class APIFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request= (HttpServletRequest) servletRequest;
Log.i("API", request.getRequestURI()+Tools.getHttpServletRequest(request));
try {
filterChain.doFilter(servletRequest, servletResponse);
}catch (Exception ignored){
}
}
}

View File

@ -20,10 +20,11 @@ public class Log {
* 普通输出 * 普通输出
* @param str 正文 * @param str 正文
*/ */
public static void i(String str) { public static void i(Object str) {
System.out.println(str); System.out.println(str);
logger.info(str); logger.info(str);
} }
/** /**
* 错误输出带标题 * 错误输出带标题
* @param title 标题 * @param title 标题

View File

@ -38,8 +38,7 @@ public class MD5Signature {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String str="channelid=1499395535416&cpArea=1&money=1000&notes=1_2_1499400140&order=T20170707120223&time=1499400143360&uid=2"; String str="channelid=1499395535416&cpArea=1&money=1000&notes=1_2_1499400140&order=T20170707120223&time=1499400143360&uid=2";
String md5=sign(str, "XT9TEBMAAOH8KNYXUC8TUQB3CTOTOZK4"); String md5=sign(str, "XT9TEBMAAOH8KNYXUC8TUQB3CTOTOZK4");
System.out.println(md5);
} }
} }

View File

@ -126,6 +126,6 @@ public class RedisUtlis {
public static void main(String[] args) { public static void main(String[] args) {
String str= "\"aaa\""; String str= "\"aaa\"";
str=str.replaceAll("\"aaa\"", "0"); str=str.replaceAll("\"aaa\"", "0");
System.out.println(str); Log.i(str);
} }
} }

View File

@ -56,7 +56,7 @@ public class Tools {
//String url = oss.upload(saveFile, path); //String url = oss.upload(saveFile, path);
//oss.close(); //oss.close();
fileName=URLEncoder.encode(fileName,"UTF-8"); fileName=URLEncoder.encode(fileName,"UTF-8");
System.out.println("上传文件保存路径:"+(path+fileName)); Log.i("上传文件保存路径:"+(path+fileName));
return path+fileName; return path+fileName;
} }
/** /**
@ -220,7 +220,6 @@ public class Tools {
Cookie[] cookies = request.getCookies(); Cookie[] cookies = request.getCookies();
String value=null; String value=null;
for (Cookie cookie : cookies) { for (Cookie cookie : cookies) {
System.out.println(cookie.getName()+" "+cookie.getValue());
if (cookie.getName().equals(key)) { if (cookie.getName().equals(key)) {
value=cookie.getValue(); value=cookie.getValue();
break; break;
@ -300,8 +299,8 @@ public class Tools {
array.put(3); array.put(3);
array.put(4); array.put(4);
array.put(5); array.put(5);
System.out.println(array.toString()); Log.i(array.toString());
System.out.println(array.toString()); Log.i(array.toString());
} }
/** /**
* N以内的不重复随机数 * N以内的不重复随机数
@ -476,6 +475,15 @@ public class Tools {
Log.i("HttpServletRequest", "Key:" + name + " value:" + request.getParameter(name)); Log.i("HttpServletRequest", "Key:" + name + " value:" + request.getParameter(name));
} }
} }
public static String getHttpServletRequest(HttpServletRequest request){
String queryString="?";
Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
queryString+=name+"="+request.getParameter(name)+"&";
}
return queryString.substring(0,queryString.length()-1);
}
public static void PrintfSession(HttpServletRequest request) { public static void PrintfSession(HttpServletRequest request) {
Enumeration<String> names=request.getSession().getAttributeNames(); Enumeration<String> names=request.getSession().getAttributeNames();
while (names.hasMoreElements()) { while (names.hasMoreElements()) {
@ -519,6 +527,9 @@ public class Tools {
return -1; return -1;
} }
String ujson = RedisUtlis.get(token); String ujson = RedisUtlis.get(token);
if(ujson==null){
return -1;
}
JSONObject reJson=new JSONObject(ujson); JSONObject reJson=new JSONObject(ujson);
if(reJson.getString("msg").equals("注册成功")) { if(reJson.getString("msg").equals("注册成功")) {
return 0; return 0;