MCPcopy Index your code
hub / github.com/dnote/dnote / userResetPasswordCmd

Function userResetPasswordCmd

pkg/server/cmd/user.go:118–152  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

116}
117
118func userResetPasswordCmd(args []string) {
119 fs := setupFlagSet("reset-password", "dnote-server user reset-password")
120
121 email := fs.String("email", "", "User email address (required)")
122 password := fs.String("password", "", "New password (required)")
123 dbPath := fs.String("dbPath", "", "Path to SQLite database file (env: DBPath, default: $XDG_DATA_HOME/dnote/server.db)")
124
125 fs.Parse(args)
126
127 requireString(fs, *email, "email")
128 requireString(fs, *password, "password")
129
130 a, cleanup := createApp(fs, *dbPath)
131 defer cleanup()
132
133 // Find the user
134 user, err := a.GetUserByEmail(*email)
135 if err != nil {
136 if errors.Is(err, app.ErrNotFound) {
137 fmt.Printf("Error: user with email %s not found\n", *email)
138 } else {
139 log.ErrorWrap(err, "finding user")
140 }
141 os.Exit(1)
142 }
143
144 // Update the password
145 if err := app.UpdateUserPassword(a.DB, user, *password); err != nil {
146 log.ErrorWrap(err, "updating password")
147 os.Exit(1)
148 }
149
150 fmt.Printf("Password reset successfully\n")
151 fmt.Printf("Email: %s\n", *email)
152}
153
154func userListCmd(args []string, output io.Writer) {
155 fs := setupFlagSet("list", "dnote-server user list")

Callers 2

TestUserResetPasswordCmdFunction · 0.85
userCmdFunction · 0.85

Calls 6

ErrorWrapFunction · 0.92
UpdateUserPasswordFunction · 0.92
setupFlagSetFunction · 0.85
requireStringFunction · 0.85
createAppFunction · 0.85
GetUserByEmailMethod · 0.80

Tested by 1

TestUserResetPasswordCmdFunction · 0.68