mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-05-07 14:32:42 +08:00
30 lines
557 B
Go
30 lines
557 B
Go
package kernel
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/0xJacky/Nginx-UI/model"
|
|
"github.com/uozi-tech/cosy"
|
|
)
|
|
|
|
func InitUser(ctx context.Context) {
|
|
db := cosy.UseDB(ctx)
|
|
user := &model.User{}
|
|
db.Unscoped().Where("id = ?", 1).Find(user)
|
|
|
|
// if user is not found, create a new user
|
|
if user.ID == 0 {
|
|
db.Create(&model.User{
|
|
Model: model.Model{
|
|
ID: 1,
|
|
},
|
|
Name: "admin",
|
|
})
|
|
return
|
|
}
|
|
|
|
// if user is found, check if the user is deleted
|
|
// if the user is deleted, restore the user
|
|
db.Unscoped().Where("id = ?", 1).Update("deleted_at", nil)
|
|
}
|