diff options
author | 2024-03-23 14:05:05 -0700 | |
---|---|---|
committer | 2024-03-23 14:32:55 -0700 | |
commit | 3db3f9884fc06a03256a8c9c19880cb4b46e9a26 (patch) | |
tree | 8e8acc8cd8fec09187861f4dc1dc3ffa18f3cbd1 /internal/cli/create_admin.go | |
parent | ad1d349a0cde68a09a1c328479aa2937ce2c885e (diff) | |
download | v2-3db3f9884fc06a03256a8c9c19880cb4b46e9a26.tar.gz v2-3db3f9884fc06a03256a8c9c19880cb4b46e9a26.tar.zst v2-3db3f9884fc06a03256a8c9c19880cb4b46e9a26.zip |
cli: avoid misleading error message when creating an admin user
Diffstat (limited to '')
-rw-r--r-- | internal/cli/create_admin.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/internal/cli/create_admin.go b/internal/cli/create_admin.go index d45073f3..f8199819 100644 --- a/internal/cli/create_admin.go +++ b/internal/cli/create_admin.go @@ -12,17 +12,22 @@ import ( "miniflux.app/v2/internal/validator" ) -func createAdmin(store *storage.Storage) { +func createAdminUserFromEnvironmentVariables(store *storage.Storage) { + createAdminUser(store, config.Opts.AdminUsername(), config.Opts.AdminPassword()) +} + +func createAdminUserFromInteractiveTerminal(store *storage.Storage) { + username, password := askCredentials() + createAdminUser(store, username, password) +} + +func createAdminUser(store *storage.Storage, username, password string) { userCreationRequest := &model.UserCreationRequest{ - Username: config.Opts.AdminUsername(), - Password: config.Opts.AdminPassword(), + Username: username, + Password: password, IsAdmin: true, } - if userCreationRequest.Username == "" || userCreationRequest.Password == "" { - userCreationRequest.Username, userCreationRequest.Password = askCredentials() - } - if store.UserExists(userCreationRequest.Username) { slog.Info("Skipping admin user creation because it already exists", slog.String("username", userCreationRequest.Username), @@ -34,7 +39,12 @@ func createAdmin(store *storage.Storage) { printErrorAndExit(validationErr.Error()) } - if _, err := store.CreateUser(userCreationRequest); err != nil { + if user, err := store.CreateUser(userCreationRequest); err != nil { printErrorAndExit(err) + } else { + slog.Info("Created new admin user", + slog.String("username", user.Username), + slog.Int64("user_id", user.ID), + ) } } |