Add logs for bootstrap admin
This commit is contained in:
@@ -16,6 +16,9 @@ import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
const BootstrapUserUsername = "admin"
|
||||
const BootstrapUserPassword = "admin"
|
||||
|
||||
func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, db *sql.DB) {
|
||||
siteRepository := cachedrepo.NewCachedSiteRepository(database.NewSQLiteSiteRepository(db))
|
||||
deploymentRepository := database.NewSQLiteDeploymentRepository(db)
|
||||
@@ -25,20 +28,21 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
|
||||
if uList, err := userRepository.GetAllUsers(); err != nil {
|
||||
log.Printf("Warning checking users: %v", err)
|
||||
} else if len(uList) == 0 {
|
||||
pwd := "admin"
|
||||
pwd := BootstrapUserUsername
|
||||
hashedPassword, err := security.HashPassword(pwd)
|
||||
if err != nil {
|
||||
log.Println("Error hashing default user password: ", err)
|
||||
}
|
||||
defaultUser := models.User{
|
||||
Name: "admin",
|
||||
Name: BootstrapUserPassword,
|
||||
HashedPassword: hashedPassword,
|
||||
Role: "admin",
|
||||
}
|
||||
if err := userRepository.CreateUser(&defaultUser); err != nil {
|
||||
log.Printf("Warning creating default user: %v", err)
|
||||
} else {
|
||||
log.Printf("Created default user: admin/admin")
|
||||
log.Printf("Created default user: username '%s' with password '%s'", BootstrapUserUsername, pwd)
|
||||
log.Printf("Please log in and change the default password immediately")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user