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 Template t;
26 t = new Template(ChangePasswordPage.class.getResource("ChangePasswordForm.templ"));
30 public void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
31 t.output(out, l, vars);
35 public boolean submit(PrintWriter out, HttpServletRequest req) {
36 String oldpassword = req.getParameter("oldpassword");
37 String p1 = req.getParameter("pword1");
38 String p2 = req.getParameter("pword2");
39 GigiApiException error = new GigiApiException();
40 if (oldpassword == null || p1 == null || p2 == null) {
41 new GigiApiException("All fields are required.").format(out, Page.getLanguage(req));
44 if ( !p1.equals(p2)) {
45 new GigiApiException("New passwords do not match.").format(out, Page.getLanguage(req));
49 target.changePassword(oldpassword, p1);
50 } catch (GigiApiException e) {
53 if ( !error.isEmpty()) {
54 error.format(out, Page.getLanguage(req));