Resolve some TODOs
This commit is contained in:
		@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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(())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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()?)?;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user