|
@@ -33,7 +33,8 @@ func (s *StoreEntry) Auth(ctx context.Context, auth *operationPb.UserAuthData) (
|
|
return nil, xerr.Customf("该账号已被禁用,请联系管理员")
|
|
return nil, xerr.Customf("该账号已被禁用,请联系管理员")
|
|
}
|
|
}
|
|
|
|
|
|
- token, err := jwt.GenerateToken(systemUser.Name, systemUser.Password)
|
|
|
|
|
|
+ jwtToken := jwt.NewJWTTokenGen(s.Cfg.AppName, s.Cfg.JwtTokenKeyConfig.PrivateKey)
|
|
|
|
+ token, err := jwtToken.GenerateToken(systemUser.Name, s.Cfg.JwtExpireTime)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
@@ -48,18 +49,28 @@ func (s *StoreEntry) Auth(ctx context.Context, auth *operationPb.UserAuthData) (
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (s *StoreEntry) GetUserName(ctx context.Context) (string, error) {
|
|
|
|
+ userNameInter := ctx.Value("userName")
|
|
|
|
+ if userNameInter == nil {
|
|
|
|
+ return "", xerr.Customf("cannot userName")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if userName, ok := userNameInter.(string); ok {
|
|
|
|
+ return userName, nil
|
|
|
|
+ } else {
|
|
|
|
+ return "", xerr.Customf("waring userName")
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// GetUserInfo 获取用户信息
|
|
// GetUserInfo 获取用户信息
|
|
func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error) {
|
|
func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error) {
|
|
systemUser := &model.SystemUser{}
|
|
systemUser := &model.SystemUser{}
|
|
- claims, err := jwt.ParseToken(token)
|
|
|
|
|
|
+ userName, err := s.GetUserName(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
- if claims.Username == "" {
|
|
|
|
- return nil, xerr.Custom("token解析失败")
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if err = s.DB.Where("name = ?", claims.Username).First(systemUser).Error; err != nil {
|
|
|
|
|
|
+ if err = s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -251,7 +262,7 @@ func (s *StoreEntry) IsShowSystemUser(ctx context.Context, req *operationPb.IsSh
|
|
// GetSystemUserPermissions 返回系统用户相关菜单权限
|
|
// GetSystemUserPermissions 返回系统用户相关菜单权限
|
|
func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context, token string) (*operationPb.SystemUserMenuPermissions, error) {
|
|
func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context, token string) (*operationPb.SystemUserMenuPermissions, error) {
|
|
// 解析token
|
|
// 解析token
|
|
- claims, err := jwt.ParseToken(token)
|
|
|
|
|
|
+ /*claims, err := jwt.ParseToken(token)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
@@ -274,8 +285,8 @@ func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context, token string)
|
|
systemRoles := make([]*model.SystemRole, 0)
|
|
systemRoles := make([]*model.SystemRole, 0)
|
|
if err = s.DB.Where("is_show = ?", operationPb.IsShow_OK).Find(&systemRoles, roleIds).Error; err != nil {
|
|
if err = s.DB.Where("is_show = ?", operationPb.IsShow_OK).Find(&systemRoles, roleIds).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }*/
|
|
|
|
+ systemRoles := make([]*model.SystemRole, 0)
|
|
systemAllPermissionsList := &SystemAllPermissionsList{
|
|
systemAllPermissionsList := &SystemAllPermissionsList{
|
|
PastureList: make([]*model.SystemGroupPasturePermissions, 0),
|
|
PastureList: make([]*model.SystemGroupPasturePermissions, 0),
|
|
MenuList: make([]*model.SystemMenuPermissions, 0),
|
|
MenuList: make([]*model.SystemMenuPermissions, 0),
|