whitelabel middleware
This commit is contained in:
parent
7c1b4193cf
commit
f319143e16
@ -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 {
|
||||
|
@ -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 {
|
||||
|
39
app/http/middleware/verifywhitelabel.go
Normal file
39
app/http/middleware/verifywhitelabel.go
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user