Update `last_accessed`

This commit is contained in:
JSH32 2022-09-20 19:54:00 -05:00
parent 73c54b0ce2
commit 0fe638f7e9
2 changed files with 22 additions and 13 deletions

View File

@ -6,11 +6,9 @@ use crate::{
ServiceError, ServiceResult,
},
};
use chrono::Utc;
use sea_orm::{
ActiveModelTrait, ColumnTrait, Condition, DatabaseConnection, EntityTrait, IntoActiveModel,
ModelTrait, QueryFilter, Set,
};
use sea_orm::{prelude::*, Condition, IntoActiveModel, Set};
use std::sync::Arc;
use super::new_password;
@ -63,6 +61,7 @@ impl AuthMethodService {
}
/// Get a user by authentication method and value.
/// This also updates `last_accessed`
pub async fn get_user_by_value(
&self,
method: AuthMethod,
@ -76,11 +75,23 @@ impl AuthMethodService {
)
.await
{
Ok(v) => v
.find_related(users::Entity)
.one(self.database.as_ref())
.await
.map_err(|e| ServiceError::DbErr(e)),
Ok(v) => {
let user = v
.find_related(users::Entity)
.one(self.database.as_ref())
.await
.map_err(|e| ServiceError::DbErr(e))?;
// Update `last_accessed`.
let mut active_method = v.into_active_model();
active_method.last_accessed = Set(Utc::now());
active_method
.update(self.database.as_ref())
.await
.map_err(|e| ServiceError::DbErr(e))?;
Ok(user)
}
Err(e) => match e {
ServiceError::NotFound(_) => Ok(None),
_ => Err(e),

View File

@ -2,11 +2,9 @@ use std::pin::Pin;
use derive_more::Display;
use futures::Future;
use oauth2::basic::BasicClient;
use oauth2::reqwest::async_http_client;
use oauth2::{
AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, RedirectUrl, Scope,
TokenResponse, TokenUrl,
basic::BasicClient, reqwest::async_http_client, AuthUrl, AuthorizationCode, ClientId,
ClientSecret, CsrfToken, RedirectUrl, Scope, TokenResponse, TokenUrl,
};
use serde::de::DeserializeOwned;
use serde::Deserialize;