3a7bf07c1e979191005d378c6aa07d111d54359d
[gigi.git] / src / org / cacert / gigi / pages / admin / support / FindUserForm.java
1 package org.cacert.gigi.pages.admin.support;
2
3 import java.io.PrintWriter;
4 import java.util.Map;
5
6 import javax.servlet.http.HttpServletRequest;
7
8 import org.cacert.gigi.GigiApiException;
9 import org.cacert.gigi.dbObjects.User;
10 import org.cacert.gigi.localisation.Language;
11 import org.cacert.gigi.output.template.Form;
12 import org.cacert.gigi.output.template.SprintfCommand;
13 import org.cacert.gigi.output.template.Template;
14
15 public class FindUserForm extends Form {
16
17     private User users[];
18
19     private static final Template t = new Template(FindDomainForm.class.getResource("FindUserForm.templ"));
20
21     public FindUserForm(HttpServletRequest hsr) {
22         super(hsr);
23     }
24
25     @Override
26     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
27         User[] users = User.findByEmail(req.getParameter("email"));
28         if (users.length == 0) {
29             throw new GigiApiException(SprintfCommand.createSimple("No users found matching {0}", req.getParameter("email")));
30         }
31         this.users = users;
32         return true;
33     }
34
35     @Override
36     protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
37         t.output(out, l, vars);
38     }
39
40     public User[] getUsers() {
41         return users;
42     }
43
44 }