Added an option to specify demo user, will be created on startup if it does not exist

This commit is contained in:
2026-03-02 15:28:00 +01:00
parent 660c44992e
commit 78c777170b
6 changed files with 17 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"slices"
"strings"
"git.artlef.fr/PersonalLibraryManager/internal/config"
@@ -53,6 +54,11 @@ func CreateDefaultUsers(db *gorm.DB, config *config.Config) error {
usernames = append(usernames, splittedString[0])
usersPasswordMap[splittedString[0]] = splittedString[1]
}
if !slices.Contains(usernames, config.DemoUsername) {
usernames = append(usernames, config.DemoUsername)
usersPasswordMap[config.DemoUsername] = ""
}
var existingUsers []model.User
err := db.Where("name IN ?", usernames).Find(&existingUsers).Error