Skip to content

bug: user password command not working #707

@rkcoder101

Description

@rkcoder101

Due passing of empty PasswordChangeView, password change does not happen via the CLI

func UserPasswordChangeCmd() *cobra.Command {
	var opts reset.PasswordChangeView

	cmd := &cobra.Command{
		Use:   "password",
		Short: "Reset user password by name or id",
		Long:  "Allows admin to reset the password for a specified user or select interactively if no username is provided.",
		Args:  cobra.MinimumNArgs(0),
		Run: func(cmd *cobra.Command, args []string) {
			var userId int64
			var err error
			resetView := &reset.PasswordChangeView{
				NewPassword:     opts.NewPassword,
				ConfirmPassword: opts.ConfirmPassword,
			}

			if len(args) > 0 {
				userId, err = api.GetUsersIdByName(args[0])
				if err != nil {
					log.Errorf("failed to get user id for '%s': %v", args[0], err)
					return
				}
				if userId == 0 {
					log.Errorf("User with name '%s' not found", args[0])
					return
				}
			} else {
				userId = prompt.GetUserIdFromUser()
			}

			reset.ChangePasswordView(resetView)

			err = api.ResetPassword(userId, opts)
			if err != nil {
				if isUnauthorizedError(err) {
					log.Error("Permission denied: Admin privileges are required to execute this command.")
				} else {
					log.Errorf("failed to reset user password: %v", err)
				}
			}
		},
	}
	return cmd
}

Note the empty opts getting passed to the API (err = api.ResetPassword(userId, opts))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions