summaryrefslogtreecommitdiff
path: root/src/login/repo/tokens.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/login/repo/tokens.rs')
-rw-r--r--src/login/repo/tokens.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/login/repo/tokens.rs b/src/login/repo/tokens.rs
index 584f6dc..3ec3d63 100644
--- a/src/login/repo/tokens.rs
+++ b/src/login/repo/tokens.rs
@@ -1,3 +1,4 @@
+use chrono::TimeDelta;
use sqlx::{sqlite::Sqlite, SqliteConnection, Transaction};
use uuid::Uuid;
@@ -62,6 +63,23 @@ impl<'c> Tokens<'c> {
Ok(())
}
+ pub async fn expire(&mut self, expire_at: DateTime) -> Result<(), BoxedError> {
+ // Somewhat arbitrarily, expire after 90 days.
+ let expired_issue_at = expire_at - TimeDelta::days(90);
+ sqlx::query!(
+ r#"
+ delete
+ from token
+ where issued_at < $1
+ "#,
+ expired_issue_at,
+ )
+ .execute(&mut *self.0)
+ .await?;
+
+ Ok(())
+ }
+
/// Validate a token by its secret, retrieving the associated Login record.
/// Will return [None] if the token is not valid.
pub async fn validate(&mut self, secret: &str) -> Result<Option<Login>, BoxedError> {