feat: 添加禁用状态字段并实现token有效性检查逻辑
- 为授权表添加禁用状态字段并实现token有效性检查逻辑 - 为TokenInfo结构体添加disable字段以支持令牌禁用功能。
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user