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>
26 lines
697 B
Rust
26 lines
697 B
Rust
use std::default::Default;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
|
pub struct LoginResult {
|
|
pub id: uuid::Uuid,
|
|
pub username: String,
|
|
pub token: String,
|
|
#[serde(alias = "token_type")]
|
|
pub token_type: String,
|
|
pub expiration: i64,
|
|
}
|
|
|
|
impl LoginResult {
|
|
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
|
|
}
|
|
}
|