mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
some refactors
This commit is contained in:
@@ -30,7 +30,7 @@ public class Register extends HttpServlet {
|
|||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||||
|
|
||||||
String wechat = checkWechat(request.getParameter("wechatid"), request);
|
String wechat = checkWechat(request);
|
||||||
if (wechat == null) {
|
if (wechat == null) {
|
||||||
Redirect.message(response, 0, "Illegal_Request");
|
Redirect.message(response, 0, "Illegal_Request");
|
||||||
return;
|
return;
|
||||||
@@ -144,12 +144,9 @@ public class Register extends HttpServlet {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String checkWechat(String wechat, HttpServletRequest request) {
|
private String checkWechat(HttpServletRequest request) {
|
||||||
if (wechat == null) return null;
|
if (request.getSession(false) == null) return null;
|
||||||
if (request.getSession() == null) return null;
|
return (String) request.getSession(false).getAttribute("wechat");
|
||||||
String reqWechat = (String) request.getSession().getAttribute("wechat");
|
|
||||||
if (reqWechat != null && reqWechat.equals(wechat)) return reqWechat;
|
|
||||||
else return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import javax.servlet.annotation.WebServlet;
|
|||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
@@ -48,16 +49,12 @@ public class TicketQuery extends HttpServlet {
|
|||||||
|
|
||||||
private Response query(HttpServletRequest request) {
|
private Response query(HttpServletRequest request) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
// if (request.getParameter("id") != null) {
|
|
||||||
// Ticket t = s.get(Ticket.class, Integer.parseInt(request.getParameter("id")));
|
HttpSession httpSession = request.getSession(false);
|
||||||
// if (t == null) return new Response(Response.ResponseCode.TICKET_NOT_FOUND);
|
if (httpSession == null || httpSession.getAttribute("authorized") != Command.QUERY) {
|
||||||
// else return new Response(Response.ResponseCode.OK, t);
|
|
||||||
// }
|
|
||||||
if (request.getSession() == null || request.getSession().getAttribute("authorized") != Command.QUERY) {
|
|
||||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
User u = (User) httpSession.getAttribute("user");
|
||||||
User u = (User) request.getSession().getAttribute("user");
|
|
||||||
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
|
|
||||||
Criteria c = s.createCriteria(Ticket.class);
|
Criteria c = s.createCriteria(Ticket.class);
|
||||||
@@ -79,9 +76,11 @@ public class TicketQuery extends HttpServlet {
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||||
} catch (HibernateException e) {
|
} catch (HibernateException e) {
|
||||||
return new Response(Response.ResponseCode.DATABASE_ERROR);
|
e.printStackTrace();
|
||||||
|
return new Response(Response.ResponseCode.DATABASE_ERROR, e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Response(Response.ResponseCode.INTERNAL_ERROR);
|
e.printStackTrace();
|
||||||
|
return new Response(Response.ResponseCode.INTERNAL_ERROR, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import javax.servlet.annotation.WebServlet;
|
|||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
@@ -45,12 +46,20 @@ public class TicketSubmit extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Response submit(HttpServletRequest request) {
|
private Response submit(HttpServletRequest request) {
|
||||||
|
String desc = request.getParameter("desc");
|
||||||
|
if (desc == null) {
|
||||||
|
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||||
|
}
|
||||||
|
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
if (request.getSession() == null || request.getSession().getAttribute("authorized") != Command.SUBMIT) {
|
|
||||||
|
HttpSession httpSession = request.getSession(false);
|
||||||
|
if (httpSession == null || httpSession.getAttribute("authorized") != Command.SUBMIT) {
|
||||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
User u = (User) request.getSession().getAttribute("user");
|
User u = (User) httpSession.getAttribute("user");
|
||||||
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
|
|
||||||
long n = (long) s.createCriteria(Ticket.class)
|
long n = (long) s.createCriteria(Ticket.class)
|
||||||
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
||||||
.add(Restrictions.eq(Ticket.PROPERTY_STATUS, 0))
|
.add(Restrictions.eq(Ticket.PROPERTY_STATUS, 0))
|
||||||
@@ -59,10 +68,6 @@ public class TicketSubmit extends HttpServlet {
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
return new Response(Response.ResponseCode.ALREADY_SUBMITTED);
|
return new Response(Response.ResponseCode.ALREADY_SUBMITTED);
|
||||||
}
|
}
|
||||||
String desc = request.getParameter("desc");
|
|
||||||
if (desc == null) {
|
|
||||||
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
|
||||||
}
|
|
||||||
Ticket t = new Ticket();
|
Ticket t = new Ticket();
|
||||||
t.setUser(u);
|
t.setUser(u);
|
||||||
t.setDescription(desc);
|
t.setDescription(desc);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class CancelHandler implements WxMpMessageHandler {
|
|||||||
}
|
}
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
t.setUpdateTime(new Date());
|
t.setUpdateTime(new Date());
|
||||||
t.setDescription(lang("User_Cancel_Remark"));
|
t.setRemark(lang("User_Cancel_Remark"));
|
||||||
t.setStatus(Status.SOLVED);
|
t.setStatus(Status.SOLVED);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.update(t);
|
s.update(t);
|
||||||
|
|||||||
Reference in New Issue
Block a user