Logout redirect works.

This commit is contained in:
Ada Werefox 2025-04-23 10:23:18 -07:00
parent 253ffac472
commit b214dbb108

View file

@ -122,7 +122,7 @@ func logoutRedirect(context *gin.Context) {
} else { } else {
log.Println(err) log.Println(err)
} }
context.Redirect(http.StatusTemporaryRedirect, "/") context.Redirect(http.StatusTemporaryRedirect, "http://localhost:15995/")
} }
func authCallback(context *gin.Context) { func authCallback(context *gin.Context) {
@ -228,6 +228,36 @@ func dashboardDisplay(context *gin.Context) {
context.Redirect(http.StatusTemporaryRedirect, "/") 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() { func main() {
db = dbcommands.InitializeDatabase() db = dbcommands.InitializeDatabase()
config = parseConfig("config.toml") config = parseConfig("config.toml")
@ -240,5 +270,6 @@ func main() {
app.GET("/auth/callback", authCallback) app.GET("/auth/callback", authCallback)
app.GET("/logout", logoutRedirect) app.GET("/logout", logoutRedirect)
app.GET("/dashboard", dashboardDisplay) app.GET("/dashboard", dashboardDisplay)
app.GET("/authorized", isUserAutorized)
app.Run(":31337") app.Run(":31337")
} }