X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Fadmin%2Fsupport%2FSupportUserDetailsPage.java;h=5f626b4ef5d24e3c78a8c7afea46843e664b91f3;hp=5792532576feaa23de4cd99177e552ef0c384fb5;hb=a4a022f3ef3f697298fca60520d422d8662ec706;hpb=84b6b25e4e79ea15ba48cbd83eaf2900aef776b4 diff --git a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java index 57925325..5f626b4e 100644 --- a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java +++ b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java @@ -7,28 +7,41 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.dbObjects.Domain; import org.cacert.gigi.dbObjects.EmailAddress; -import org.cacert.gigi.dbObjects.Group; +import org.cacert.gigi.dbObjects.SupportedUser; 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.LoginPage; import org.cacert.gigi.pages.Page; +import org.cacert.gigi.util.AuthorizationContext; public class SupportUserDetailsPage extends Page { public static final String PATH = "/support/user/"; - public SupportUserDetailsPage(String title) { - super(title); + public SupportUserDetailsPage() { + super("Support: User Details"); } @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - int id; + int id = -1; + if ( !req.getPathInfo().endsWith("/")) { + resp.sendError(404); + } String[] idP = req.getPathInfo().split("/"); - id = Integer.parseInt(idP[idP.length - 1]); + try { + id = Integer.parseInt(idP[idP.length - 1]); + } catch (NumberFormatException e) { + resp.sendError(404); + } final User user = User.getById(id); - SupportUserDetailsForm f = new SupportUserDetailsForm(req, user); + SupportedUser targetUser = new SupportedUser(user, getUser(req), LoginPage.getAuthorizationContext(req).getSupporterTicketId()); + SupportUserDetailsForm f = new SupportUserDetailsForm(req, targetUser); HashMap vars = new HashMap(); vars.put("details", f); final EmailAddress[] addrs = user.getEmails(); @@ -38,26 +51,62 @@ public class SupportUserDetailsPage extends Page { @Override public boolean next(Language l, Map vars) { - if (i == addrs.length) { - return false; + for (; i < addrs.length;) { + EmailAddress secAddress = addrs[i++]; + String address = secAddress.getAddress(); + if ( !address.equals(user.getEmail())) { + vars.put("secmail", address); + vars.put("status", l.getTranslation(secAddress.isVerified() ? "verified" : "not verified")); + return true; + } } - String address = addrs[i].getAddress(); - i++; - if ( !address.equals(user.getEmail())) { - vars.put("secmail", address); + return false; + } + }); + + final Domain[] doms = user.getDomains(); + vars.put("domains", new IterableDataset() { + + private int point = 0; + + @Override + public boolean next(Language l, Map vars) { + if (point >= doms.length) { + return false; } + Domain domain = doms[point]; + vars.put("domain", domain.getSuffix()); + vars.put("status", l.getTranslation(domain.isVerified() ? "verified" : "not verified")); + point++; return true; } }); - vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, user)); + + vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, targetUser)); getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars); } @Override - public boolean isPermitted(User u) { - if (u == null) { - return false; + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + try { + if (req.getParameter("revokeall") != null) { + if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) { + throw new GigiApiException("No ticket number set."); + } + } else if (req.getParameter("detailupdate") != null || req.getParameter("resetPass") != null || req.getParameter("deny") != null || req.getParameter("grant") != null) { + if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) { + throw new GigiApiException("No ticket number set."); + } + } + } catch (GigiApiException e) { + e.printStackTrace(); + e.format(resp.getWriter(), getLanguage(req)); } - return u.isInGroup(Group.getByString("supporter")); + super.doPost(req, resp); + } + + @Override + public boolean isPermitted(AuthorizationContext ac) { + return ac != null && ac.canSupport(); } }