diff options
| author | Melonai <einebeere@gmail.com> | 2021-07-26 21:52:58 +0200 |
|---|---|---|
| committer | Melonai <einebeere@gmail.com> | 2021-07-26 21:53:36 +0200 |
| commit | 0ac82c133b78a14239beb9034380c44d95d4bad3 (patch) | |
| tree | 3ba65b4e3e5ceafaf2180ea697cc7794a07da669 /handlers/portgate.go | |
| parent | 7819a23171145e8a626e8357e88446817c8785dc (diff) | |
| download | portgate-0ac82c133b78a14239beb9034380c44d95d4bad3.tar.zst portgate-0ac82c133b78a14239beb9034380c44d95d4bad3.zip | |
Portgate pages and templates
Diffstat (limited to 'handlers/portgate.go')
| -rw-r--r-- | handlers/portgate.go | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/handlers/portgate.go b/handlers/portgate.go index 9d4f3ef..1cd9bb8 100644 --- a/handlers/portgate.go +++ b/handlers/portgate.go @@ -1,10 +1,47 @@ package handlers -import "github.com/valyala/fasthttp" +import ( + "github.com/valyala/fasthttp" + "net/http" + "portgate" +) // handlePortgateRequest handles all Portgate specific request for either showing Portgate // specific pages or handling creation of authorization tokens. -func (h *RequestHandler) handlePortgateRequest(ctx *fasthttp.RequestCtx) { - // TODO: Implement authentication, authorization - _, _ = ctx.WriteString("Portgate request.") +func (h *RequestHandler) handlePortgateRequest(ctx *fasthttp.RequestCtx, path portgate.Path) { + if path.IsPortgateStaticPath() { + h.staticHandler(ctx) + } else { + // TODO: Implement authentication, authorization + h.handlePortgateIndexRequest(ctx) + } +} + +// handlePortgateIndexRequest delegates requests directed at /_portgate. +func (h *RequestHandler) handlePortgateIndexRequest(ctx *fasthttp.RequestCtx) { + switch string(ctx.Method()) { + case "GET": + // If we received a GET request, the user wants to see either the login page, + // or an info page if they're already authenticated. + h.handlePortgatePageRequest(ctx) + case "POST": + // If we received a POST request, the user wants to get authorization to Portgate. + h.handleAuthenticateRequest(ctx) + } +} + +// handlePortgatePageRequest renders the Portgate page with either the authentication page or +// a basic information page. +func (h *RequestHandler) handlePortgatePageRequest(ctx *fasthttp.RequestCtx) { + // We render the page template and pass it to the user. + ctx.Response.Header.SetContentType("text/html") + err := h.templates.ExecuteTemplate(ctx, "authenticate.template.html", nil) + if err != nil { + ctx.SetStatusCode(http.StatusInternalServerError) + _, _ = ctx.WriteString("An error occurred.") + } +} + +func (h *RequestHandler) handleAuthenticateRequest(ctx *fasthttp.RequestCtx) { + // TODO } |
