diff --git a/server/internal/adapter/http/user.go b/server/internal/adapter/http/user.go index ba7452d0ec..3f351ad4b1 100644 --- a/server/internal/adapter/http/user.go +++ b/server/internal/adapter/http/user.go @@ -2,10 +2,7 @@ package http import ( "context" - "errors" - "github.com/reearth/reearth/server/internal/adapter" - "github.com/reearth/reearth/server/pkg/id" "github.com/reearth/reearthx/account/accountdomain" "github.com/reearth/reearthx/account/accountdomain/user" "github.com/reearth/reearthx/account/accountusecase/accountinterfaces" @@ -32,14 +29,14 @@ type SignupInput struct { Sub *string `json:"sub"` Secret *string `json:"secret"` UserID *accountdomain.UserID `json:"userId"` - WorkspaceID *accountdomain.WorkspaceID `json:"teamId"` - Name *string `json:"name"` - // Username is an alias of Name - Username *string `json:"username"` - Email *string `json:"email"` - Password *string `json:"password"` - Theme *user.Theme `json:"theme"` - Lang *language.Tag `json:"lang"` + WorkspaceID *accountdomain.WorkspaceID `json:"workspaceId"` + TeamID *accountdomain.WorkspaceID `json:"teamId"` // TeamID is an alias of WorkspaceID + Name string `json:"name"` + Username string `json:"username"` // ysername is an alias of Name + Email string `json:"email"` + Password string `json:"password"` + Theme *user.Theme `json:"theme"` + Lang *language.Tag `json:"lang"` } type CreateVerificationInput struct { @@ -51,13 +48,6 @@ type VerifyUserOutput struct { Verified bool `json:"verified"` } -type CreateUserInput struct { - Sub string `json:"sub"` - Secret string `json:"secret"` - UserID *id.UserID `json:"userId"` - WorkspaceID *accountdomain.WorkspaceID `json:"teamId"` -} - type SignupOutput struct { ID string `json:"id"` Name string `json:"name"` @@ -65,52 +55,43 @@ type SignupOutput struct { } func (c *UserController) Signup(ctx context.Context, input SignupInput) (SignupOutput, error) { - var u *user.User - var err error - - name := input.Name - if name == nil { - name = input.Username + if input.Name == "" && input.Username != "" { + input.Name = input.Username } - if name == nil { - name = input.Email + if input.WorkspaceID == nil && input.TeamID != nil { + input.WorkspaceID = input.TeamID } - if au := adapter.GetAuthInfo(ctx); au != nil { - var name2 string - if name != nil { - name2 = *name + if input.Sub != nil && *input.Sub != "" && input.Email != "" && input.Name != "" { + u, err := c.usecase.SignupOIDC(ctx, accountinterfaces.SignupOIDCParam{ + Name: input.Name, + Email: input.Email, + Sub: *input.Sub, + Secret: input.Secret, + }) + + if err != nil { + return SignupOutput{}, err } - u, err = c.usecase.SignupOIDC(ctx, accountinterfaces.SignupOIDCParam{ - Sub: au.Sub, - AccessToken: au.Token, - Issuer: au.Iss, - Email: au.Email, - Name: name2, - Secret: input.Secret, - User: accountinterfaces.SignupUserParam{ - UserID: input.UserID, - WorkspaceID: input.WorkspaceID, - Lang: input.Lang, - Theme: input.Theme, - }, - }) - } else if name != nil && input.Email != nil { - u, err = c.usecase.Signup(ctx, accountinterfaces.SignupParam{ - Name: *name, - Email: *input.Email, - Password: *input.Password, - Secret: input.Secret, - UserID: input.UserID, - WorkspaceID: input.WorkspaceID, - Lang: input.Lang, - Theme: input.Theme, - }) - } else { - err = errors.New("invalid params") + return SignupOutput{ + ID: u.ID().String(), + Name: u.Name(), + Email: u.Email(), + }, nil } + u, err := c.usecase.Signup(ctx, accountinterfaces.SignupParam{ + Name: input.Name, + Email: input.Email, + Password: input.Password, + Secret: input.Secret, + UserID: input.UserID, + WorkspaceID: input.WorkspaceID, + Lang: input.Lang, + Theme: input.Theme, + }) + if err != nil { return SignupOutput{}, err }