From c973b5c8ba55a49b39ed61b3a97a6886e0fd9005 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 8 Jul 2022 03:00:05 -0600 Subject: [PATCH] Ensuring all Render calls are using server.Context --- accounts/routes.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/accounts/routes.go b/accounts/routes.go index e12bf45..570f813 100644 --- a/accounts/routes.go +++ b/accounts/routes.go @@ -113,11 +113,12 @@ func (s *Service) LoginPOST(c echo.Context) error { // LoginAuthPOST ... func (s *Service) LoginAuthPOST(c echo.Context) error { + gctx := c.(*server.Context) form := &LoginForm{} if err := form.Validate(c, s.fetch); err != nil { switch err.(type) { case validate.InputErrors: - return c.Render(http.StatusOK, "login.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "login.html", gobwebs.Map{ "errors": err, "form": form, }) @@ -127,7 +128,6 @@ func (s *Service) LoginAuthPOST(c echo.Context) error { } } - gctx := c.(*server.Context) UserLogin(c, form.user.GetID()) UpdateLastLogin(gctx.Server.DB, form.user) @@ -152,7 +152,7 @@ func (s *Service) LoginEmailPOST(c echo.Context) error { if err := form.Validate(c); err != nil { switch err.(type) { case validate.InputErrors: - return c.Render(http.StatusOK, "login_email.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "login_email.html", gobwebs.Map{ "errors": err, "form": form, }) @@ -275,11 +275,12 @@ func (s *Service) ChangePassword(c echo.Context) error { // ChangePasswordPOST changes the password for an authenticated user func (s *Service) ChangePasswordPOST(c echo.Context) error { + gctx := c.(*server.Context) form := &ChangePasswordForm{} if err := form.Validate(c); err != nil { switch err.(type) { case validate.InputErrors: - return c.Render(http.StatusOK, "change_password.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "change_password.html", gobwebs.Map{ "errors": err, "form": form, }) @@ -289,7 +290,6 @@ func (s *Service) ChangePasswordPOST(c echo.Context) error { } } - gctx := c.(*server.Context) user := gctx.User user.SetPassword(form.NPassword) if err := s.fetch.WritePassword(gctx.Server.DB, user); err != nil { @@ -305,7 +305,7 @@ func (s *Service) ChangePasswordPOST(c echo.Context) error { return c.Redirect(http.StatusMovedPermanently, next) } - return c.Render(http.StatusOK, "change_password.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "change_password.html", gobwebs.Map{ "form": form, }) } @@ -339,7 +339,7 @@ func (s *Service) ForgotPasswordPOST(c echo.Context) error { if err := form.Validate(c); err != nil { switch err.(type) { case validate.InputErrors: - return c.Render(http.StatusOK, "forgot_password.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "forgot_password.html", gobwebs.Map{ "errors": err, "form": form, }) @@ -492,7 +492,7 @@ func (s *Service) ForgotPasswordConfPOST(c echo.Context) error { if err := form.Validate(c); err != nil { switch err.(type) { case validate.InputErrors: - return c.Render(http.StatusOK, "forgot_password_conf.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "forgot_password_conf.html", gobwebs.Map{ "errors": err, "form": form, "user": user, @@ -606,7 +606,7 @@ func (s *Service) UpdateEmailPOST(c echo.Context) error { if err := form.Validate(c); err != nil { switch err.(type) { case validate.InputErrors: - return c.Render(http.StatusOK, "update_email.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "update_email.html", gobwebs.Map{ "errors": err, "form": form, }) @@ -624,7 +624,7 @@ func (s *Service) UpdateEmailPOST(c echo.Context) error { } else { // Email already exists in the system nerr := fmt.Errorf("This email is currently registered to an existing account") - return c.Render(http.StatusOK, "update_email.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "update_email.html", gobwebs.Map{ "errors": validate.GetInputErrors([]error{nerr}), "form": form, }) @@ -675,7 +675,7 @@ func (s *Service) UpdateEmailPOST(c echo.Context) error { if pid != 0 { // Email already exists in pending email change nerr := fmt.Errorf("This email is currently pending confirmation for another account") - return c.Render(http.StatusOK, "update_email.html", gobwebs.Map{ + return gctx.Render(http.StatusOK, "update_email.html", gobwebs.Map{ "errors": validate.GetInputErrors([]error{nerr}), "form": form, }) -- 2.45.2