diff --git a/app/http/endpoints/api/whitelabelpost.go b/app/http/endpoints/api/whitelabelpost.go index 2d3d47f..1ee0e49 100644 --- a/app/http/endpoints/api/whitelabelpost.go +++ b/app/http/endpoints/api/whitelabelpost.go @@ -15,25 +15,6 @@ import ( func WhitelabelPost(ctx *gin.Context) { userId := ctx.Keys["userid"].(uint64) - premiumTier := rpc.PremiumClient.GetTierByUser(userId, false) - if premiumTier < premium.Whitelabel { - var isForced bool - for _, forced := range config.Conf.ForceWhitelabel { - if forced == userId { - isForced = true - break - } - } - - if !isForced { - ctx.JSON(402, gin.H{ - "success": false, - "error": "You must have the whitelabel premium tier", - }) - return - } - } - // Get token var data map[string]interface{} if err := ctx.BindJSON(&data); err != nil { diff --git a/app/http/endpoints/api/whitelabelstatuspost.go b/app/http/endpoints/api/whitelabelstatuspost.go index b19dc6c..e39720a 100644 --- a/app/http/endpoints/api/whitelabelstatuspost.go +++ b/app/http/endpoints/api/whitelabelstatuspost.go @@ -13,25 +13,6 @@ import ( func WhitelabelStatusPost(ctx *gin.Context) { userId := ctx.Keys["userid"].(uint64) - premiumTier := rpc.PremiumClient.GetTierByUser(userId, false) - if premiumTier < premium.Whitelabel { - var isForced bool - for _, forced := range config.Conf.ForceWhitelabel { - if forced == userId { - isForced = true - break - } - } - - if !isForced { - ctx.JSON(402, gin.H{ - "success": false, - "error": "You must have the whitelabel premium tier", - }) - return - } - } - // Get bot bot, err := database.Client.Whitelabel.GetByUserId(userId) if err != nil { diff --git a/app/http/middleware/verifywhitelabel.go b/app/http/middleware/verifywhitelabel.go new file mode 100644 index 0000000..3f09e9e --- /dev/null +++ b/app/http/middleware/verifywhitelabel.go @@ -0,0 +1,39 @@ +package middleware + +import ( + "fmt" + "github.com/TicketsBot/GoPanel/config" + "github.com/TicketsBot/GoPanel/rpc" + "github.com/TicketsBot/common/premium" + "github.com/gin-gonic/gin" +) + +func VerifyWhitelabel(isApi bool) func(ctx *gin.Context) { + return func(ctx *gin.Context) { + + userId := ctx.Keys["userid"].(uint64) + + if rpc.PremiumClient.GetTierByUser(userId, false) < premium.Whitelabel { + var isForced bool + for _, forced := range config.Conf.ForceWhitelabel { + if forced == userId { + isForced = true + break + } + } + + if !isForced { + if isApi { + ctx.AbortWithStatusJSON(402, gin.H{ + "success": false, + "error": "You must have the whitelabel premium tier", + }) + } else { + ctx.Redirect(302, fmt.Sprintf("%s/premium", config.Conf.Server.MainSite)) + ctx.Abort() + } + return + } + } + } +} diff --git a/app/http/server.go b/app/http/server.go index 2d0586e..d982f26 100644 --- a/app/http/server.go +++ b/app/http/server.go @@ -113,11 +113,16 @@ func StartServer() { { userGroup.GET("/guilds", api.GetGuilds) - userGroup.GET("/whitelabel", api.WhitelabelGet) - userGroup.GET("/whitelabel/errors", api.WhitelabelGetErrors) + { + whitelabelGroup := userGroup.Group("/whitelabel", middleware.VerifyWhitelabel(false)) + whitelabelApiGroup := userGroup.Group("/whitelabel", middleware.VerifyWhitelabel(true)) - userGroup.Group("/").Use(createLimiter(10, time.Minute)).POST("/whitelabel", api.WhitelabelPost) - userGroup.Group("/").Use(createLimiter(1, time.Second * 5)).POST("/whitelabel/status", api.WhitelabelStatusPost) + whitelabelGroup.GET("/", api.WhitelabelGet) + whitelabelApiGroup.GET("/errors", api.WhitelabelGetErrors) + + whitelabelApiGroup.Group("/").Use(createLimiter(10, time.Minute)).POST("/", api.WhitelabelPost) + whitelabelApiGroup.Group("/").Use(createLimiter(1, time.Second * 5)).POST("/status", api.WhitelabelStatusPost) + } } if err := router.Run(config.Conf.Server.Host); err != nil {