Remove all HTML rendering.
This commit is contained in:
		
							parent
							
								
									b214dbb108
								
							
						
					
					
						commit
						7e3a8d1c81
					
				
					 7 changed files with 3 additions and 166 deletions
				
			
		| 
						 | 
				
			
			@ -94,22 +94,6 @@ func createDiscordOAuthConfig() *oauth2.Config {
 | 
			
		|||
	return config
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func loginDisplay(context *gin.Context) {
 | 
			
		||||
	oauthTokenString, err := context.Cookie("discord-oauthtoken")
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		var oauthToken *oauth2.Token
 | 
			
		||||
		err := json.Unmarshal([]byte(oauthTokenString), &oauthToken)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			if oauthToken.Valid() {
 | 
			
		||||
				context.Redirect(http.StatusTemporaryRedirect, "/dashboard")
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	context.HTML(http.StatusOK, "root.html", gin.H{
 | 
			
		||||
		"message": "Please log in.",
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func loginRedirect(context *gin.Context) {
 | 
			
		||||
	context.Redirect(302, oauthConfig.AuthCodeURL(context.GetString("state")))
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -131,9 +115,7 @@ func authCallback(context *gin.Context) {
 | 
			
		|||
	var err error
 | 
			
		||||
	oauthToken, err := oauthConfig.Exchange(context.Request.Context(), context.Query("code"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		context.HTML(http.StatusInternalServerError, "internalservererror.html", gin.H{
 | 
			
		||||
			"message": "internalservererror",
 | 
			
		||||
		})
 | 
			
		||||
		context.Redirect(http.StatusInternalServerError, "http://localhost:15995/")
 | 
			
		||||
	}
 | 
			
		||||
	oauthTokenJSON, _ := json.Marshal(oauthToken)
 | 
			
		||||
	context.SetCookie("discord-oauthtoken", string(oauthTokenJSON), 0, "", config.API.Domain, false, false)
 | 
			
		||||
| 
						 | 
				
			
			@ -152,14 +134,14 @@ func getDiscordUser(context *gin.Context, oauthToken *oauth2.Token) discordUser
 | 
			
		|||
		} else {
 | 
			
		||||
			responseMessage = response.Status
 | 
			
		||||
		}
 | 
			
		||||
		context.HTML(http.StatusInternalServerError, "internalservererror.html", gin.H{
 | 
			
		||||
		context.JSON(http.StatusInternalServerError, gin.H{
 | 
			
		||||
			"message": responseMessage,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	defer response.Body.Close()
 | 
			
		||||
	body, err := io.ReadAll(response.Body)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		context.HTML(http.StatusInternalServerError, "internalservererror.html", gin.H{
 | 
			
		||||
		context.JSON(http.StatusInternalServerError, gin.H{
 | 
			
		||||
			"message": err.Error(),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -263,9 +245,7 @@ func main() {
 | 
			
		|||
	config = parseConfig("config.toml")
 | 
			
		||||
	oauthConfig = createDiscordOAuthConfig()
 | 
			
		||||
	app := gin.Default()
 | 
			
		||||
	app.LoadHTMLGlob("src/templates/*.html")
 | 
			
		||||
	app.Static("/public", "./public")
 | 
			
		||||
	app.GET("/", loginDisplay)
 | 
			
		||||
	app.GET("/login", loginRedirect)
 | 
			
		||||
	app.GET("/auth/callback", authCallback)
 | 
			
		||||
	app.GET("/logout", logoutRedirect)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,25 +0,0 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
    <title>Bad Request!</title>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <meta name="description" content="Bad request trying to authenticate Discord oauth">
 | 
			
		||||
    <meta name="keywords" content="HTML, CSS, JavaScript">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
			
		||||
    <link rel="stylesheet" href="/public/css/style.css" />
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
    <div class="bg-gray-200">
 | 
			
		||||
        <div class="min-h-screen">
 | 
			
		||||
            <div class="container max-w-3xl pt-4 pb-4 space-y-4">
 | 
			
		||||
                <h1 class="text-left">Oops!</h1>
 | 
			
		||||
                <p class="text-lg">There was some problem with the authentication process...</p>
 | 
			
		||||
                <p>{{ .message }}</p>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,40 +0,0 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
    <title>Dashboard</title>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <meta name="keywords" content="HTML, CSS, JavaScript">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
			
		||||
    <link rel="stylesheet" href="/public/css/style.css" />
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
    <div class="bg-black">
 | 
			
		||||
        <div class="min-h-screen p-2 md:p-4">
 | 
			
		||||
            <div
 | 
			
		||||
                class="container max-w-3xl p-4 mx-auto space-y-2 font-mono text-white bg-primary min-w-xs md:space-y-4">
 | 
			
		||||
                <div class="p-2 bg-secondary md:p-4 ring-2 ring-secondary/80">
 | 
			
		||||
                    <div class="bg-primary ring-2 ring-primary/80">
 | 
			
		||||
                        <div
 | 
			
		||||
                            class="flex flex-col w-full h-full p-2 space-x-4 rounded-sm space-2 drop-shadow-md drop-shadow-accent">
 | 
			
		||||
                            <h1 class="text-md md:text-xl">> USER AUTHENTICATED</h1>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="p-2 bg-secondary md:p-4 ring-2 ring-secondary/80">
 | 
			
		||||
                    {{ template "userinfo.html" . }}
 | 
			
		||||
                </div>
 | 
			
		||||
                <a class="flex w-full p-2 font-mono text-lg md:p-4 md:text-2xl bg-secondary ring-2 ring-secondary/80 h-fit0 hover:bg-secondary/50"
 | 
			
		||||
                    href="logout">
 | 
			
		||||
                    <div class="w-full h-full text-center bg-primary">
 | 
			
		||||
                        <p class="drop-shadow-accent drop-shadow-md">Logout</p>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </a>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,25 +0,0 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
    <title>Internal Server Error!</title>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <meta name="description" content="Bad request trying to authenticate Discord oauth">
 | 
			
		||||
    <meta name="keywords" content="HTML, CSS, JavaScript">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
			
		||||
    <link rel="stylesheet" href="/public/css/style.css" />
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
    <div class="bg-gray-200">
 | 
			
		||||
        <div class="min-h-screen">
 | 
			
		||||
            <div class="container max-w-3xl pt-4 pb-4 space-y-4">
 | 
			
		||||
                <h1 class="text-left">Oops!</h1>
 | 
			
		||||
                <p class="text-lg">We experienced some kind of server error...</p>
 | 
			
		||||
                <p>{{ .message }}</p>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,34 +0,0 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
    <title>Hello!</title>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <meta name="keywords" content="HTML, CSS, JavaScript">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
			
		||||
    <link rel="stylesheet" href="/public/css/style.css" />
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
    <div class="bg-gray-200">
 | 
			
		||||
        <div class="min-h-screen px-4">
 | 
			
		||||
            <div class="container w-full max-w-3xl pt-4 pb-4 m-auto space-y-4">
 | 
			
		||||
                <h1 class="text-3xl text-center">Welcome!</h1>
 | 
			
		||||
                <div class="border-2 border-gray-900 border-solid bg-[#eeea] p-4">
 | 
			
		||||
                    <div class="flex flex-col m-auto text-lg text-left align-middle">
 | 
			
		||||
                        <div class="flex flex-col space-y-2">
 | 
			
		||||
                            <p>There really isn't much here yet, but you can log in with Discord.</p>
 | 
			
		||||
                            <a class="text-lg bg-blue-600 ring-2 ring-black" href="/login">
 | 
			
		||||
                                <div class="m-auto text-lg text-center text-white align-middle">
 | 
			
		||||
                                    Login to Discord
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </a>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,19 +0,0 @@
 | 
			
		|||
<div class="bg-primary ring-2 ring-primary/80">
 | 
			
		||||
    <div class="flex flex-row w-full h-full p-4 space-x-4 rounded-sm">
 | 
			
		||||
        <div class="md:min-w-fit md:min-h-fit md:max-w-fit md:max-h-fit max-w-32 max-h-32">
 | 
			
		||||
            <img class="fixed z-1 max-w-[96px] max-h-[96px] md:max-w-[128px] md:max-h-[128px]"
 | 
			
		||||
                src="https://cdn.discordapp.com/avatar-decoration-presets/{{ .Avatar_Decoration_Data.Asset }}.png" />
 | 
			
		||||
            <img class="max-w-[96px] max-h-[96px] mask-clip-border rounded-full md:max-w-[128px] md:max-h-[128px] drop-shadow-accent drop-shadow-md border-8 border-accent"
 | 
			
		||||
                src="https://cdn.discordapp.com/avatars/{{ .Id }}/{{ .Avatar }}.png" />
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="w-full m-auto drop-shadow-md drop-shadow-accent text-accent">
 | 
			
		||||
            <p class="text-xl md:text-3xl">
 | 
			
		||||
                {{ .Global_Name }}
 | 
			
		||||
            </p>
 | 
			
		||||
            <a class="ml-2 text-white text-md md:text-xl hover:text-gray-300" href="https://discord.com/users/{{ .Id }}"
 | 
			
		||||
                target="_blank">
 | 
			
		||||
                @{{ .Username }}
 | 
			
		||||
            </a>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
		Loading…
	
		Reference in a new issue