| 116 | } |
| 117 | |
| 118 | func 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 | |
| 154 | func userListCmd(args []string, output io.Writer) { |
| 155 | fs := setupFlagSet("list", "dnote-server user list") |