|
|
@@ -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),
|
|
|
+ )
|
|
|
}
|
|
|
}
|