Update last activity of token
This commit is contained in:
parent
b1937d42a2
commit
579e54f7d3
@ -210,6 +210,14 @@ pub async fn update_rights(id: TokenID, rights: TokenRights) -> anyhow::Result<(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set last_used value of token
|
||||||
|
pub async fn refresh_last_used(id: TokenID) -> anyhow::Result<()> {
|
||||||
|
let mut token = get_single(id).await?;
|
||||||
|
token.last_used = time();
|
||||||
|
token.save()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Delete an API token
|
/// Delete an API token
|
||||||
pub async fn delete(id: TokenID) -> anyhow::Result<()> {
|
pub async fn delete(id: TokenID) -> anyhow::Result<()> {
|
||||||
let path = AppConfig::get().api_token_definition_path(id);
|
let path = AppConfig::get().api_token_definition_path(id);
|
||||||
|
@ -114,7 +114,10 @@ impl FromRequest for ApiAuthExtractor {
|
|||||||
// TODO : manually validate all checks
|
// TODO : manually validate all checks
|
||||||
|
|
||||||
if token.should_update_last_activity() {
|
if token.should_update_last_activity() {
|
||||||
// TODO : update last activity
|
if let Err(e) = api_tokens::refresh_last_used(token.id).await {
|
||||||
|
log::error!("Could not update token last activity! {e}");
|
||||||
|
return Err(ErrorBadRequest("!"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ApiAuthExtractor { token, claims })
|
Ok(ApiAuthExtractor { token, claims })
|
||||||
|
Loading…
Reference in New Issue
Block a user