X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Forga%2FCreateOrgForm.java;h=7b69822549d16860cd37da089a967933b0d28f07;hb=ef4e1fb737eabb4d9816f63d19453dcc88b25662;hp=57f39d62c6a1e60e7dd7b9351f537ecea8d7809c;hpb=cee46f66ee6e45667adf46a9a8b5df040bc61e21;p=gigi.git diff --git a/src/org/cacert/gigi/pages/orga/CreateOrgForm.java b/src/org/cacert/gigi/pages/orga/CreateOrgForm.java index 57f39d62..7b698225 100644 --- a/src/org/cacert/gigi/pages/orga/CreateOrgForm.java +++ b/src/org/cacert/gigi/pages/orga/CreateOrgForm.java @@ -9,6 +9,7 @@ import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Organisation; import org.cacert.gigi.email.EmailProvider; import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.CountrySelector; import org.cacert.gigi.output.template.Form; import org.cacert.gigi.output.template.SprintfCommand; import org.cacert.gigi.output.template.Template; @@ -22,8 +23,6 @@ public class CreateOrgForm extends Form { private String o = ""; - private String c = ""; - private String st = ""; private String l = ""; @@ -36,16 +35,21 @@ public class CreateOrgForm extends Form { private boolean isEdit = false; + private CountrySelector cs; + public CreateOrgForm(HttpServletRequest hsr) { super(hsr); + cs = new CountrySelector("C", false); } public CreateOrgForm(HttpServletRequest hsr, Organisation t) { - super(hsr); + this(hsr); isEdit = true; result = t; o = t.getName(); - c = t.getState(); + + cs = new CountrySelector("C", false, t.getCountry()); + st = t.getProvince(); l = t.getCity(); email = t.getContactEmail(); @@ -54,52 +58,48 @@ public class CreateOrgForm extends Form { } @Override - public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException { + public SubmissionResult submit(HttpServletRequest req) throws GigiApiException { String action = req.getParameter("action"); if (action == null) { - return false; + throw new GigiApiException("No action given."); } if (action.equals("new")) { checkCertData(req); checkOrganisationData(req); - Organisation ne = new Organisation(o, c, st, l, email, optionalName, postalAddress, LoginPage.getUser(req)); + Organisation ne = new Organisation(o, cs.getCountry(), st, l, email, optionalName, postalAddress, LoginPage.getUser(req)); result = ne; - return true; } else if (action.equals("updateOrganisationData")) { checkOrganisationData(req); result.updateOrgData(email, optionalName, postalAddress); - return true; } else if (action.equals("updateCertificateData")) { checkCertData(req); - result.updateCertData(o, c, st, l); - return true; + result.updateCertData(o, cs.getCountry(), st, l); + } else { + throw new GigiApiException("No valid action given."); } - - return false; + return new RedirectResult(ViewOrgPage.DEFAULT_PATH + "/" + result.getId()); } private void checkOrganisationData(HttpServletRequest req) throws GigiApiException { email = extractParam(req, "contact"); optionalName = extractParam(req, "optionalName"); postalAddress = extractParam(req, "postalAddress"); - if ( !EmailProvider.MAIL.matcher(email).matches()) { + if ( !EmailProvider.isValidMailAddress(email)) { throw new GigiApiException("Contact email is not a valid email address"); } } private void checkCertData(HttpServletRequest req) throws GigiApiException { o = extractParam(req, "O"); - c = extractParam(req, "C"); st = extractParam(req, "ST"); l = extractParam(req, "L"); if (o.length() > 64 || o.length() < 1) { throw new GigiApiException(SprintfCommand.createSimple("{0} not given or longer than {1} characters", "Organisation name", 64)); } - if (c.length() != 2) { - throw new GigiApiException(SprintfCommand.createSimple("{0} not given or not exactly {1} characters long", "Country code", 2)); - } + + cs.update(req); if (st.length() > 128 || st.length() < 1) { throw new GigiApiException(SprintfCommand.createSimple("{0} not given or longer than {1} characters", "State/county", 128)); @@ -118,19 +118,16 @@ public class CreateOrgForm extends Form { return parameter.trim(); } - public Organisation getResult() { - return result; - } - @Override protected void outputContent(PrintWriter out, Language l, Map vars) { vars.put("O", o); - vars.put("C", c); + vars.put("C", cs); vars.put("ST", st); vars.put("L", this.l); vars.put("email", email); vars.put("optionalName", optionalName); vars.put("postalAddress", postalAddress); + vars.put("countryCode", cs); if (isEdit) { vars.put("edit", true); }