]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/Verify.java
Move the "dbObject"s to their own package.
[gigi.git] / src / org / cacert / gigi / pages / Verify.java
1 package org.cacert.gigi.pages;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.cacert.gigi.GigiApiException;
10 import org.cacert.gigi.dbObjects.Domain;
11 import org.cacert.gigi.dbObjects.EmailAddress;
12
13 public class Verify extends Page {
14
15     public static final String PATH = "/verify";
16
17     public Verify() {
18         super("Verify email");
19     }
20
21     @Override
22     public boolean needsLogin() {
23         return false;
24     }
25
26     @Override
27     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
28         PrintWriter out = resp.getWriter();
29         String hash = req.getParameter("hash");
30         String type = req.getParameter("type");
31         String id = req.getParameter("id");
32         if ("email".equals(type)) {
33             try {
34                 EmailAddress ea = EmailAddress.getById(Integer.parseInt(id));
35                 ea.verify(hash);
36                 out.println("Email verification completed.");
37             } catch (IllegalArgumentException e) {
38                 out.println(translate(req, "The email address is invalid."));
39             } catch (GigiApiException e) {
40                 e.format(out, getLanguage(req));
41             }
42         } else if ("domain".equals(type)) {
43             try {
44                 Domain ea = Domain.getById(Integer.parseInt(id));
45                 ea.verify(hash);
46                 out.println("Domain verification completed.");
47             } catch (IllegalArgumentException e) {
48                 out.println(translate(req, "The domain address is invalid."));
49             } catch (GigiApiException e) {
50                 e.format(out, getLanguage(req));
51             }
52         }
53     }
54
55 }