diff options
author | Vitaly Takmazov | 2023-01-16 09:21:49 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-16 09:27:20 +0300 |
commit | b836c344d49a8d3ad8f7d164bf0425b59df51384 (patch) | |
tree | aa262c5f85cc4edb1c95295e14e1c40d201d9ff1 /src/main/java/com/juick/service | |
parent | 0c30281a5a0745927b0e1fd39e4cfaefe9021920 (diff) |
email: cleanup expired auth codes
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r-- | src/main/java/com/juick/service/EmailService.java | 3 | ||||
-rw-r--r-- | src/main/java/com/juick/service/EmailServiceImpl.java | 11 |
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 bdd7d405..614cf412 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 977d9a75..7f358533 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)); + } } |