Skip to content

Commit

Permalink
Merge pull request #312 from systemli/Add-command-to-change-user-pass…
Browse files Browse the repository at this point in the history
…word

✨Add command to change user password
  • Loading branch information
0x46616c6b authored May 2, 2024
2 parents 803b27b + 76bb7a5 commit a0c60a6
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 a0c60a6

Please sign in to comment.