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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user