Logout redirect works.
This commit is contained in:
parent
253ffac472
commit
b214dbb108
1 changed files with 32 additions and 1 deletions
|
@ -122,7 +122,7 @@ func logoutRedirect(context *gin.Context) {
|
|||
} else {
|
||||
log.Println(err)
|
||||
}
|
||||
context.Redirect(http.StatusTemporaryRedirect, "/")
|
||||
context.Redirect(http.StatusTemporaryRedirect, "http://localhost:15995/")
|
||||
}
|
||||
|
||||
func authCallback(context *gin.Context) {
|
||||
|
@ -228,6 +228,36 @@ func dashboardDisplay(context *gin.Context) {
|
|||
context.Redirect(http.StatusTemporaryRedirect, "/")
|
||||
}
|
||||
|
||||
func isUserAutorized(context *gin.Context) {
|
||||
oauthTokenJSON, err := context.Cookie("discord-oauthtoken")
|
||||
log.Printf("Something something: %s", oauthTokenJSON)
|
||||
if err == nil {
|
||||
var oauthToken *oauth2.Token
|
||||
err := json.Unmarshal([]byte(oauthTokenJSON), &oauthToken)
|
||||
if err == nil {
|
||||
if oauthToken.Valid() {
|
||||
user := getDiscordUser(context, oauthToken)
|
||||
log.Printf("What the fuck: %v", user)
|
||||
is_logged_in := dbcommands.DatabaseUserLoggedIn(db, user.Id)
|
||||
log.Printf("Whyyyyyy: %v", is_logged_in)
|
||||
context.JSON(http.StatusOK, gin.H{
|
||||
"message": is_logged_in,
|
||||
})
|
||||
return
|
||||
} else {
|
||||
log.Println(err)
|
||||
}
|
||||
} else {
|
||||
log.Println(err)
|
||||
}
|
||||
} else {
|
||||
log.Println(err)
|
||||
}
|
||||
context.JSON(http.StatusOK, gin.H{
|
||||
"message": false,
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
db = dbcommands.InitializeDatabase()
|
||||
config = parseConfig("config.toml")
|
||||
|
@ -240,5 +270,6 @@ func main() {
|
|||
app.GET("/auth/callback", authCallback)
|
||||
app.GET("/logout", logoutRedirect)
|
||||
app.GET("/dashboard", dashboardDisplay)
|
||||
app.GET("/authorized", isUserAutorized)
|
||||
app.Run(":31337")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue