commit 5b736808e5cd0ea9a3f5088d5296a242ab9ceee9
parent 642ea22a429925c79dbaa0a07c873e6c2ffd9698
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 15 Dec 2023 02:08:08 -0500
cleanup
Diffstat:
1 file changed, 75 insertions(+), 74 deletions(-)
diff --git a/pkg/web/handlers/signup.go b/pkg/web/handlers/signup.go
@@ -94,95 +94,96 @@ func signupHandler(c echo.Context) error {
data.CaptchaID, data.CaptchaImg = captcha.New()
}
- if c.Request().Method == http.MethodPost {
- data.Username = strings.TrimSpace(c.Request().PostFormValue("username"))
- data.Password = c.Request().PostFormValue("password")
- data.RePassword = c.Request().PostFormValue("repassword")
- data.Pow = c.Request().PostFormValue("pow")
- captchaID := c.Request().PostFormValue("captcha_id")
- captchaInput := c.Request().PostFormValue("captcha")
- captchaInputImg := c.Request().PostFormValue("captcha_img")
- if !signupInfo.hasSolvedCaptcha {
- if err := hutils.CaptchaVerifyString(c, captchaID, captchaInput); err != nil {
- data.ErrCaptcha = err.Error()
- config.SignupFailed.Inc()
- return c.Render(http.StatusOK, "standalone.signup", data)
- }
- }
- data.Captcha = captchaInput
- data.CaptchaImg = captchaInputImg
-
- signupInfo.hasSolvedCaptcha = true
- data.HasSolvedCaptcha = signupInfo.hasSolvedCaptcha
- signupCache.SetD(signupToken, signupInfo)
-
- // verify POW
- if config.PowEnabled.IsTrue() {
- if !hutils.VerifyPow(data.Username, data.Pow, config.PowDifficulty) {
- data.ErrPow = "invalid proof of work"
- return c.Render(http.StatusOK, "standalone.signup", data)
- }
+ if c.Request().Method == http.MethodGet {
+ return c.Render(http.StatusOK, "standalone.signup", data)
+ }
+
+ // POST
+ data.Username = strings.TrimSpace(c.Request().PostFormValue("username"))
+ data.Password = c.Request().PostFormValue("password")
+ data.RePassword = c.Request().PostFormValue("repassword")
+ data.Pow = c.Request().PostFormValue("pow")
+ captchaID := c.Request().PostFormValue("captcha_id")
+ captchaInput := c.Request().PostFormValue("captcha")
+ captchaInputImg := c.Request().PostFormValue("captcha_img")
+ if !signupInfo.hasSolvedCaptcha {
+ if err := hutils.CaptchaVerifyString(c, captchaID, captchaInput); err != nil {
+ data.ErrCaptcha = err.Error()
+ config.SignupFailed.Inc()
+ return c.Render(http.StatusOK, "standalone.signup", data)
}
+ }
+ data.Captcha = captchaInput
+ data.CaptchaImg = captchaInputImg
- config.SignupSucceed.Inc()
+ signupInfo.hasSolvedCaptcha = true
+ data.HasSolvedCaptcha = signupInfo.hasSolvedCaptcha
+ signupCache.SetD(signupToken, signupInfo)
- // If SignupFakeEnabled is enabled, we always say the account was created, but we do not create it.
- if config.SignupFakeEnabled.IsTrue() {
- c.SetCookie(hutils.DeleteCookie(hutils.WaitCookieName))
- return c.Render(http.StatusOK, "flash", FlashResponse{"Your account has been created", "/login", "alert-success"})
+ // verify POW
+ if config.PowEnabled.IsTrue() {
+ if !hutils.VerifyPow(data.Username, data.Pow, config.PowDifficulty) {
+ data.ErrPow = "invalid proof of work"
+ return c.Render(http.StatusOK, "standalone.signup", data)
}
+ }
- // Fuck with kicked users. Prevent them from registering again.
- //authCookie, err := c.Cookie("auth-token")
- //if err == nil && authCookie.Value != "" {
- // return c.Render(http.StatusOK, "flash", FlashResponse{"Your account has been created", "/login", "alert-success"})
- //}
+ config.SignupSucceed.Inc()
- signupInfoEnc, _ := json.Marshal(signupInfo)
+ // If SignupFakeEnabled is enabled, we always say the account was created, but we do not create it.
+ if config.SignupFakeEnabled.IsTrue() {
+ c.SetCookie(hutils.DeleteCookie(hutils.WaitCookieName))
+ return c.Render(http.StatusOK, "flash", FlashResponse{"Your account has been created", "/login", "alert-success"})
+ }
- registrationDuration := time.Now().UnixMilli() - start
- newUser, errs := db.CreateUser(data.Username, data.Password, data.RePassword, registrationDuration, string(signupInfoEnc))
- if errs.HasError() {
- data.Errors = errs
- return c.Render(http.StatusOK, "standalone.signup", data)
- }
+ // Fuck with kicked users. Prevent them from registering again.
+ //authCookie, err := c.Cookie("auth-token")
+ //if err == nil && authCookie.Value != "" {
+ // return c.Render(http.StatusOK, "flash", FlashResponse{"Your account has been created", "/login", "alert-success"})
+ //}
- // Fuck with hellbanned users. New account also hellbanned
- if hasHBCookie {
- newUser.IsHellbanned = true
- newUser.DoSave(db)
- }
+ signupInfoEnc, _ := json.Marshal(signupInfo)
- invitationToken := c.Param("invitationToken")
- if invitationToken != "" {
- if invitation, err := db.GetUnusedInvitationByToken(invitationToken); err == nil {
- invitation.InviteeUserID = newUser.ID
- invitation.DoSave(db)
- }
+ registrationDuration := time.Now().UnixMilli() - start
+ newUser, errs := db.CreateUser(data.Username, data.Password, data.RePassword, registrationDuration, string(signupInfoEnc))
+ if errs.HasError() {
+ data.Errors = errs
+ return c.Render(http.StatusOK, "standalone.signup", data)
+ }
+
+ // Fuck with hellbanned users. New account also hellbanned
+ if hasHBCookie {
+ newUser.IsHellbanned = true
+ newUser.DoSave(db)
+ }
+
+ invitationToken := c.Param("invitationToken")
+ if invitationToken != "" {
+ if invitation, err := db.GetUnusedInvitationByToken(invitationToken); err == nil {
+ invitation.InviteeUserID = newUser.ID
+ invitation.DoSave(db)
}
+ }
- // If more than 10 users were created in the past minute, auto disable signup for the website
- if db.GetRecentUsersCount() > 10 {
- settings := db.GetSettings()
- settings.SignupEnabled = false
- settings.DoSave(db)
- config.SignupEnabled.SetFalse()
- if userNull, err := db.GetUserByUsername(config.NullUsername); err == nil {
- db.NewAudit(userNull, fmt.Sprintf("auto turn off signup"))
-
- // Display message in chat
- txt := fmt.Sprintf("auto turn off registrations")
- if err := db.CreateSysMsg(txt, txt, "", config.GeneralRoomID, userNull.ID); err != nil {
- logrus.Error(err)
- }
+ // If more than 10 users were created in the past minute, auto disable signup for the website
+ if db.GetRecentUsersCount() > 10 {
+ settings := db.GetSettings()
+ settings.SignupEnabled = false
+ settings.DoSave(db)
+ config.SignupEnabled.SetFalse()
+ if userNull, err := db.GetUserByUsername(config.NullUsername); err == nil {
+ db.NewAudit(userNull, fmt.Sprintf("auto turn off signup"))
+
+ // Display message in chat
+ txt := fmt.Sprintf("auto turn off registrations")
+ if err := db.CreateSysMsg(txt, txt, "", config.GeneralRoomID, userNull.ID); err != nil {
+ logrus.Error(err)
}
}
-
- c.SetCookie(hutils.DeleteCookie(hutils.WaitCookieName))
- return c.Render(http.StatusOK, "flash", FlashResponse{"Your account has been created", "/login", "alert-success"})
}
- return c.Render(http.StatusOK, "standalone.signup", data)
+ c.SetCookie(hutils.DeleteCookie(hutils.WaitCookieName))
+ return c.Render(http.StatusOK, "flash", FlashResponse{"Your account has been created", "/login", "alert-success"})
}
func SignalCss1(c echo.Context) error {