ezidam: added logout page, added RefreshToken guard
This commit is contained in:
parent
49b3a3d1fe
commit
5100aa1b4e
10 changed files with 205 additions and 3 deletions
|
|
@ -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?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue