Browse Source

Bugfix: drop token after use

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main
Stephan Richter 6 months ago
parent
commit
1d1044980c
  1. 2
      pom.xml
  2. 5
      src/main/java/de/srsoftware/widerhall/data/User.java
  3. 13
      src/main/java/de/srsoftware/widerhall/web/Web.java
  4. 2
      static/templates/footer.st

2
pom.xml

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<groupId>org.example</groupId>
<artifactId>Widerhall</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<build>
<plugins>
<plugin>

5
src/main/java/de/srsoftware/widerhall/data/User.java

@ -137,6 +137,11 @@ public class User { @@ -137,6 +137,11 @@ public class User {
Database.open().query(sql).compile().run();
}
public void dropPasswordToken() throws SQLException {
Database.open().update(TABLE_NAME).set(RESET_TOKEN,null).where(EMAIL,email).compile().run();
}
/**
* Withdraw a specific permission from the user object.
* Updated permission flag will be written to db.

13
src/main/java/de/srsoftware/widerhall/web/Web.java

@ -372,14 +372,17 @@ public class Web extends TemplateServlet { @@ -372,14 +372,17 @@ public class Web extends TemplateServlet {
case RESET_PASSWORD:
if (!isGet) return resetPassword(req,resp);
// TODO: move following code into resetPassword method
try {
user = User.byToken(req.getParameter(TOKEN));
if (user != null) {
var token = req.getParameter(TOKEN);
if (token != null){
try {
user = User.byToken(req.getParameter(TOKEN));
if (user == null) return loadTemplate(path,Map.of(ERROR,"Failed to find user for token!"),resp);
user.dropPasswordToken();
req.getSession().setAttribute("user",user);
return redirectTo(NEW_PASSWORD_FORM,resp);
} catch (SQLException sqle){
return loadTemplate(path,Map.of(ERROR,"Failed to add user for token!"),resp);
}
} catch (SQLException sqle){
return loadTemplate(path,Map.of(ERROR,"Failed to add user for token!"),resp);
}
var email = req.getParameter(EMAIL);
return loadTemplate(path,email == null ? null : Map.of(EMAIL,email),resp);

2
static/templates/footer.st

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<div class="footer">
Widerhall Mail Distributor.
Version 1.0.3.
Version 1.0.4.
Get the sources at <a target="_blank" href="https://git.srsoftware.de/StephanRichter/Widerhall">git.srsoftware.de</a>
</div>

Loading…
Cancel
Save