chore: update token related logic

This commit is contained in:
JustSong
2022-11-11 20:02:28 +08:00
parent e1d09aa58f
commit d42b4511cf
6 changed files with 71 additions and 55 deletions
+8 -1
View File
@@ -57,9 +57,16 @@ func pushMessageHelper(c *gin.Context, message *channel.Message) {
})
return
}
if user.Token != "" {
if user.Token != "" && user.Token != " " {
if message.Token == "" {
message.Token = c.Request.Header.Get("Authorization")
if message.Token == "" {
c.JSON(http.StatusForbidden, gin.H{
"success": false,
"message": "token 为空",
})
return
}
}
if user.Token != message.Token {
c.JSON(http.StatusForbidden, gin.H{
+11 -2
View File
@@ -350,7 +350,9 @@ func UpdateSelf(c *gin.Context) {
})
return
}
if user.Password == "" {
user.Password = "$I_LOVE_U" // make Validator happy :)
}
if err := common.Validate.Struct(&user); err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
@@ -364,8 +366,15 @@ func UpdateSelf(c *gin.Context) {
Username: user.Username,
Password: user.Password,
DisplayName: user.DisplayName,
Token: user.Token,
}
if cleanUser.Token == "" {
cleanUser.Token = " " // this is because gorm will ignore zero value
}
if user.Password == "$I_LOVE_U" {
user.Password = "" // rollback to what it should be
cleanUser.Password = ""
}
updatePassword := user.Password != ""
if err := cleanUser.Update(updatePassword); err != nil {
c.JSON(http.StatusOK, gin.H{