This commit is contained in:
loveuer 2024-11-08 09:57:48 +08:00
parent 48e8d96726
commit cf7d098a5f
2 changed files with 16 additions and 3 deletions

View File

@ -94,3 +94,16 @@ func (u *Urbac) newPrivilege(ctx context.Context, code, label string, parent str
return p, nil
}
func (u *Urbac) newUser(target *model.User) (*model.User, error) {
result := u.store.Session().Create(target)
if result.Error != nil {
return nil, result.Error
}
if result.RowsAffected != 1 {
return nil, fmt.Errorf("invalid rows affected")
}
return target, nil
}

View File

@ -66,10 +66,10 @@ func New(opts ...Option) (*Urbac, error) {
Password: tool.NewPassword("123456"),
Status: model.StatusActive,
Nickname: "管理员",
RoleNames: []string{"admin"},
RoleNames: []string{rootRole.Code},
}
u.newUser()
_, err = u.newUser(rootUser)
return u, nil
return u, err
}