mirror of
https://github.com/harness/drone.git
synced 2025-05-20 10:59:56 +08:00
[CODE-617]: Move disable logic to handler and remove todo for it
This commit is contained in:
parent
9fb093bad3
commit
e93e4500a0
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user