From e04773a40932bb36f102f284fdb5aadef3dd8ecc Mon Sep 17 00:00:00 2001 From: caisi35 Date: Fri, 24 Jan 2025 17:28:40 +0800 Subject: [PATCH 1/2] fix(user):register duplicate name --- api/user/user.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/user/user.go b/api/user/user.go index 396ceb9d..e0bef5ff 100644 --- a/api/user/user.go +++ b/api/user/user.go @@ -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 { From 8ffe29de78a2e05a39bfb92c14d8a93872ea12eb Mon Sep 17 00:00:00 2001 From: caisi35 Date: Fri, 24 Jan 2025 17:30:27 +0800 Subject: [PATCH 2/2] fix(user):"Attempts" create and update to 2 --- internal/user/login.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/user/login.go b/internal/user/login.go index 26b0bb93..518caa98 100644 --- a/internal/user/login.go +++ b/internal/user/login.go @@ -42,6 +42,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)) }