You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

  1. package utils
  2. import (
  3. "gin-vue-admin/global"
  4. systemReq "gin-vue-admin/model/system/request"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // 从Gin的Context中获取从jwt解析出来的用户ID
  8. func GetUserID(c *gin.Context) uint {
  9. if claims, exists := c.Get("claims"); !exists {
  10. global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件!")
  11. return 0
  12. } else {
  13. waitUse := claims.(*systemReq.CustomClaims)
  14. return waitUse.ID
  15. }
  16. }
  17. // 从Gin的Context中获取从jwt解析出来的用户UUID
  18. func GetUserUuid(c *gin.Context) string {
  19. if claims, exists := c.Get("claims"); !exists {
  20. global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
  21. return ""
  22. } else {
  23. waitUse := claims.(*systemReq.CustomClaims)
  24. return waitUse.UUID.String()
  25. }
  26. }
  27. // 从Gin的Context中获取从jwt解析出来的用户角色id
  28. func GetUserAuthorityId(c *gin.Context) string {
  29. if claims, exists := c.Get("claims"); !exists {
  30. global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
  31. return ""
  32. } else {
  33. waitUse := claims.(*systemReq.CustomClaims)
  34. return waitUse.AuthorityId
  35. }
  36. }