refactor: reorganize models to pkg/model and add authentication module
- 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
This commit is contained in:
41
internal/module/auth/auth.go
Normal file
41
internal/module/auth/auth.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user