feat: add run.ps1 script to start projects easily
add a powershell script that supports starting MES, WMS, WMSClient, Workstation and Dashboard projects with one command, includes build and run logic for backend services and npm dev for dashboard
This commit is contained in:
@@ -42,6 +42,11 @@ type UserInfoResp struct {
|
||||
PermissionCodes []string `json:"permissionCodes"`
|
||||
}
|
||||
|
||||
type ChangePasswordReq struct {
|
||||
OldPassword string `json:"oldPassword"`
|
||||
NewPassword string `json:"newPassword"`
|
||||
}
|
||||
|
||||
type permissionItem struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
@@ -148,6 +153,31 @@ func (s *Service) UserInfo(ctx context.Context, userId int) (UserInfoResp, error
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ChangePassword 当前登录用户修改自己的密码
|
||||
func (s *Service) ChangePassword(ctx context.Context, userId int, req ChangePasswordReq) error {
|
||||
if userId <= 0 {
|
||||
return errors.New("未登录")
|
||||
}
|
||||
if req.OldPassword == "" || req.NewPassword == "" {
|
||||
return errors.New("请输入旧密码与新密码")
|
||||
}
|
||||
if len(req.NewPassword) < 6 {
|
||||
return errors.New("新密码长度至少 6 位")
|
||||
}
|
||||
usr, err := s.ctx.EntClient.User.Get(ctx, userId)
|
||||
if err != nil {
|
||||
return errors.New("用户不存在")
|
||||
}
|
||||
if bcrypt.CompareHashAndPassword([]byte(usr.Password), []byte(req.OldPassword)) != nil {
|
||||
return errors.New("旧密码不正确")
|
||||
}
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.ctx.EntClient.User.UpdateOneID(userId).SetPassword(string(hash)).Exec(ctx)
|
||||
}
|
||||
|
||||
// ------ 用户 / 角色 / 权限 管理 ------
|
||||
|
||||
type UserReq struct {
|
||||
|
||||
@@ -33,14 +33,18 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
_ = s.ctx.EntClient.Role.Create().SetName(r.name).SetCode(r.code).SetPermissionCodes(codes).Exec(ctx)
|
||||
}
|
||||
|
||||
// 2. 超级管理员账号 admin / Hardman_2026
|
||||
if !s.ctx.EntClient.User.Query().Where(user.Username("admin")).ExistX(ctx) {
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte("Hardman_2026"), bcrypt.DefaultCost)
|
||||
adminRole, _ := s.ctx.EntClient.Role.Query().Where(role.Code("SUPER_ADMIN")).First(ctx)
|
||||
roleId := 0
|
||||
if adminRole != nil {
|
||||
roleId = adminRole.ID
|
||||
}
|
||||
// 2. 超级管理员账号 admin / Hardman_2026(对已存在的旧行做对齐,避免残留禁用状态)
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte("Hardman_2026"), bcrypt.DefaultCost)
|
||||
adminRole, _ := s.ctx.EntClient.Role.Query().Where(role.Code("SUPER_ADMIN")).First(ctx)
|
||||
roleId := 0
|
||||
if adminRole != nil {
|
||||
roleId = adminRole.ID
|
||||
}
|
||||
if s.ctx.EntClient.User.Query().Where(user.Username("admin")).ExistX(ctx) {
|
||||
_ = s.ctx.EntClient.User.Update().
|
||||
Where(user.Username("admin")).
|
||||
SetPassword(string(hash)).SetStatus("ENABLED").SetRoleId(roleId).Exec(ctx)
|
||||
} else {
|
||||
_ = s.ctx.EntClient.User.Create().
|
||||
SetUsername("admin").SetPassword(string(hash)).SetName("系统管理员").
|
||||
SetRoleId(roleId).SetStatus("ENABLED").Exec(ctx)
|
||||
|
||||
Reference in New Issue
Block a user