has_guilds key
This commit is contained in:
parent
740f058a18
commit
24a848a575
@ -80,17 +80,15 @@ func CallbackHandler(ctx *gin.Context) {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRedirect(ctx)
|
|
||||||
|
|
||||||
// Cache guilds because Discord takes like 2 whole seconds to return then
|
|
||||||
go func() {
|
|
||||||
var guilds []guild.Guild
|
var guilds []guild.Guild
|
||||||
err, _ = userEndpoint.CurrentUserGuilds.Request(store, nil, nil, &guilds)
|
err, _ = userEndpoint.CurrentUserGuilds.Request(store, nil, nil, &guilds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
handleRedirect(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store.Set("has_guilds", true)
|
||||||
|
|
||||||
var wrappedGuilds []database.UserGuild
|
var wrappedGuilds []database.UserGuild
|
||||||
|
|
||||||
// endpoint's partial guild doesn't include ownerid
|
// endpoint's partial guild doesn't include ownerid
|
||||||
@ -112,7 +110,8 @@ func CallbackHandler(ctx *gin.Context) {
|
|||||||
if err := dbclient.Client.UserGuilds.Set(currentUser.Id, wrappedGuilds); err != nil {
|
if err := dbclient.Client.UserGuilds.Set(currentUser.Id, wrappedGuilds); err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
handleRedirect(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRedirect(ctx *gin.Context) {
|
func handleRedirect(ctx *gin.Context) {
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
package root
|
package root
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/TicketsBot/GoPanel/config"
|
"github.com/TicketsBot/GoPanel/config"
|
||||||
"github.com/gin-gonic/contrib/sessions"
|
"github.com/gin-gonic/contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IndexHandler(ctx *gin.Context) {
|
func IndexHandler(ctx *gin.Context) {
|
||||||
store := sessions.Default(ctx)
|
store := sessions.Default(ctx)
|
||||||
|
|
||||||
|
if _, hasGuilds := store.Get("has_guilds").(bool); !hasGuilds {
|
||||||
|
redirect := url.QueryEscape(config.Conf.Oauth.RedirectUri)
|
||||||
|
ctx.Redirect(302, fmt.Sprintf("https://discordapp.com/oauth2/authorize?response_type=code&redirect_uri=%s&scope=identify+guilds&client_id=%d&state=%s", redirect, config.Conf.Oauth.Id, ctx.Query("state")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ctx.HTML(200, "main/index", gin.H{
|
ctx.HTML(200, "main/index", gin.H{
|
||||||
"name": store.Get("name").(string),
|
"name": store.Get("name").(string),
|
||||||
"baseurl": config.Conf.Server.BaseUrl,
|
"baseurl": config.Conf.Server.BaseUrl,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user