Invite button
This commit is contained in:
parent
1433521855
commit
83193f934e
33
app/http/endpoints/api/whitelabelget.go
Normal file
33
app/http/endpoints/api/whitelabelget.go
Normal file
@ -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),
|
||||
})
|
||||
}
|
||||
}
|
@ -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,
|
@ -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 {
|
||||
|
@ -26,13 +26,20 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-2 pr-1">
|
||||
<div class="col-md-1">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-fill" type="submit"><i class="fas fa-paper-plane"></i>
|
||||
<button class="btn btn-primary btn-fill" type="submit">
|
||||
<i class="fas fa-paper-plane"></i>
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button class="btn btn-primary btn-fill" id="invite" type="button">
|
||||
<i class="fas fa-plus"></i>
|
||||
Generate Invite Link
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -45,7 +52,22 @@
|
||||
<div style="position: absolute; right: 10px" id="toast-container">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// invite button
|
||||
document.getElementById('invite').addEventListener('click', async () => {
|
||||
// get bot ID
|
||||
const res = await axios.get('/user/whitelabel');
|
||||
if (res.status !== 200 || !res.data.success) {
|
||||
showToast('Error', res.data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
const inviteUrl = 'https://discord.com/oauth2/authorize?client_id=' + res.data.id + '&scope=bot&permissions=805825648';
|
||||
|
||||
window.open(inviteUrl, '_blank');
|
||||
}, false);
|
||||
</script>
|
||||
|
||||
<script>
|
||||
async function updateSettings() {
|
||||
@ -63,4 +85,5 @@
|
||||
showToast('Success', `Started tickets whitelabel on ${res.data.bot.username}#${res.data.bot.discriminator}`);
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
{{end}}
|
Loading…
x
Reference in New Issue
Block a user