mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
Merge pull request #831 from caisi35/dev
fix duplicate user and attempts
This commit is contained in:
commit
80f01e61d3
2 changed files with 9 additions and 0 deletions
|
@ -57,6 +57,14 @@ func AddUser(c *gin.Context) {
|
||||||
Password: json.Password,
|
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)
|
err = u.Create(&user)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -36,6 +36,7 @@ func BanIP(ip string) {
|
||||||
Attempts: 1,
|
Attempts: 1,
|
||||||
ExpiredAt: time.Now().Unix() + int64(settings.AuthSettings.BanThresholdMinutes*60),
|
ExpiredAt: time.Now().Unix() + int64(settings.AuthSettings.BanThresholdMinutes*60),
|
||||||
})
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
_, _ = b.Where(b.IP.Eq(ip)).UpdateSimple(b.Attempts.Add(1))
|
_, _ = b.Where(b.IP.Eq(ip)).UpdateSimple(b.Attempts.Add(1))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue