Skip to content

Commit

Permalink
✨Add command to change user password
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed May 2, 2024
1 parent 803b27b commit 76bb7a5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ var (
fmt.Printf("Deleted user %s\n", email)
},
}

userChangePasswordCmd = &cobra.Command{
Use: "password",
Short: "Change a user's password",
Run: func(cmd *cobra.Command, args []string) {
if email == "" {
log.Fatal("email is required")
}
if password == "" {
log.Fatal("password is required")
}

user, err := store.FindUserByEmail(email)
if err != nil {
log.WithError(err).Fatal("could not find user")
}

user.UpdatePassword(password)
if err := store.SaveUser(&user); err != nil {
log.WithError(err).Fatal("could not save user")
}

fmt.Printf("Changed password for user %s\n", email)
},
}
)

func init() {
Expand All @@ -81,4 +106,8 @@ func init() {

userCmd.AddCommand(userDeleteCmd)
userDeleteCmd.Flags().StringVar(&email, "email", "", "email address of the user")

userCmd.AddCommand(userChangePasswordCmd)
userChangePasswordCmd.Flags().StringVar(&email, "email", "", "email address of the user")
userChangePasswordCmd.Flags().StringVar(&password, "password", "", "new password of the user")
}

0 comments on commit 76bb7a5

Please sign in to comment.