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.output.template.TranslateCommand;
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 SubmissionResult submit(HttpServletRequest req) throws GigiApiException {
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 throw new GigiApiException("All fields are required.");
40 if ( !p1.equals(p2)) {
41 throw new GigiApiException("New passwords do not match.");
44 target.changePassword(oldpassword, p1);
45 } catch (GigiApiException e) {
48 if ( !error.isEmpty()) {
51 return new SuccessMessageResult(new TranslateCommand("Password changed."));