From 3714ec6cd0e950d5889bfd284e19a62168ffe410 Mon Sep 17 00:00:00 2001 From: matresnan <1358168412@qq.com> Date: Tue, 19 Aug 2025 11:45:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=AD=97=E6=AE=B5=E5=B9=B6=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?token=E6=9C=89=E6=95=88=E6=80=A7=E6=A3=80=E6=9F=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为授权表添加禁用状态字段并实现token有效性检查逻辑 - 为TokenInfo结构体添加disable字段以支持令牌禁用功能。 --- src/db.rs | 8 ++++++++ src/main.rs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/db.rs b/src/db.rs index 91a14ce..4182410 100644 --- a/src/db.rs +++ b/src/db.rs @@ -11,6 +11,7 @@ pub struct Authorize { pub project: String, pub token: String, pub device_id: String, + pub disable: i8, pub expire: String, pub insert_time: String, } @@ -19,6 +20,7 @@ pub struct InsertArgs { pub project: String, pub token: String, pub device_id: String, + pub disable: i8, pub expire: String, pub insert_time: String, } @@ -54,6 +56,7 @@ impl Db { project TEXT NOT NULL, token TEXT NOT NULL, device_id TEXT NOT NULL, + disable INTEGER DEFAULT 1, expire TEXT NOT NULL, insert_time TEXT NOT NULL ) @@ -96,6 +99,10 @@ impl Db { .next(); match row { Some(a) => { + // 判断token有效性 + if a.disable == 0 { + return Ok(false); + } // 判断截止时间 let expire_time = NaiveDateTime::parse_from_str(&a.expire, "%Y-%m-%d %H:%M:%S")?; @@ -132,6 +139,7 @@ impl Db { auth.project = args.project.to_string(); auth.token = args.token.to_string(); auth.device_id = args.device_id.to_string(); + auth.disable = args.disable; auth.expire = args.expire.to_string(); auth.insert_time = args.insert_time.to_string(); diff --git a/src/main.rs b/src/main.rs index c78ab93..f9b35e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,6 +89,7 @@ async fn create_token( project: args.project.clone(), token: token.clone(), device_id: args.device_id.clone(), + disable: 1, expire: exp_time, insert_time: str_time, }) @@ -143,6 +144,7 @@ async fn get_token_info( project: v.project, token: v.token, device_id: v.device_id, + disable: v.disable, expire: v.expire, insert_time: v.insert_time, })), @@ -196,6 +198,7 @@ struct TokenInfo { project: String, token: String, device_id: String, + disable: i8, expire: String, insert_time: String, }