package auth import ( "context" "log" auth "gitea.loveuer.com/loveuer/cluster/pkg/model/auth" "gitea.loveuer.com/loveuer/cluster/pkg/tool" "gorm.io/gorm" ) func Init(ctx context.Context, db *gorm.DB) error { if err := db.AutoMigrate(&auth.User{}); err != nil { return err } var count int64 if err := db.Model(&auth.User{}).Count(&count).Error; err != nil { return err } if count == 0 { defaultAdmin := &auth.User{ Username: "admin", Password: tool.NewPassword("cluster"), Email: "admin@cluster.local", Nickname: "Administrator", Role: "admin", Status: "active", Permissions: "registry_read,registry_write,cluster_read,cluster_write", } if err := db.Create(defaultAdmin).Error; err != nil { return err } log.Println("[Auth] Default admin user created: username=admin, password=cluster") } return nil }