- Move ORM models from internal/model to pkg/model organized by module (auth/k8s/registry) - Add authentication module with login, user management handlers - Update all import paths to use new model locations - Add frontend auth pages (Login, UserManagement) and authStore - Remove deprecated internal/model/model.go
42 lines
887 B
Go
42 lines
887 B
Go
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
|
|
}
|