|
@@ -24,7 +24,10 @@ const CurrentUserName = "userName"
|
|
|
// Login 用户登录
|
|
|
func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SystemUserResponse, error) {
|
|
|
systemUser := &model.SystemUser{}
|
|
|
- if err := s.DB.Where("name = ?", req.Name).Find(systemUser).Error; err != nil {
|
|
|
+ if err := s.DB.Where("name = ?", req.Name).
|
|
|
+ Where("is_delete = ?", pasturePb.IsShow_Ok).
|
|
|
+ Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
|
+ Find(systemUser).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
@@ -36,6 +39,12 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
|
|
|
return nil, xerr.Customf("该账号已被禁用,请联系管理员")
|
|
|
}
|
|
|
|
|
|
+ systemRole := &model.SystemRole{Id: systemUser.RoleId}
|
|
|
+ if err := s.DB.Where("is_show = ? and is_delete = ?", pasturePb.IsShow_Ok, pasturePb.IsShow_Ok).
|
|
|
+ First(systemRole).Error; err != nil {
|
|
|
+ zaplog.Error("Login", zap.Any("systemRole", err))
|
|
|
+ }
|
|
|
+
|
|
|
jwtToken := jwt.NewJWTTokenGen(s.Cfg.AppName, s.Cfg.JwtTokenKeyConfig.PrivateKey)
|
|
|
token, err := jwtToken.GenerateToken(systemUser.Name, s.Cfg.JwtExpireTime)
|
|
|
if err != nil {
|
|
@@ -52,9 +61,9 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
|
|
|
Data: &pasturePb.SystemUserData{
|
|
|
AccessToken: token,
|
|
|
Expires: expires,
|
|
|
- RefreshToken: expires,
|
|
|
+ RefreshToken: token,
|
|
|
Username: systemUser.Name,
|
|
|
- Roles: []string{"admin"},
|
|
|
+ Roles: []string{systemRole.Name},
|
|
|
Avatar: systemUser.Avatar,
|
|
|
},
|
|
|
}, nil
|
|
@@ -320,11 +329,12 @@ func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUs
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
// 获取用户菜单
|
|
|
- systemMenu := &model.SystemMenu{}
|
|
|
+ systemMenuList := make([]*model.SystemMenu, 0)
|
|
|
if err = s.DB.Table(fmt.Sprintf("%s as a", new(model.SystemRoleMenu).TableName())).
|
|
|
+ Select("b.*").
|
|
|
Joins("LEFT JOIN system_menu AS b ON a.menu_id = b.id").
|
|
|
Where("a.role_id = ? and b.is_delete = ?", systemRole.Id, pasturePb.IsShow_Ok).
|
|
|
- Find(&systemMenu).Error; err != nil {
|
|
|
+ Find(&systemMenuList).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
@@ -332,7 +342,7 @@ func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUs
|
|
|
return &pasturePb.SystemUserMenuTreeResponse{
|
|
|
Code: http.StatusOK,
|
|
|
Message: "ok",
|
|
|
- Data: nil,
|
|
|
+ Data: model.SystemMenuSlice(systemMenuList).ToTree(),
|
|
|
}, nil
|
|
|
}
|
|
|
|