aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r--src/main/java/com/juick/service/EmailService.java3
-rw-r--r--src/main/java/com/juick/service/EmailServiceImpl.java11
2 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/com/juick/service/EmailService.java b/src/main/java/com/juick/service/EmailService.java
index bdd7d405e..614cf4122 100644
--- a/src/main/java/com/juick/service/EmailService.java
+++ b/src/main/java/com/juick/service/EmailService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -38,4 +38,5 @@ public interface EmailService {
List<String> getEmails(Integer userId, boolean active);
String getEmailByAuthCode(String code);
void deleteAuthCode(String code);
+ Integer cleanupAuthCodes();
}
diff --git a/src/main/java/com/juick/service/EmailServiceImpl.java b/src/main/java/com/juick/service/EmailServiceImpl.java
index 977d9a751..7f358533a 100644
--- a/src/main/java/com/juick/service/EmailServiceImpl.java
+++ b/src/main/java/com/juick/service/EmailServiceImpl.java
@@ -24,6 +24,10 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
+import java.sql.Types;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.temporal.ChronoUnit;
import java.util.List;
/**
@@ -110,4 +114,11 @@ public class EmailServiceImpl extends BaseJdbcService implements EmailService {
getJdbcTemplate().update("DELETE FROM auth WHERE authcode=?", code);
}
+ @Override
+ public Integer cleanupAuthCodes() {
+ Instant day = Instant.now().minus(1, ChronoUnit.DAYS);
+ return getNamedParameterJdbcTemplate().update("DELETE FROM auth WHERE ts < :day",
+ new MapSqlParameterSource()
+ .addValue("day", day.atOffset(ZoneOffset.UTC), Types.TIMESTAMP_WITH_TIMEZONE));
+ }
}