mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-11-01 02:46:19 +08:00 
			
		
		
		
	use RSA to encrypt login
This commit is contained in:
		| @@ -62,7 +62,7 @@ public class Authorize extends HttpServlet { | ||||
| 			l = System.currentTimeMillis(); | ||||
| 		} | ||||
|  | ||||
| 		if (!Checker.nonNull(c, l)) { | ||||
| 		if (Checker.hasNull(c, l)) { | ||||
| 			return new Response(Response.ResponseCode.AUTHORIZE_FAILED); | ||||
| 		} | ||||
| 		if (l < System.currentTimeMillis() - Settings.I.User_Command_Timeout * 1000) { | ||||
|   | ||||
| @@ -28,7 +28,7 @@ import java.io.PrintWriter; | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| @WebServlet(name = "QueryTicket", urlPatterns = "/api/ticketquery", loadOnStartup = 24) | ||||
| @WebServlet(name = "TicketQuery", urlPatterns = "/api/ticketquery", loadOnStartup = 24) | ||||
| public class TicketQuery extends HttpServlet { | ||||
|  | ||||
| 	private Gson gson = SQLCore.gson; | ||||
|   | ||||
| @@ -49,7 +49,7 @@ public class Login extends HttpServlet { | ||||
| 		String wechat = request.getParameter("wechat"); | ||||
| 		String opId = request.getParameter("op"); | ||||
| 		String password = request.getParameter("pass"); | ||||
| 		if (Checker.nonNull(wechat, opId, password)) return new Response(Response.ResponseCode.PARAMETER_REQUIRED); | ||||
| 		if (Checker.hasNull(wechat, opId, password)) return new Response(Response.ResponseCode.PARAMETER_REQUIRED); | ||||
|  | ||||
| 		try (Session s = SQLCore.sf.openSession()) { | ||||
| 			Operator operator = s.get(Operator.class, Integer.parseInt(opId)); | ||||
| @@ -63,7 +63,7 @@ public class Login extends HttpServlet { | ||||
| 			HttpSession httpSession = request.getSession(true); | ||||
| 			httpSession.setAttribute("wechat", wechat); | ||||
| 			httpSession.setAttribute("operator", operator); | ||||
| 			return new Response(Response.ResponseCode.OK); | ||||
| 			return new Response(Response.ResponseCode.OK, operator); | ||||
| 		} catch (NumberFormatException e) { | ||||
| 			return new Response(Response.ResponseCode.ILLEGAL_PARAMETER); | ||||
| 		} catch (HibernateException e) { | ||||
|   | ||||
| @@ -0,0 +1,10 @@ | ||||
| package love.sola.netsupport.api.admin; | ||||
|  | ||||
| /** | ||||
|  * *********************************************** | ||||
|  * Created by Sola on 2015/12/13. | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| public class TicketQuery { | ||||
| } | ||||
| @@ -0,0 +1,82 @@ | ||||
| package love.sola.netsupport.api.admin; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
| import love.sola.netsupport.api.Response; | ||||
| import love.sola.netsupport.pojo.Operator; | ||||
| import love.sola.netsupport.pojo.Ticket; | ||||
| import love.sola.netsupport.sql.SQLCore; | ||||
| import love.sola.netsupport.util.Checker; | ||||
| import love.sola.netsupport.util.ParseUtil; | ||||
| import org.hibernate.HibernateException; | ||||
| import org.hibernate.Session; | ||||
|  | ||||
| import javax.servlet.ServletException; | ||||
| import javax.servlet.annotation.WebServlet; | ||||
| import javax.servlet.http.HttpServlet; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.servlet.http.HttpSession; | ||||
| import java.io.IOException; | ||||
| import java.io.PrintWriter; | ||||
|  | ||||
| /** | ||||
|  * *********************************************** | ||||
|  * Created by Sola on 2015/12/13. | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| @WebServlet(name = "TicketUpdate", urlPatterns = "/api/ticketupdate", loadOnStartup = 32) | ||||
| public class TicketUpdate extends HttpServlet { | ||||
|  | ||||
| 	private Gson gson = SQLCore.gson; | ||||
|  | ||||
| 	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||||
| 		doGet(request, response); | ||||
| 	} | ||||
|  | ||||
| 	@SuppressWarnings("Duplicates") | ||||
| 	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||||
| 		request.setCharacterEncoding("utf-8"); | ||||
| 		response.setCharacterEncoding("utf-8"); | ||||
| 		response.addHeader("Content-type", "text/json;charset=utf-8"); | ||||
| 		PrintWriter out = response.getWriter(); | ||||
| 		String json = gson.toJson(update(request)); | ||||
| 		out.println(ParseUtil.parseJsonP(request, json)); | ||||
| 		out.close(); | ||||
| 	} | ||||
|  | ||||
| 	private Response update(HttpServletRequest request) { | ||||
| 		String ticket = request.getParameter("ticket"); | ||||
| 		String remark = request.getParameter("remark"); | ||||
| 		String status = request.getParameter("status"); | ||||
| 		if (Checker.hasNull(ticket, remark, status)) return new Response(Response.ResponseCode.PARAMETER_REQUIRED); | ||||
|  | ||||
| 		try (Session s = SQLCore.sf.openSession()) { | ||||
| 			HttpSession httpSession = request.getSession(false); | ||||
| 			if (!Checker.operator(httpSession)) { | ||||
| 				return new Response(Response.ResponseCode.UNAUTHORIZED); | ||||
| 			} | ||||
| 			Operator op = (Operator) httpSession.getAttribute("operator"); | ||||
| 			Ticket t = s.get(Ticket.class, Integer.parseInt(ticket)); | ||||
| 			if (t == null) { | ||||
| 				return new Response(Response.ResponseCode.TICKET_NOT_FOUND); | ||||
| 			} | ||||
| 			t.setOperator(op); | ||||
| 			t.setRemark(remark); | ||||
| 			t.setStatus(Integer.parseInt(status)); | ||||
| 			s.beginTransaction(); | ||||
| 			s.update(t); | ||||
| 			s.getTransaction().commit(); | ||||
| 			return new Response(Response.ResponseCode.OK, t); | ||||
| 		} catch (NumberFormatException e) { | ||||
| 			return new Response(Response.ResponseCode.ILLEGAL_PARAMETER); | ||||
| 		} catch (HibernateException e) { | ||||
| 			e.printStackTrace(); | ||||
| 			return new Response(Response.ResponseCode.DATABASE_ERROR, e); | ||||
| 		} catch (Exception e) { | ||||
| 			e.printStackTrace(); | ||||
| 			return new Response(Response.ResponseCode.INTERNAL_ERROR, e); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola