dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 4a321fdce2d89db39809beba28b0e46d770c9291
parent 4be3be8e4ee3dcf7902e8c21e503305be045b347
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  1 Jan 2024 17:41:47 -0500

cleanup

Diffstat:
Mpkg/database/tableUsers.go | 8++++++++
Mpkg/web/handlers/login.go | 6++----
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -363,6 +363,14 @@ func (u *User) DoSave(db *DkfDB) { } } +func (u *User) ResetLoginAttempts(db *DkfDB) { + db.db.Model(u).Select("LoginAttempts").Updates(User{LoginAttempts: 0}) +} + +func (u *User) IncrLoginAttempts(db *DkfDB) { + db.db.Model(u).Select("LoginAttempts").Updates(User{LoginAttempts: u.LoginAttempts + 1}) +} + func (u *User) ResetChipsTest(db *DkfDB) { db.db.Model(u).Select("ChipsTest").Updates(User{ChipsTest: 1000}) } diff --git a/pkg/web/handlers/login.go b/pkg/web/handlers/login.go @@ -345,8 +345,7 @@ func loginFormHandler(c echo.Context) error { return c.Render(http.StatusOK, "standalone.login", data) } - user.LoginAttempts++ - user.DoSave(db) + user.IncrLoginAttempts(db) if user.LoginAttempts > 4 && !captchaSolved { data.CaptchaRequired = true @@ -433,8 +432,7 @@ func loginFormHandler(c echo.Context) error { func completeLogin(c echo.Context, user database.User, sessionDuration time.Duration) error { db := c.Get("database").(*database.DkfDB) - user.LoginAttempts = 0 - user.DoSave(db) + user.ResetLoginAttempts(db) for _, session := range db.GetActiveUserSessions(user.ID) { msg := fmt.Sprintf(`New login`)