From: Janis Streib Date: Wed, 14 Jan 2015 11:24:46 +0000 (+0100) Subject: UPD: SE: Extracted revokeCertificateForm from the page X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=f643fac1b939993dd6b32e814aaca58d59f4c2b1 UPD: SE: Extracted revokeCertificateForm from the page --- diff --git a/src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.java b/src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.java new file mode 100644 index 00000000..e51a19ec --- /dev/null +++ b/src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.java @@ -0,0 +1,86 @@ +package org.cacert.gigi.pages.admin.support; + +import java.io.IOException; +import java.io.PrintWriter; +import java.security.GeneralSecurityException; +import java.util.Date; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.dbObjects.Certificate; +import org.cacert.gigi.dbObjects.CertificateProfile; +import org.cacert.gigi.dbObjects.User; +import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.DateSelector; +import org.cacert.gigi.output.template.Form; +import org.cacert.gigi.output.template.IterableDataset; +import org.cacert.gigi.output.template.Template; + +public class SupportRevokeCertificatesForm extends Form { + + private static Template t; + + private User user; + static { + t = new Template(SupportRevokeCertificatesForm.class.getResource("SupportRevokeCertificatesForm.templ")); + } + + public SupportRevokeCertificatesForm(HttpServletRequest hsr, User user) { + super(hsr); + this.user = user; + } + + @Override + public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException { + return false; + } + + @Override + protected void outputContent(PrintWriter out, Language l, Map vars) { + final Certificate[] certs = user.getCertificates(true); + final CertificateProfile[] profiles = CertificateProfile.getAll(); + vars.put("types", new IterableDataset() { + + int typeIndex = 0; + + @Override + public boolean next(Language l, Map vars) { + if (typeIndex > profiles.length - 1) { + return false; + } + int valid = 0; + int total = 0; + long lastExpire = Long.MIN_VALUE; + for (int i = 0; i < certs.length; i++) { + try { + if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) { + continue; + } + total++; + certs[i].cert().checkValidity(); + lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime()); + valid++; + } catch (GeneralSecurityException | IOException e) { + continue; + } + } + vars.put("total", total); + vars.put("profile", profiles[typeIndex].getVisibleName()); + vars.put("valid", valid); + vars.put("exp", total - valid); + vars.put("rev", "TODO"); + if (lastExpire == Long.MIN_VALUE) { + vars.put("lastdate", "-"); + } else { + vars.put("lastdate", DateSelector.getDateFormat().format(new Date(lastExpire))); + } + typeIndex++; + return true; + } + }); + t.output(out, l, vars); + } + +} diff --git a/src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.templ b/src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.templ new file mode 100644 index 00000000..f4a0060e --- /dev/null +++ b/src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.templ @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
\ No newline at end of file diff --git a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.templ b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.templ index 5d35a792..2e9cfdf9 100644 --- a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.templ +++ b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.templ @@ -3,7 +3,7 @@ 's Account Details - Email: + : diff --git a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java index b9368e42..fccdd5ee 100644 --- a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java +++ b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java @@ -1,21 +1,16 @@ package org.cacert.gigi.pages.admin.support; import java.io.IOException; -import java.security.GeneralSecurityException; -import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.cacert.gigi.dbObjects.Certificate; -import org.cacert.gigi.dbObjects.CertificateProfile; 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.DateSelector; import org.cacert.gigi.output.template.IterableDataset; import org.cacert.gigi.pages.Page; @@ -51,47 +46,7 @@ public class SupportUserDetailsPage extends Page { return i != addrs.length - 1; } }); - final Certificate[] certs = user.getCertificates(true); - final CertificateProfile[] profiles = CertificateProfile.getAll(); - vars.put("types", new IterableDataset() { - - int typeIndex = 0; - - @Override - public boolean next(Language l, Map vars) { - if (typeIndex > profiles.length - 1) { - return false; - } - int valid = 0; - int total = 0; - long lastExpire = Long.MIN_VALUE; - for (int i = 0; i < certs.length; i++) { - try { - if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) { - continue; - } - total++; - certs[i].cert().checkValidity(); - lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime()); - valid++; - } catch (GeneralSecurityException | IOException e) { - continue; - } - } - vars.put("total", total); - vars.put("profile", profiles[typeIndex].getVisibleName()); - vars.put("valid", valid); - vars.put("exp", total - valid); - vars.put("rev", "TODO"); - if (lastExpire == Long.MIN_VALUE) { - vars.put("lastdate", "-"); - } else { - vars.put("lastdate", DateSelector.getDateFormat().format(new Date(lastExpire))); - } - typeIndex++; - return true; - } - }); + vars.put("certifrevoke", new SupportRevokeCertificatesForm(req, user)); getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars); } diff --git a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.templ b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.templ index 5c0ef84e..8eed2bb3 100644 --- a/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.templ +++ b/src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.templ @@ -11,31 +11,4 @@
- - - - - - - - - - - - - - - - - - - - - - - -
-
-
- -
\ No newline at end of file + \ No newline at end of file