instead of just the primary one
fixes issue #99
Change-Id: I3ed6e9007357d2091a832aabbd3c97249af77ff2
import java.io.IOException;
import java.util.Date;
import java.io.IOException;
import java.util.Date;
+import java.util.LinkedList;
import java.util.Locale;
import org.cacert.gigi.GigiApiException;
import java.util.Locale;
import org.cacert.gigi.GigiApiException;
+
+ public User getOwner() {
+ return owner;
+ }
+
+ public static EmailAddress[] findByAllEmail(String mail) {
+ LinkedList<EmailAddress> results = new LinkedList<EmailAddress>();
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `emails`.`id` FROM `emails` INNER JOIN `users` ON `users`.`id` = `emails`.`memid` INNER JOIN `certOwners` ON `certOwners`.`id` = `users`.`id` WHERE `emails`.`email` LIKE ? AND `emails`.`deleted` IS NULL AND `certOwners`.`deleted` IS NULL ORDER BY `users`.`id`, `emails`.`email` LIMIT 100")) {
+ ps.setString(1, mail);
+ GigiResultSet rs = ps.executeQuery();
+ while (rs.next()) {
+ results.add(EmailAddress.getById(rs.getInt(1)));
+ }
+ return results.toArray(new EmailAddress[results.size()]);
+ }
+ }
import javax.servlet.http.HttpServletRequest;
import org.cacert.gigi.GigiApiException;
import javax.servlet.http.HttpServletRequest;
import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.dbObjects.EmailAddress;
import org.cacert.gigi.localisation.Language;
import org.cacert.gigi.output.template.Form;
import org.cacert.gigi.output.template.SprintfCommand;
import org.cacert.gigi.localisation.Language;
import org.cacert.gigi.output.template.Form;
import org.cacert.gigi.output.template.SprintfCommand;
public class FindUserForm extends Form {
public class FindUserForm extends Form {
+ private EmailAddress emails[];
private static final Template t = new Template(FindDomainForm.class.getResource("FindUserForm.templ"));
private static final Template t = new Template(FindDomainForm.class.getResource("FindUserForm.templ"));
@Override
public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
@Override
public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
- User[] users = User.findByEmail(req.getParameter("email"));
- if (users.length == 0) {
+ EmailAddress[] emails = EmailAddress.findByAllEmail(req.getParameter("email"));
+ if (emails.length == 0) {
throw new GigiApiException(SprintfCommand.createSimple("No users found matching {0}", req.getParameter("email")));
}
throw new GigiApiException(SprintfCommand.createSimple("No users found matching {0}", req.getParameter("email")));
}
t.output(out, l, vars);
}
t.output(out, l, vars);
}
- public User[] getUsers() {
- return users;
+ public EmailAddress[] getEmails() {
+ return emails;
import javax.servlet.http.HttpServletResponse;
import org.cacert.gigi.GigiApiException;
import javax.servlet.http.HttpServletResponse;
import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.dbObjects.EmailAddress;
import org.cacert.gigi.localisation.Language;
import org.cacert.gigi.output.template.Form;
import org.cacert.gigi.output.template.IterableDataset;
import org.cacert.gigi.localisation.Language;
import org.cacert.gigi.output.template.Form;
import org.cacert.gigi.output.template.IterableDataset;
FindUserForm form = Form.getForm(req, FindUserForm.class);
try {
form.submit(resp.getWriter(), req);
FindUserForm form = Form.getForm(req, FindUserForm.class);
try {
form.submit(resp.getWriter(), req);
- final User[] users = form.getUsers();
- if (users.length == 1) {
- resp.sendRedirect(SupportUserDetailsPage.PATH + users[0].getId());
+ final EmailAddress[] emails = form.getEmails();
+ if (emails.length == 1) {
+ resp.sendRedirect(SupportUserDetailsPage.PATH + emails[0].getOwner().getId());
} else {
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("first", false);
} else {
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("first", false);
@Override
public boolean next(Language l, Map<String, Object> vars) {
@Override
public boolean next(Language l, Map<String, Object> vars) {
- if (i == users.length) {
+ if (i == emails.length) {
- vars.put("usrid", users[i].getId());
- vars.put("usermail", users[i].getEmail());
+ vars.put("usrid", emails[i].getOwner().getId());
+ vars.put("usermail", emails[i].getAddress());