feat: 添加令牌过期时间验证并优化查询处理

- 在数据库查询逻辑中添加令牌过期时间验证功能,通过比较当前时间与存储的过期时间来判断令牌有效性,并优化查询结果处理方式。
- 交换令牌创建中的过期时间和插入时间字段,并在令牌验证结果中添加状态消息。
This commit is contained in:
2025-08-18 15:57:22 +08:00
parent c241e16883
commit ce6c2e6cc2
2 changed files with 33 additions and 7 deletions

View File

@@ -98,8 +98,8 @@ async fn create_token(
project: args.project.clone(),
token: token.clone(),
device_id: args.device_id.clone(),
expire: str_time,
insert_time: exp_time,
expire: exp_time,
insert_time: str_time,
})
.await;
@@ -120,9 +120,21 @@ async fn verify_token(
Query(args): Query<VerifyToken>,
) -> (StatusCode, Json<VerifyResult>) {
if state.db.verify_token(&args.token).await.unwrap() {
(StatusCode::OK, Json(VerifyResult { code: 200 }))
(
StatusCode::OK,
Json(VerifyResult {
code: 200,
msg: "正常".to_owned(),
}),
)
} else {
(StatusCode::OK, Json(VerifyResult { code: 404 }))
(
StatusCode::OK,
Json(VerifyResult {
code: 404,
msg: "token已过期".to_owned(),
}),
)
}
}
@@ -184,6 +196,7 @@ struct VerifyToken {
#[derive(Serialize)]
struct VerifyResult {
code: i16,
msg: String,
}
#[derive(Serialize)]