]> WPIA git - gigi.git/blobdiff - src/club/wpia/gigi/pages/PasswordResetPage.java
add: implement password change log
[gigi.git] / src / club / wpia / gigi / pages / PasswordResetPage.java
index 7dc950cacd72fe49eafdf36ac3021a8907052402..b5132f058558da45548c9ce0543f979f18f19469 100644 (file)
@@ -20,6 +20,7 @@ import club.wpia.gigi.output.template.TranslateCommand;
 import club.wpia.gigi.util.AuthorizationContext;
 import club.wpia.gigi.util.RandomToken;
 import club.wpia.gigi.util.ServerConstants;
+import club.wpia.gigi.util.ServerConstants.Host;
 
 public class PasswordResetPage extends Page {
 
@@ -60,7 +61,7 @@ public class PasswordResetPage extends Page {
 
         @Override
         public SuccessMessageResult submit(HttpServletRequest req) throws GigiApiException {
-            try (GigiPreparedStatement passwordReset = new GigiPreparedStatement("UPDATE `passwordResetTickets` SET `used` = CURRENT_TIMESTAMP WHERE `used` IS NULL AND `created` < CURRENT_TIMESTAMP - interval '1 hours' * ?;")) {
+            try (GigiPreparedStatement passwordReset = new GigiPreparedStatement("UPDATE `passwordResetTickets` SET `used` = CURRENT_TIMESTAMP WHERE `used` IS NULL AND `created` < CURRENT_TIMESTAMP - interval '1 hours' * ?::INTEGER;")) {
                 passwordReset.setInt(1, HOUR_MAX);
                 passwordReset.execute();
             }
@@ -75,6 +76,7 @@ public class PasswordResetPage extends Page {
                 throw new GigiApiException("New passwords differ.");
             }
             u.consumePasswordResetTicket(id, tok, p1);
+            u.writeUserLog(u, "User token based password reset");
             return new SuccessMessageResult(new TranslateCommand("Password reset successful."));
         }
 
@@ -94,16 +96,16 @@ public class PasswordResetPage extends Page {
     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
         if (Form.printFormErrors(req, resp.getWriter())) {
             PasswordResetForm form = Form.getForm(req, PasswordResetForm.class);
-            form.output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+            form.output(resp.getWriter(), getLanguage(req), getDefaultVars(req));
         }
     }
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
         try {
-            new PasswordResetForm(req).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+            new PasswordResetForm(req).output(resp.getWriter(), getLanguage(req), getDefaultVars(req));
         } catch (GigiApiException e) {
-            e.format(resp.getWriter(), getLanguage(req));
+            e.format(resp.getWriter(), getLanguage(req), getDefaultVars(req));
         }
     }
 
@@ -121,7 +123,7 @@ public class PasswordResetPage extends Page {
             HashMap<String, Object> vars = new HashMap<>();
             vars.put("subject", subject);
             vars.put("method", method);
-            vars.put("link", "https://" + ServerConstants.getWwwHostNamePortSecure() + PasswordResetPage.PATH //
+            vars.put("link", "https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + PasswordResetPage.PATH //
                     + "?id=" + id + "&token=" + URLEncoder.encode(ptok, "UTF-8"));
             vars.put("hour_max", HOUR_MAX);