]> WPIA git - gigi.git/blob - src/org/cacert/gigi/api/EmailReping.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / src / org / cacert / gigi / api / EmailReping.java
1 package org.cacert.gigi.api;
2
3 import java.io.IOException;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import org.cacert.gigi.GigiApiException;
9 import org.cacert.gigi.dbObjects.EmailAddress;
10 import org.cacert.gigi.dbObjects.User;
11 import org.cacert.gigi.localisation.Language;
12
13 public class EmailReping extends APIPoint {
14
15     public static final String PATH = "/account/emails/reping";
16
17     @Override
18     protected void process(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
19         try {
20             String email = req.getParameter("email");
21             if (email == null) {
22                 resp.sendError(500, "No parameter 'email'.");
23                 return;
24             }
25             for (EmailAddress e : u.getEmails()) {
26                 if (e.getAddress().equals(email)) {
27                     e.requestReping(Language.getInstance(u.getPreferredLocale()));
28                     resp.setContentType("text/plain; charset=UTF-8");
29                     return;
30                 }
31             }
32             resp.sendError(500, "Error, Email address not found.");
33         } catch (IllegalArgumentException e) {
34             resp.sendError(500, "Invalid email");
35         } catch (GigiApiException e) {
36             resp.setStatus(500);
37             resp.setContentType("text/plain; charset=UTF-8");
38             e.formatPlain(resp.getWriter());
39         }
40     }
41 }