Skip to content

Commit

Permalink
Reset password implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorbin committed May 28, 2023
1 parent c315b99 commit 729ba4b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
9 changes: 9 additions & 0 deletions client/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
30 changes: 30 additions & 0 deletions cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Execute() error {
Short: "Manage your account password",
}
password.AddCommand(changePasswordCmd())
password.AddCommand(sendResetPasswordLink())
account.AddCommand(password)

// token
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/appclacks/go-types/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 729ba4b

Please sign in to comment.