mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-11-01 02:46:19 +08:00 
			
		
		
		
	improve room check
This commit is contained in:
		| @@ -1,8 +1,13 @@ | ||||
| package love.sola.netsupport.api; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
| import love.sola.netsupport.enums.Attribute; | ||||
| import love.sola.netsupport.pojo.User; | ||||
| import love.sola.netsupport.sql.SQLCore; | ||||
| import love.sola.netsupport.util.Checker; | ||||
| import love.sola.netsupport.util.ParseUtil; | ||||
| import love.sola.netsupport.wechat.Command; | ||||
| import me.chanjar.weixin.common.session.WxSession; | ||||
|  | ||||
| import javax.servlet.ServletException; | ||||
| import javax.servlet.annotation.WebServlet; | ||||
| @@ -38,6 +43,17 @@ public class ProfileModify extends HttpServlet { | ||||
| 	} | ||||
|  | ||||
| 	private Response process(HttpServletRequest request) { | ||||
| 		WxSession session = Checker.isAuthorized(request, Command.QUERY); | ||||
| 		if (session == null) { | ||||
| 			return new Response(Response.ResponseCode.UNAUTHORIZED); | ||||
| 		} | ||||
| 		User u = (User) session.getAttribute(Attribute.USER); | ||||
| 		if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED); | ||||
| 		String isp = request.getParameter("isp"); | ||||
| 		String netaccount = request.getParameter("username"); | ||||
| 		String block = request.getParameter("block"); | ||||
| 		String room = request.getParameter("room"); | ||||
| 		String phone = request.getParameter("phone"); | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -20,6 +20,8 @@ import javax.servlet.http.HttpServletResponse; | ||||
| import java.io.IOException; | ||||
| import java.io.PrintWriter; | ||||
|  | ||||
| import static love.sola.netsupport.util.Checker.*; | ||||
|  | ||||
| /** | ||||
|  * *********************************************** | ||||
|  * Created by Sola on 2015/11/29. | ||||
| @@ -29,8 +31,6 @@ import java.io.PrintWriter; | ||||
| @WebServlet(name = "Register", urlPatterns = "/api/register", loadOnStartup = 21) | ||||
| public class Register extends HttpServlet { | ||||
|  | ||||
| 	public static final String STUDENT_ID_REGEX = "^(2010|2012|2013|2014|2015)[0-9]{9}$"; | ||||
| 	public static final String PHONE_NUMBER_REGEX = "^1[34578][0-9]{9}$"; | ||||
|  | ||||
| 	private Gson gson = SQLCore.gson; | ||||
|  | ||||
| @@ -105,66 +105,6 @@ public class Register extends HttpServlet { | ||||
| 		return "Register_Success"; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	private long checkStudentId(String studentId) { | ||||
| 		if (studentId == null) return -1; | ||||
| 		if (studentId.matches(STUDENT_ID_REGEX)) { | ||||
| 			try { | ||||
| 				return Long.parseLong(studentId); | ||||
| 			} catch (NumberFormatException ignored) { | ||||
| 			} | ||||
| 		} | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	private long checkPhoneNumber(String phone) { | ||||
| 		if (phone == null) return -1; | ||||
| 		if (phone.matches(PHONE_NUMBER_REGEX)) { | ||||
| 			try { | ||||
| 				return Long.parseLong(phone); | ||||
| 			} catch (NumberFormatException ignored) { | ||||
| 			} | ||||
| 		} | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	private ISP checkISP(String isp) { | ||||
| 		if (isp == null) return null; | ||||
| 		try { | ||||
| 			return ISP.fromId(Integer.parseInt(isp)); | ||||
| 		} catch (NumberFormatException ignored) { | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	private String checkNetAccount(String account, ISP isp) { | ||||
| 		if (isp == null) return null; | ||||
| 		if (account == null) return null; | ||||
| 		if (!account.matches(isp.accountRegex)) return null; | ||||
| 		return account; | ||||
| 	} | ||||
|  | ||||
| 	private int checkBlock(String block) { | ||||
| 		if (block == null) return -1; | ||||
| 		try { | ||||
| 			return Integer.parseInt(block); | ||||
| 		} catch (NumberFormatException ignored) { | ||||
| 		} | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	private int checkRoom(String room, int block) { | ||||
| 		if (block == -1) return -1; | ||||
| 		if (room == null) return -1; | ||||
| 		try { | ||||
| 			Integer i = Integer.parseInt(room); | ||||
| 			if (i <= 100 || i >= 1300) return -1; | ||||
| 			return i; | ||||
| 		} catch (NumberFormatException ignored) { | ||||
| 		} | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	private void printAuthorizeFailed(HttpServletRequest request, PrintWriter out) { | ||||
| 		out.println(ParseUtil.parseJsonP(request, gson.toJson(new Response(Response.ResponseCode.AUTHORIZE_FAILED)))); | ||||
| 		out.close(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola