tsk-71: Add token expiration checks (#78)
All checks were successful
Rust Build / Check (pull_request) Successful in 58s
Rust Build / Test Suite (pull_request) Successful in 45s
Rust Build / build (pull_request) Successful in 38s
Release Tagging / release (push) Successful in 36s
Rust Build / Rustfmt (pull_request) Successful in 1m3s
Rust Build / Clippy (pull_request) Successful in 36s
All checks were successful
Rust Build / Check (pull_request) Successful in 58s
Rust Build / Test Suite (pull_request) Successful in 45s
Rust Build / build (pull_request) Successful in 38s
Release Tagging / release (push) Successful in 36s
Rust Build / Rustfmt (pull_request) Successful in 1m3s
Rust Build / Clippy (pull_request) Successful in 36s
Closes #71 Reviewed-on: #78 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit was merged in pull request #78.
This commit is contained in:
@@ -2,7 +2,7 @@ use std::default::Default;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct LoginResult {
|
||||
pub id: uuid::Uuid,
|
||||
pub username: String,
|
||||
@@ -12,20 +12,14 @@ pub struct LoginResult {
|
||||
pub expiration: i64,
|
||||
}
|
||||
|
||||
impl Default for LoginResult {
|
||||
fn default() -> Self {
|
||||
LoginResult {
|
||||
id: uuid::Uuid::nil(),
|
||||
username: String::new(),
|
||||
token: String::new(),
|
||||
token_type: String::new(),
|
||||
expiration: -1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LoginResult {
|
||||
pub fn _to_json(&self) -> Result<String, serde_json::Error> {
|
||||
pub fn to_json(&self) -> Result<String, serde_json::Error> {
|
||||
serde_json::to_string_pretty(&self)
|
||||
}
|
||||
|
||||
pub fn token_expired(&self) -> bool {
|
||||
let current_time = time::OffsetDateTime::now_utc();
|
||||
let expired = time::OffsetDateTime::from_unix_timestamp(self.expiration).unwrap();
|
||||
current_time > expired
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user