1 package org.cacert.gigi.pages;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.HashMap;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.dbObjects.Domain;
13 import org.cacert.gigi.dbObjects.EmailAddress;
14 import org.cacert.gigi.localisation.Language;
15 import org.cacert.gigi.output.template.Form;
17 public class Verify extends Page {
19 private class VerificationForm extends Form {
27 public VerificationForm(HttpServletRequest hsr) {
29 hash = hsr.getParameter("hash");
30 type = hsr.getParameter("type");
31 id = hsr.getParameter("id");
35 public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
36 if ("email".equals(type)) {
38 EmailAddress ea = EmailAddress.getById(Integer.parseInt(id));
40 out.println("Email verification completed.");
41 } catch (IllegalArgumentException e) {
42 out.println(translate(req, "The email address is invalid."));
43 } catch (GigiApiException e) {
44 e.format(out, getLanguage(req));
46 } else if ("domain".equals(type)) {
48 Domain ea = Domain.getById(Integer.parseInt(id));
50 out.println("Domain verification completed.");
51 } catch (IllegalArgumentException e) {
52 out.println(translate(req, "The domain address is invalid."));
53 } catch (GigiApiException e) {
54 e.format(out, getLanguage(req));
61 protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
62 vars.put("hash", hash);
64 vars.put("type", type);
65 getDefaultTemplate().output(out, l, vars);
70 public static final String PATH = "/verify";
73 super("Verify email");
77 public boolean needsLogin() {
82 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
84 if (Form.getForm(req, VerificationForm.class).submit(resp.getWriter(), req)) {
86 } catch (GigiApiException e) {
87 e.format(resp.getWriter(), getLanguage(req));
92 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
93 new VerificationForm(req).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());