diff --git a/internal/api/controller/user/register.go b/internal/api/controller/user/register.go index 28ee89e26..b6d62d899 100644 --- a/internal/api/controller/user/register.go +++ b/internal/api/controller/user/register.go @@ -12,27 +12,12 @@ import ( "github.com/harness/gitness/types" ) -type RegisterInput struct { - Email string `json:"email"` - DisplayName string `json:"display_name"` - UID string `json:"uid"` - Password string `json:"password"` -} - /* * Register creates a new user and returns a new session token on success. * This differs from the Create method as it doesn't require auth, but has limited * functionalities (unable to create admin user for example). */ func (c *Controller) Register(ctx context.Context, in *CreateInput, config *types.Config) (*types.TokenResponse, error) { - // TODO: allow to configure if open register is allowed. - - signUpFlag := config.AllowSignUp - - if !signUpFlag { - return nil, fmt.Errorf("user sign-up is disabled") - } - user, err := c.CreateNoAuth(ctx, &CreateInput{ UID: in.UID, Email: in.Email, diff --git a/internal/api/handler/account/register.go b/internal/api/handler/account/register.go index 7b74d436e..7a7d79f38 100644 --- a/internal/api/handler/account/register.go +++ b/internal/api/handler/account/register.go @@ -6,6 +6,7 @@ package account import ( "encoding/json" + "github.com/harness/gitness/types" "net/http" "github.com/harness/gitness/internal/api/controller/user" @@ -18,13 +19,19 @@ func HandleRegister(userCtrl *user.Controller, config *types.Config) http.Handle return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - in := new(user.RegisterInput) + in := new(user.CreateInput) err := json.NewDecoder(r.Body).Decode(in) if err != nil { render.BadRequestf(w, "Invalid request body: %s.", err) return } + signUpFlag := config.AllowSignUp + if !signUpFlag { + render.BadRequestf(w, "User sign-up is disabled.") + return + } + tokenResponse, err := userCtrl.Register(ctx, in, config) if err != nil { render.TranslatedUserError(w, err) diff --git a/internal/api/openapi/account.go b/internal/api/openapi/account.go index cf01db147..d8deef248 100644 --- a/internal/api/openapi/account.go +++ b/internal/api/openapi/account.go @@ -21,7 +21,7 @@ type loginRequest struct { // request to register an account. type registerRequest struct { - user.RegisterInput + user.CreateInput } // helper function that constructs the openapi specification