From 3b91785dff4f4caace5ace5b560fe3db92c28361 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Wed, 22 May 2024 23:33:46 +0530 Subject: [PATCH] feat: user registration kill switch --- server/auth/signup.go | 13 +++++++++++++ templates/auth/signup.tmpl | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/auth/signup.go b/server/auth/signup.go index 33d29c6..e836f18 100644 --- a/server/auth/signup.go +++ b/server/auth/signup.go @@ -7,6 +7,7 @@ import ( "github.com/gin-gonic/gin" "github.com/puni9869/pinmyblogs/internal/signup" "github.com/puni9869/pinmyblogs/models" + "github.com/puni9869/pinmyblogs/pkg/config" "github.com/puni9869/pinmyblogs/pkg/formbinding" "github.com/puni9869/pinmyblogs/pkg/logger" "github.com/puni9869/pinmyblogs/pkg/utils" @@ -30,6 +31,18 @@ func SignupGet(c *gin.Context) { func SignupPost(signUp signup.Service) gin.HandlerFunc { log := logger.NewLogger() return func(c *gin.Context) { + if !config.C.Authentication.EnableRegistration { + log. + WithField("isEnableRegistration", config.C.Authentication.EnableRegistration). + Warn("User registration is disabled globally.") + + c.HTML(http.StatusOK, "signup.tmpl", gin.H{ + "HasError": true, + "Error": "New account's registration is currently disabled.", + }) + c.Abort() + return + } form := middlewares.GetForm(c).(*forms.SignUpForm) ctx := middlewares.GetContext(c) diff --git a/templates/auth/signup.tmpl b/templates/auth/signup.tmpl index 83c1d06..d58cb96 100644 --- a/templates/auth/signup.tmpl +++ b/templates/auth/signup.tmpl @@ -5,8 +5,10 @@ pinmyblogs.com

Sign up for new account

-
-
+ +
+

{{.Error}}

+