summaryrefslogtreecommitdiff
path: root/internal/cli/create_admin.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/cli/create_admin.go26
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),
+ )
}
}