UPD: SE: Extracted revokeCertificateForm from the page
authorJanis Streib <janis@dogcraft.de>
Wed, 14 Jan 2015 11:24:46 +0000 (12:24 +0100)
committerJanis Streib <janis@dogcraft.de>
Wed, 14 Jan 2015 11:24:46 +0000 (12:24 +0100)
src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.java [new file with mode: 0644]
src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.templ [new file with mode: 0644]
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.templ
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.templ

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 (file)
index 0000000..e51a19e
--- /dev/null
@@ -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<String, Object> 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<String, Object> 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 (file)
index 0000000..f4a0060
--- /dev/null
@@ -0,0 +1,28 @@
+<table class="wrapper dataTable">
+        <tbody><tr>
+            <th colspan="6"><?=_Certificates?></td>
+        </tr>
+        <tr>
+            <th><?=_Cert Type?></th>
+            <th><?=_Total?></th>
+            <th><?=_Valid?></th>
+            <th><?=_Expired?></th>
+            <th><?=_Revoked?></th>
+            <th><?=_Latest Expire?></th>
+        </tr>
+       <? foreach($types) { ?>
+        <tr>
+            <td><?=$profile?></th>
+                <td><?=$total?></td>
+            <td><?=$valid?></td>
+            <td><?=$exp?></td>
+            <td><?=$rev?></td>
+            <td><?=$lastdate?></td>
+            </tr>
+            <? } ?>
+        <tr>
+            <th colspan="6">
+                    <input value="<?=_revoke certificates?>" type="submit">
+            </th>
+        </tr>
+    </tbody></table>
\ No newline at end of file
index 5d35a792b1dca3ca6f73299ef9c545c03c4609b2..2e9cfdf91ca3a78b7b4320c54d6545a1124fddb1 100644 (file)
@@ -3,7 +3,7 @@
             <th colspan="2"><?=$mail?>'s Account Details</th>
         </tr>
         <tr>
-            <td>Email:</td>
+            <td><?=_Email?>:</td>
             <td><?=$mail?></td>
         </tr>
         <tr>
index b9368e42edbb44872729afdb2b002ffe465a4a1b..fccdd5ee2121fbc6af5db801e468dab3e175b5d6 100644 (file)
@@ -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<String, Object> 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);
     }
 
index 5c0ef84e6c992e53b1d1cf5a019af0d56eb38c96..8eed2bb35494278ca5b994757e7bafd253a681be 100644 (file)
         </tbody>
 </table>
 <br/>
-<table class="wrapper dataTable">
-        <tbody><tr>
-            <th colspan="6"><?=_Certificates?></td>
-        </tr>
-        <tr>
-            <th><?=_Cert Type?></th>
-            <th><?=_Total?></th>
-            <th><?=_Valid?></th>
-            <th><?=_Expired?></th>
-            <th><?=_Revoked?></th>
-            <th><?=_Latest Expire?></th>
-        </tr>
-       <? foreach($types) { ?>
-        <tr>
-            <td><?=$profile?></th>
-                <td><?=$total?></td>
-            <td><?=$valid?></td>
-            <td><?=$exp?></td>
-            <td><?=$rev?></td>
-            <td><?=$lastdate?></td>
-            </tr>
-            <? } ?>
-        <tr>
-            <td colspan="6" class="title">
-                    <input value="revoke certificates" type="submit">
-            </td>
-        </tr>
-    </tbody></table>
\ No newline at end of file
+<?=$certifrevoke?>
\ No newline at end of file