dkforest

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

commit 705e1f48c487a3ba211dd8692215f5395cabe831
parent 6d93532554f164b8149bdddabc085546318ae8fd
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 12 Jun 2023 20:11:56 -0700

move code

Diffstat:
Mpkg/web/handlers/chat.go | 12++++++++++++
Mpkg/web/handlers/handlers.go | 51---------------------------------------------------
Mpkg/web/handlers/settings.go | 39+++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 51 deletions(-)

diff --git a/pkg/web/handlers/chat.go b/pkg/web/handlers/chat.go @@ -12,6 +12,18 @@ import ( "time" ) +func RedRoomHandler(c echo.Context) error { + return chatHandler(c, true, false) +} + +func ChatHandler(c echo.Context) error { + return chatHandler(c, false, false) +} + +func ChatStreamHandler(c echo.Context) error { + return chatHandler(c, false, true) +} + func chatHandler(c echo.Context, redRoom, stream bool) error { const chatPasswordTmplName = "standalone.chat-password" diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -1293,14 +1293,6 @@ func RoomsHandler(c echo.Context) error { return c.Render(http.StatusOK, "rooms", data) } -func RedRoomHandler(c echo.Context) error { - return chatHandler(c, true, false) -} - -func ChatHandler(c echo.Context) error { - return chatHandler(c, false, false) -} - func getTutorialStepDuration() int64 { secs := int64(15) if config.Development.IsTrue() { @@ -1428,45 +1420,6 @@ func ShopHandler(c echo.Context) error { return c.Render(http.StatusOK, "shop", data) } -func SettingsSecretPhraseHandler(c echo.Context) error { - authUser := c.Get("authUser").(*database.User) - db := c.Get("database").(*database.DkfDB) - var data settingsSecretPhraseData - data.ActiveTab = "secretPhrase" - data.SecretPhrase = string(authUser.SecretPhrase) - - if c.Request().Method == http.MethodGet { - return c.Render(http.StatusOK, "settings.secret-phrase", data) - } - - // POST - currentPassword := c.Request().PostFormValue("currentPassword") - secretPhrase := c.Request().PostFormValue("secretPhrase") - data.CurrentPassword = currentPassword - data.SecretPhrase = secretPhrase - - if len(currentPassword) == 0 { - data.ErrorCurrentPassword = "This field is required" - return c.Render(http.StatusOK, "settings.secret-phrase", data) - } - - if !govalidator.RuneLength(secretPhrase, "3", "50") { - data.ErrorSecretPhrase = "secret phrase must have between 3 and 50 characters" - return c.Render(http.StatusOK, "settings.secret-phrase", data) - } - - if !authUser.CheckPassword(db, currentPassword) { - data.ErrorCurrentPassword = "Invalid password" - return c.Render(http.StatusOK, "settings.secret-phrase", data) - } - - authUser.SecretPhrase = database.EncryptedString(secretPhrase) - authUser.DoSave(db) - - db.CreateSecurityLog(authUser.ID, database.ChangeSecretPhraseSecurityLog) - return c.Render(http.StatusFound, "flash", FlashResponse{Message: "Secret phrase changed successfully", Redirect: c.Request().Referer()}) -} - func ChatDeleteHandler(c echo.Context) error { authUser := c.Get("authUser").(*database.User) db := c.Get("database").(*database.DkfDB) @@ -2245,10 +2198,6 @@ func BHCHandler(c echo.Context) error { return c.Render(http.StatusOK, "bhc", data) } -func ChatStreamHandler(c echo.Context) error { - return chatHandler(c, false, true) -} - // ChatStreamMenuHandler return the html for the "stream" chat right-manu. func ChatStreamMenuHandler(c echo.Context) error { db := c.Get("database").(*database.DkfDB) diff --git a/pkg/web/handlers/settings.go b/pkg/web/handlers/settings.go @@ -938,3 +938,42 @@ func SettingsInvitationsHandler(c echo.Context) error { data.Invitations, _ = db.GetUserUnusedInvitations(authUser.ID) return c.Render(http.StatusOK, "settings.invitations", data) } + +func SettingsSecretPhraseHandler(c echo.Context) error { + authUser := c.Get("authUser").(*database.User) + db := c.Get("database").(*database.DkfDB) + var data settingsSecretPhraseData + data.ActiveTab = "secretPhrase" + data.SecretPhrase = string(authUser.SecretPhrase) + + if c.Request().Method == http.MethodGet { + return c.Render(http.StatusOK, "settings.secret-phrase", data) + } + + // POST + currentPassword := c.Request().PostFormValue("currentPassword") + secretPhrase := c.Request().PostFormValue("secretPhrase") + data.CurrentPassword = currentPassword + data.SecretPhrase = secretPhrase + + if len(currentPassword) == 0 { + data.ErrorCurrentPassword = "This field is required" + return c.Render(http.StatusOK, "settings.secret-phrase", data) + } + + if !govalidator.RuneLength(secretPhrase, "3", "50") { + data.ErrorSecretPhrase = "secret phrase must have between 3 and 50 characters" + return c.Render(http.StatusOK, "settings.secret-phrase", data) + } + + if !authUser.CheckPassword(db, currentPassword) { + data.ErrorCurrentPassword = "Invalid password" + return c.Render(http.StatusOK, "settings.secret-phrase", data) + } + + authUser.SecretPhrase = database.EncryptedString(secretPhrase) + authUser.DoSave(db) + + db.CreateSecurityLog(authUser.ID, database.ChangeSecretPhraseSecurityLog) + return c.Render(http.StatusFound, "flash", FlashResponse{Message: "Secret phrase changed successfully", Redirect: c.Request().Referer()}) +}