diff --git a/client/account.go b/client/account.go index 720f8f4..1ba0d05 100644 --- a/client/account.go +++ b/client/account.go @@ -15,3 +15,12 @@ func (c *Client) ChangeAccountPassword(ctx context.Context, payload apitypes.Cha } return result, nil } + +func (c *Client) AskResetPasswordLink(ctx context.Context, payload apitypes.ResetAccountPasswordLinkInput) (apitypes.Response, error) { + var result apitypes.Response + _, err := c.sendRequest(ctx, "/account/password/ask-reset", http.MethodPost, payload, &result, nil, NoAuth) + if err != nil { + return apitypes.Response{}, err + } + return result, nil +} diff --git a/cmd/account.go b/cmd/account.go index 9932ba8..8794ad1 100644 --- a/cmd/account.go +++ b/cmd/account.go @@ -14,6 +14,36 @@ import ( "github.com/spf13/cobra" ) +func sendResetPasswordLink() *cobra.Command { + var email string + var askResetPassword = &cobra.Command{ + Use: "send-reset-link", + Short: "Send a reset password link for this email", + Run: func(cmd *cobra.Command, args []string) { + client := buildClient() + ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout) + defer cancel() + payload := apitypes.ResetAccountPasswordLinkInput{ + Email: email, + } + result, err := client.AskResetPasswordLink(ctx, payload) + exitIfError(err) + t := tabby.New() + t.AddHeader("Messages") + for _, message := range result.Messages { + t.AddLine(message) + } + t.Print() + os.Exit(0) + }, + } + askResetPassword.PersistentFlags().StringVar(&email, "email", "", "Email") + err := askResetPassword.MarkPersistentFlagRequired("email") + exitIfError(err) + return askResetPassword + +} + func changePasswordCmd() *cobra.Command { var changePassword = &cobra.Command{ Use: "change", diff --git a/cmd/root.go b/cmd/root.go index f8013ea..096018f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -39,6 +39,7 @@ func Execute() error { Short: "Manage your account password", } password.AddCommand(changePasswordCmd()) + password.AddCommand(sendResetPasswordLink()) account.AddCommand(password) // token diff --git a/go.mod b/go.mod index c69212d..d33fde5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/appclacks/cli go 1.20 require ( - github.com/appclacks/go-types v0.0.0-20230510191813-4ccfbeee3e7c + github.com/appclacks/go-types v0.0.0-20230514202307-77b895c55c7e github.com/cheynewallace/tabby v1.1.1 github.com/spf13/cobra v1.5.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index adb597c..abd8547 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/appclacks/go-types v0.0.0-20230509204234-07f206f7c4af h1:Du12cHfa7Gvv github.com/appclacks/go-types v0.0.0-20230509204234-07f206f7c4af/go.mod h1:ULkbKlyVigBCY+eSEV0scorq+akwJlVbdnLI5xI8IwU= github.com/appclacks/go-types v0.0.0-20230510191813-4ccfbeee3e7c h1:3pByBZlbOlA23fFCDhWnh0UfCbLBlDzdjWOxHJ7QBF0= github.com/appclacks/go-types v0.0.0-20230510191813-4ccfbeee3e7c/go.mod h1:ULkbKlyVigBCY+eSEV0scorq+akwJlVbdnLI5xI8IwU= +github.com/appclacks/go-types v0.0.0-20230514202307-77b895c55c7e h1:bw0mnSpPTUEAMa1vGqAF/+fXA7RTCxoby/cIRg6ETy4= +github.com/appclacks/go-types v0.0.0-20230514202307-77b895c55c7e/go.mod h1:ULkbKlyVigBCY+eSEV0scorq+akwJlVbdnLI5xI8IwU= github.com/cheynewallace/tabby v1.1.1 h1:JvUR8waht4Y0S3JF17G6Vhyt+FRhnqVCkk8l4YrOU54= github.com/cheynewallace/tabby v1.1.1/go.mod h1:Pba/6cUL8uYqvOc9RkyvFbHGrQ9wShyrn6/S/1OYVys= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= diff --git a/vendor/github.com/appclacks/go-types/account.go b/vendor/github.com/appclacks/go-types/account.go index 9535c11..bcd608e 100644 --- a/vendor/github.com/appclacks/go-types/account.go +++ b/vendor/github.com/appclacks/go-types/account.go @@ -3,3 +3,7 @@ package types type ChangeAccountPasswordInput struct { NewPassword string `json:"new-password" description:"User new password" validate:"required,min=10,max=255"` } + +type ResetAccountPasswordLinkInput struct { + Email string `json:"email" validate:"required"` +} diff --git a/vendor/modules.txt b/vendor/modules.txt index ecf1193..7989e87 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/appclacks/go-types v0.0.0-20230510191813-4ccfbeee3e7c +# github.com/appclacks/go-types v0.0.0-20230514202307-77b895c55c7e ## explicit; go 1.19 github.com/appclacks/go-types # github.com/cheynewallace/tabby v1.1.1