Skip to content

Commit

Permalink
Merge pull request #831 from caisi35/dev
Browse files Browse the repository at this point in the history
fix duplicate user and attempts
  • Loading branch information
0xJacky authored Jan 31, 2025
2 parents 76ea178 + 8ffe29d commit 80f01e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func AddUser(c *gin.Context) {
Password: json.Password,
}

// duplicate name
_, err = u.Where(u.Name.Eq(json.Name)).First()
if !(err != nil && err.Error() == "record not found") {
c.JSON(http.StatusConflict, gin.H{
"message": "name already exists",
})
}

err = u.Create(&user)

if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/user/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func BanIP(ip string) {
Attempts: 1,
ExpiredAt: time.Now().Unix() + int64(settings.AuthSettings.BanThresholdMinutes*60),
})
return
}
_, _ = b.Where(b.IP.Eq(ip)).UpdateSimple(b.Attempts.Add(1))
}

0 comments on commit 80f01e6

Please sign in to comment.