1 package org.cacert.gigi.pages.account;
3 import java.io.PrintWriter;
6 import javax.servlet.http.HttpServletRequest;
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.Template;
13 import org.cacert.gigi.pages.Page;
15 public class ChangeForm extends Form {
19 public ChangeForm(HttpServletRequest hsr, User target) {
24 private static final Template t = new Template(ChangePasswordPage.class.getResource("ChangePasswordForm.templ"));
27 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
28 t.output(out, l, vars);
32 public boolean submit(PrintWriter out, HttpServletRequest req) {
33 String oldpassword = req.getParameter("oldpassword");
34 String p1 = req.getParameter("pword1");
35 String p2 = req.getParameter("pword2");
36 GigiApiException error = new GigiApiException();
37 if (oldpassword == null || p1 == null || p2 == null) {
38 new GigiApiException("All fields are required.").format(out, Page.getLanguage(req));
41 if ( !p1.equals(p2)) {
42 new GigiApiException("New passwords do not match.").format(out, Page.getLanguage(req));
46 target.changePassword(oldpassword, p1);
47 } catch (GigiApiException e) {
50 if ( !error.isEmpty()) {
51 error.format(out, Page.getLanguage(req));