From 0934018d9cd2ffa74eae27daf0a330f5707ddcfc Mon Sep 17 00:00:00 2001 From: Janis Streib Date: Mon, 2 Feb 2015 18:58:33 +0100 Subject: [PATCH] UPD: Store ticket number --- .../admin/support/SupportEnterTicketForm.java | 12 ++++++++++- .../support/SupportEnterTicketForm.templ | 4 ++-- .../admin/support/SupportUserDetailsPage.java | 20 ++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.java b/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.java index 6357977c..5db93f30 100644 --- a/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.java +++ b/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.java @@ -6,6 +6,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.localisation.Language; import org.cacert.gigi.output.template.Form; import org.cacert.gigi.output.template.Template; @@ -13,16 +14,25 @@ import org.cacert.gigi.output.template.Template; public class SupportEnterTicketForm extends Form { private static Template t; + + private User target; static { t = new Template(SupportEnterTicketForm.class.getResource("SupportEnterTicketForm.templ")); } - public SupportEnterTicketForm(HttpServletRequest hsr) { + public SupportEnterTicketForm(HttpServletRequest hsr, User target) { super(hsr); + this.target = target; } @Override public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException { + // [asdmASDM]\d{8}\.\d+ + String ticket = req.getParameter("ticketno"); + if (ticket.matches("[asdmASDM]\\d{8}\\.\\d+")) { + req.getSession().setAttribute("ticketNo" + target.getId(), ticket); + return true; + } return false; } diff --git a/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.templ b/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.templ index 5a268dc8..fe9c34fb 100644 --- a/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.templ +++ b/src/org/cacert/gigi/pages/admin/support/SupportEnterTicketForm.templ @@ -4,9 +4,9 @@ : - + value="" name="ticketno"> - + \ No newline at end of file diff --git a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java index ee807253..70146d5f 100644 --- a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java +++ b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java @@ -7,10 +7,12 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.EmailAddress; import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.template.Form; import org.cacert.gigi.output.template.IterableDataset; import org.cacert.gigi.pages.Page; @@ -31,6 +33,7 @@ public class SupportUserDetailsPage extends Page { SupportUserDetailsForm f = new SupportUserDetailsForm(req, user); HashMap vars = new HashMap(); vars.put("details", f); + vars.put("ticketNo", req.getSession().getAttribute("ticketNo" + user.getId())); final EmailAddress[] addrs = user.getEmails(); vars.put("emails", new IterableDataset() { @@ -50,10 +53,25 @@ public class SupportUserDetailsPage extends Page { } }); vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, user)); - vars.put("tickethandling", new SupportEnterTicketForm(req)); + vars.put("tickethandling", new SupportEnterTicketForm(req, user)); getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars); } + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + if (req.getParameter("setTicket") != null) { + try { + if ( !Form.getForm(req, SupportEnterTicketForm.class).submit(resp.getWriter(), req)) { + throw new GigiApiException("Invalid ticket number!"); + } + } catch (GigiApiException e) { + e.printStackTrace(); + e.format(resp.getWriter(), getLanguage(req)); + } + } + super.doPost(req, resp); + } + @Override public boolean isPermitted(User u) { if (u == null) { -- 2.39.2