feat(token): 添加Token存在性检查
This commit is contained in:
@@ -26,6 +26,11 @@ func CreateTokenHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//检查Token是否存在
|
||||||
|
if db.CheckToken(input.Token) {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "创建Token失败,Token已经存在"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//创建Token
|
//创建Token
|
||||||
err := db.CreateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
|
err := db.CreateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
|
||||||
@@ -49,6 +54,11 @@ func UpdateTokenHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//检查Token是否存在
|
||||||
|
if !db.CheckToken(input.Token) {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "更改失败,Token不存在"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
|
err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -67,6 +77,11 @@ func DeleteTokenHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//检查Token是否存在
|
||||||
|
if !db.CheckToken(input.Token) {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "删除Token失败,Token不存在"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := db.DeleteToken(input.Token)
|
err := db.DeleteToken(input.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,6 +100,11 @@ func GetTokenInfoHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//检查Token是否存在
|
||||||
|
if !db.CheckToken(input.Token) {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "获取信息失败,Token不存在"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
dedupObject, err := db.GetDedupObject(input.Token)
|
dedupObject, err := db.GetDedupObject(input.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -125,6 +145,11 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//检查Token是否存在
|
||||||
|
if !db.CheckToken(input.Token) {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "删除Token失败,Token不存在"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//检查token是否存在
|
//检查token是否存在
|
||||||
_, err := db.GetDedupObject(input.Token)
|
_, err := db.GetDedupObject(input.Token)
|
||||||
|
10
db/local.go
10
db/local.go
@@ -32,6 +32,16 @@ start:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckToken(token string) bool {
|
||||||
|
InitLocalDB()
|
||||||
|
for _, t := range localDB {
|
||||||
|
if t.Token == token {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func ListToken() []Token {
|
func ListToken() []Token {
|
||||||
InitLocalDB()
|
InitLocalDB()
|
||||||
return localDB
|
return localDB
|
||||||
|
Reference in New Issue
Block a user