提交
This commit is contained in:
@@ -155,6 +155,19 @@ func GetCurrentUserID(c *gin.Context) uint64 {
|
||||
return userID.(uint64)
|
||||
}
|
||||
|
||||
// RequireFeature 功能授权检查中间件
|
||||
// 检查当前授权是否包含指定功能
|
||||
func RequireFeature(feature string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if !utils.HasFeature(feature) {
|
||||
utils.Forbidden(c, "当前授权不支持此功能: "+feature)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// GetCurrentUsername 从上下文获取当前用户名
|
||||
func GetCurrentUsername(c *gin.Context) string {
|
||||
username, exists := c.Get("username")
|
||||
|
||||
Reference in New Issue
Block a user