From c6757f477a6dd140042f4b95e12cd93054e89128 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 20 Mar 2025 21:00:29 +0100 Subject: [PATCH] Resolve some TODOs --- moneymgr_backend/src/extractors/auth_extractor.rs | 6 ++---- moneymgr_backend/src/routines.rs | 6 +++++- moneymgr_backend/src/services/tokens_service.rs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/moneymgr_backend/src/extractors/auth_extractor.rs b/moneymgr_backend/src/extractors/auth_extractor.rs index e89bcd8..9351269 100644 --- a/moneymgr_backend/src/extractors/auth_extractor.rs +++ b/moneymgr_backend/src/extractors/auth_extractor.rs @@ -26,7 +26,7 @@ pub enum AuthenticatedMethod { Cookie, /// User is authenticated through command line, for debugging purposes only Dev, - // TODO : token implementation + /// User is authenticated using an API token Token(Token), } @@ -170,9 +170,7 @@ impl FromRequest for AuthExtractor { // Handle tokens expiration if token.is_expired() { log::error!("Attempted to use expired token! {:?}", token); - return Err(actix_web::error::ErrorBadRequest( - "Token has expired!", - )); + return Err(actix_web::error::ErrorBadRequest("Token has expired!")); } return Ok(Self { diff --git a/moneymgr_backend/src/routines.rs b/moneymgr_backend/src/routines.rs index 0f0fd8a..cb9a4ad 100644 --- a/moneymgr_backend/src/routines.rs +++ b/moneymgr_backend/src/routines.rs @@ -1,4 +1,5 @@ use crate::app_config::AppConfig; +use crate::services::tokens_service; use std::time::Duration; /// The "cron" of the project @@ -20,6 +21,9 @@ pub async fn main_routine() { async fn exec_routine() -> anyhow::Result<()> { // TODO : remove orphan attachment - // TODO : remove outdated tokens + + // Remove expired tokens + tokens_service::cleanup().await?; + Ok(()) } diff --git a/moneymgr_backend/src/services/tokens_service.rs b/moneymgr_backend/src/services/tokens_service.rs index 411fd52..b4c5108 100644 --- a/moneymgr_backend/src/services/tokens_service.rs +++ b/moneymgr_backend/src/services/tokens_service.rs @@ -100,7 +100,7 @@ pub async fn delete(user_id: UserID, token_id: TokenID) -> anyhow::Result<()> { /// Remove outdated token pub async fn cleanup() -> anyhow::Result<()> { let query = format!( - "DELETE from token where last_used + max_inactivity < {};", + "DELETE from token where time_used + max_inactivity < {};", time() ); diesel::sql_query(query).execute(&mut db()?)?;