From 83193f934e0e82a2c96536650ffc62dc986b0e4a Mon Sep 17 00:00:00 2001 From: Dot-Rar Date: Thu, 28 May 2020 20:29:56 +0100 Subject: [PATCH] Invite button --- app/http/endpoints/api/whitelabelget.go | 33 ++++++++++ .../api/{whitelabel.go => whitelabelpost.go} | 6 +- app/http/server.go | 4 +- public/templates/views/whitelabel.tmpl | 61 +++++++++++++------ 4 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 app/http/endpoints/api/whitelabelget.go rename app/http/endpoints/api/{whitelabel.go => whitelabelpost.go} (96%) diff --git a/app/http/endpoints/api/whitelabelget.go b/app/http/endpoints/api/whitelabelget.go new file mode 100644 index 0000000..449ae94 --- /dev/null +++ b/app/http/endpoints/api/whitelabelget.go @@ -0,0 +1,33 @@ +package api + +import ( + "github.com/TicketsBot/GoPanel/database" + "github.com/gin-gonic/gin" + "strconv" +) + +func WhitelabelGet(ctx *gin.Context) { + userId := ctx.Keys["userid"].(uint64) + + // Check if this is a different token + bot, err := database.Client.Whitelabel.GetByUserId(userId) + if err != nil { + ctx.JSON(500, gin.H{ + "success": false, + "error": err.Error(), + }) + return + } + + if bot.BotId == 0 { + ctx.JSON(404, gin.H{ + "success": false, + "error": "No bot found", + }) + } else { + ctx.JSON(200, gin.H{ + "success": true, + "id": strconv.FormatUint(bot.BotId, 10), + }) + } +} diff --git a/app/http/endpoints/api/whitelabel.go b/app/http/endpoints/api/whitelabelpost.go similarity index 96% rename from app/http/endpoints/api/whitelabel.go rename to app/http/endpoints/api/whitelabelpost.go index d195720..2d3d47f 100644 --- a/app/http/endpoints/api/whitelabel.go +++ b/app/http/endpoints/api/whitelabelpost.go @@ -12,7 +12,7 @@ import ( "github.com/rxdn/gdl/rest" ) -func WhitelabelHandler(ctx *gin.Context) { +func WhitelabelPost(ctx *gin.Context) { userId := ctx.Keys["userid"].(uint64) premiumTier := rpc.PremiumClient.GetTierByUser(userId, false) @@ -81,14 +81,14 @@ func WhitelabelHandler(ctx *gin.Context) { return } - if existing.Token == token { + /*if existing.Token == token { // Respond with 200 to prevent information disclosure attack ctx.JSON(200, gin.H{ "success": true, "bot": bot, }) return - } + }*/ if err = dbclient.Client.Whitelabel.Set(database.WhitelabelBot{ UserId: userId, diff --git a/app/http/server.go b/app/http/server.go index 98b34d9..ca792ac 100644 --- a/app/http/server.go +++ b/app/http/server.go @@ -109,7 +109,9 @@ func StartServer() { userGroup := router.Group("/user", middleware.AuthenticateToken) { userGroup.GET("/guilds", api.GetGuilds) - userGroup.POST("/whitelabel", api.WhitelabelHandler) + + userGroup.GET("/whitelabel", api.WhitelabelGet) + userGroup.POST("/whitelabel", api.WhitelabelPost) } if err := router.Run(config.Conf.Server.Host); err != nil { diff --git a/public/templates/views/whitelabel.tmpl b/public/templates/views/whitelabel.tmpl index 7cd65a7..2c52004 100644 --- a/public/templates/views/whitelabel.tmpl +++ b/public/templates/views/whitelabel.tmpl @@ -26,13 +26,20 @@
-
+
-
+
+ +
@@ -45,22 +52,38 @@
+ + + + - - {{end}} \ No newline at end of file