2020-04-17 19:07:19 +01:00

32 lines
799 B
Go

package root
import (
"fmt"
"github.com/TicketsBot/GoPanel/config"
"github.com/TicketsBot/GoPanel/utils"
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin"
"net/url"
)
func LoginHandler(ctx *gin.Context) {
store := sessions.Default(ctx)
if store == nil {
return
}
defer store.Save()
if utils.IsLoggedIn(store) {
ctx.Redirect(302, config.Conf.Server.BaseUrl)
} else {
redirect := url.QueryEscape(config.Conf.Oauth.RedirectUri)
var guildsScope string
if _, noGuilds := ctx.GetQuery("noguilds"); !noGuilds {
guildsScope = "+guilds"
}
ctx.Redirect(302, fmt.Sprintf("https://discordapp.com/oauth2/authorize?response_type=code&redirect_uri=%s&scope=identify%s&client_id=%d&state=%s", redirect, guildsScope, config.Conf.Oauth.Id, ctx.Query("state")))
}
}