diff --git a/internal/api/controller/user/login.go b/internal/api/controller/user/login.go index 9779fbf6c..bbbcda797 100644 --- a/internal/api/controller/user/login.go +++ b/internal/api/controller/user/login.go @@ -23,8 +23,8 @@ import ( ) type LoginInput struct { - Username string `json:"username"` - Password string `json:"password"` + LoginIdentifier string `json:"login_identifier"` + Password string `json:"password"` } /* @@ -34,15 +34,15 @@ func (c *Controller) Login(ctx context.Context, session *auth.Session, in *LoginInput) (*types.TokenResponse, error) { // no auth check required, password is used for it. - user, err := findUserFromUID(ctx, c.principalStore, in.Username) + user, err := findUserFromUID(ctx, c.principalStore, in.LoginIdentifier) if errors.Is(err, store.ErrResourceNotFound) { - user, err = findUserFromEmail(ctx, c.principalStore, in.Username) + user, err = findUserFromEmail(ctx, c.principalStore, in.LoginIdentifier) } // always return not found for security reasons. if err != nil { log.Ctx(ctx).Debug().Err(err). - Str("user_uid", in.Username). + Str("user_uid", in.LoginIdentifier). Msgf("failed to retrieve user during login.") return nil, usererror.ErrNotFound } diff --git a/internal/api/controller/user/register.go b/internal/api/controller/user/register.go index 9323a8e82..b5506c72b 100644 --- a/internal/api/controller/user/register.go +++ b/internal/api/controller/user/register.go @@ -14,8 +14,8 @@ import ( type RegisterInput struct { Email string `json:"email"` - DisplayName string `json:"displayname"` - Username string `json:"username"` + DisplayName string `json:"display_name"` + UID string `json:"uid"` Password string `json:"password"` } @@ -24,10 +24,15 @@ type RegisterInput struct { * 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) (*types.TokenResponse, error) { +func (c *Controller) Register(ctx context.Context, in *RegisterInput) (*types.TokenResponse, error) { // TODO: allow to configure if open register is allowed. - user, err := c.CreateNoAuth(ctx, in, false) + user, err := c.CreateNoAuth(ctx, &CreateInput{ + UID: in.UID, + Email: in.Email, + DisplayName: in.DisplayName, + Password: in.Password, + }, false) if err != nil { return nil, fmt.Errorf("failed to create user: %w", err) } diff --git a/internal/api/handler/account/register.go b/internal/api/handler/account/register.go index 4392b047f..2ff1b5faa 100644 --- a/internal/api/handler/account/register.go +++ b/internal/api/handler/account/register.go @@ -25,12 +25,7 @@ func HandleRegister(userCtrl *user.Controller) http.HandlerFunc { return } - tokenResponse, err := userCtrl.Register(ctx, &user.CreateInput{ - UID: in.Username, - Email: in.Email, - DisplayName: in.DisplayName, - Password: in.Password, - }) + tokenResponse, err := userCtrl.Register(ctx, in) if err != nil { render.TranslatedUserError(w, err) return