Resolve some TODOs
This commit is contained in:
parent
133d0de084
commit
c6757f477a
@ -26,7 +26,7 @@ pub enum AuthenticatedMethod {
|
|||||||
Cookie,
|
Cookie,
|
||||||
/// User is authenticated through command line, for debugging purposes only
|
/// User is authenticated through command line, for debugging purposes only
|
||||||
Dev,
|
Dev,
|
||||||
// TODO : token implementation
|
/// User is authenticated using an API token
|
||||||
Token(Token),
|
Token(Token),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,9 +170,7 @@ impl FromRequest for AuthExtractor {
|
|||||||
// Handle tokens expiration
|
// Handle tokens expiration
|
||||||
if token.is_expired() {
|
if token.is_expired() {
|
||||||
log::error!("Attempted to use expired token! {:?}", token);
|
log::error!("Attempted to use expired token! {:?}", token);
|
||||||
return Err(actix_web::error::ErrorBadRequest(
|
return Err(actix_web::error::ErrorBadRequest("Token has expired!"));
|
||||||
"Token has expired!",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(Self {
|
return Ok(Self {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::app_config::AppConfig;
|
use crate::app_config::AppConfig;
|
||||||
|
use crate::services::tokens_service;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// The "cron" of the project
|
/// The "cron" of the project
|
||||||
@ -20,6 +21,9 @@ pub async fn main_routine() {
|
|||||||
|
|
||||||
async fn exec_routine() -> anyhow::Result<()> {
|
async fn exec_routine() -> anyhow::Result<()> {
|
||||||
// TODO : remove orphan attachment
|
// TODO : remove orphan attachment
|
||||||
// TODO : remove outdated tokens
|
|
||||||
|
// Remove expired tokens
|
||||||
|
tokens_service::cleanup().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ pub async fn delete(user_id: UserID, token_id: TokenID) -> anyhow::Result<()> {
|
|||||||
/// Remove outdated token
|
/// Remove outdated token
|
||||||
pub async fn cleanup() -> anyhow::Result<()> {
|
pub async fn cleanup() -> anyhow::Result<()> {
|
||||||
let query = format!(
|
let query = format!(
|
||||||
"DELETE from token where last_used + max_inactivity < {};",
|
"DELETE from token where time_used + max_inactivity < {};",
|
||||||
time()
|
time()
|
||||||
);
|
);
|
||||||
diesel::sql_query(query).execute(&mut db()?)?;
|
diesel::sql_query(query).execute(&mut db()?)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user