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.
55 lines
1.6 KiB
55 lines
1.6 KiB
package sys
|
|
|
|
import (
|
|
"shop-api/global"
|
|
"shop-api/model/request"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 从Gin的Context中获取从jwt解析出来的用户UUID
|
|
func GetUserUuid(c *gin.Context) string {
|
|
if claims, exists := c.Get("claims"); !exists {
|
|
global.MG_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
|
|
return ""
|
|
} else {
|
|
waitUse := claims.(*request.UserClaims)
|
|
return waitUse.UUID
|
|
}
|
|
}
|
|
|
|
// 从Gin的Context中获取从jwt解析出来的用户UUID
|
|
func GetUserAppid(c *gin.Context) string {
|
|
if claims, exists := c.Get("claims"); !exists {
|
|
global.MG_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
|
|
return ""
|
|
} else {
|
|
waitUse := claims.(*request.UserClaims)
|
|
return waitUse.Appid
|
|
}
|
|
}
|
|
|
|
// 从Gin的Context中获取从jwt解析出来的用户账号
|
|
func GetUserName(c *gin.Context) string {
|
|
if claims, exists := c.Get("claims"); !exists {
|
|
global.MG_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
|
|
return ""
|
|
} else {
|
|
waitUse := claims.(*request.UserClaims)
|
|
return waitUse.Username
|
|
}
|
|
}
|
|
|
|
func getUserInfo(c *gin.Context) *request.UserClaims {
|
|
if claims, exists := c.Get("claims"); !exists {
|
|
global.MG_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
|
|
return nil
|
|
} else {
|
|
waitUse := claims.(*request.UserClaims)
|
|
return waitUse
|
|
}
|
|
}
|
|
|
|
func GetUA(c *gin.Context) string {
|
|
return c.GetHeader("User-Agent")
|
|
}
|
|
|