dkforest

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

commit 709d00aa2d9dbb0d8a569a970840c9dd21bed186
parent 99beb150996ef17bfeb650361ee0ba2934bcc9d7
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed,  9 Nov 2022 20:13:32 -0800

simplify code

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

diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -1,6 +1,7 @@ package database import ( + "dkforest/pkg/config" "errors" "strings" "time" @@ -459,8 +460,13 @@ func CreateUser(username, password, repassword, gpgPublicKey string, isAdmin, ve return createUser(username, password, repassword, gpgPublicKey, isAdmin, verified, temp, registrationDuration, signupInfoEnc) } -func CreateZeroUser(username, password, repassword, gpgPublicKey string, isAdmin, verified, temp bool, registrationDuration int64, signupInfoEnc string) (User, UserErrors) { - return createUser(username, password, repassword, gpgPublicKey, isAdmin, verified, temp, registrationDuration, signupInfoEnc) +func CreateFirstUser(username, password, repassword string) (User, UserErrors) { + return CreateUser(username, password, repassword, "", true, true, false, true, 12000, "") +} + +func CreateZeroUser() (User, UserErrors) { + password := utils.GenerateToken1() + return createUser("0", password, password, config.NullUserPublicKey, false, true, false, 12000, "") } func createUser(username, password, repassword, gpgPublicKey string, isAdmin bool, verified bool, temp bool, registrationDuration int64, signupInfoEnc string) (User, UserErrors) { diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -74,14 +74,13 @@ func firstUseHandler(c echo.Context) error { data.Username = c.Request().PostFormValue("username") data.Password = c.Request().PostFormValue("password") data.RePassword = c.Request().PostFormValue("repassword") - newUser, errs := database.CreateUser(data.Username, data.Password, data.RePassword, "", true, true, false, true, 12000, "") + newUser, errs := database.CreateFirstUser(data.Username, data.Password, data.RePassword) data.Errors = errs if errs.HasError() { return c.Render(http.StatusOK, "first-use", data) } - nullPassword := utils.GenerateToken1() - _, errs = database.CreateZeroUser("0", nullPassword, nullPassword, config.NullUserPublicKey, false, true, false, 12000, "") + _, errs = database.CreateZeroUser() config.IsFirstUse.SetFalse()