mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-26 18:37:41 +02:00
[actix-identity] Fix visit deadline (#263)
This commit is contained in:
@ -152,10 +152,13 @@ impl Identity {
|
||||
pub fn login(ext: &Extensions, id: String) -> Result<Self, anyhow::Error> {
|
||||
let inner = IdentityInner::extract(ext);
|
||||
inner.session.insert(ID_KEY, id)?;
|
||||
inner.session.insert(
|
||||
LOGIN_UNIX_TIMESTAMP_KEY,
|
||||
OffsetDateTime::now_utc().unix_timestamp(),
|
||||
)?;
|
||||
let now = OffsetDateTime::now_utc().unix_timestamp();
|
||||
if inner.is_login_deadline_enabled {
|
||||
inner.session.insert(LOGIN_UNIX_TIMESTAMP_KEY, now)?;
|
||||
}
|
||||
if inner.is_visit_deadline_enabled {
|
||||
inner.session.insert(LAST_VISIT_UNIX_TIMESTAMP_KEY, now)?;
|
||||
}
|
||||
inner.session.renew();
|
||||
Ok(Self(inner))
|
||||
}
|
||||
@ -220,6 +223,12 @@ impl Identity {
|
||||
.transpose()
|
||||
.map_err(anyhow::Error::from)
|
||||
}
|
||||
|
||||
pub(crate) fn set_last_visited_at(&self) -> Result<(), anyhow::Error> {
|
||||
let now = OffsetDateTime::now_utc().unix_timestamp();
|
||||
self.0.session.insert(LAST_VISIT_UNIX_TIMESTAMP_KEY, now)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Extractor implementation for [`Identity`].
|
||||
|
@ -162,6 +162,14 @@ fn enforce_policies(req: &ServiceRequest, configuration: &Configuration) {
|
||||
) {
|
||||
identity.logout();
|
||||
return;
|
||||
} else {
|
||||
if let Err(err) = identity.set_last_visited_at() {
|
||||
tracing::warn!(
|
||||
error.display = %err,
|
||||
error.debug = ?err,
|
||||
"Failed to set the last visited timestamp on `Identity` for an incoming request."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user