ezidam: added logout page, added RefreshToken guard

This commit is contained in:
Philippe Loctaux 2023-03-18 21:49:08 +01:00
parent 49b3a3d1fe
commit 5100aa1b4e
10 changed files with 205 additions and 3 deletions

View file

@ -41,4 +41,17 @@ impl RefreshToken {
)
.await?)
}
pub async fn get_one(
conn: impl SqliteExecutor<'_>,
token: &str,
) -> Result<Option<Self>, Error> {
Ok(DatabaseRefreshTokens::get_one(conn, token)
.await?
.map(Self::from))
}
pub async fn revoke(self, conn: impl SqliteExecutor<'_>) -> Result<Option<()>, Error> {
Ok(DatabaseRefreshTokens::revoke(conn, &self.token).await?)
}
}

View file

@ -19,3 +19,17 @@ pub struct RefreshToken {
used_at: Option<DateTime<Utc>>,
revoked_at: Option<DateTime<Utc>>,
}
impl RefreshToken {
pub fn has_expired(&self) -> bool {
self.expires_at < Utc::now()
}
pub fn has_been_used(&self) -> bool {
self.used_at.is_some()
}
pub fn is_revoked(&self) -> bool {
self.revoked_at.is_some()
}
}