diff options
author | sanine <sanine.not@pm.me> | 2023-05-14 20:12:06 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-14 20:12:06 -0500 |
commit | 5b4251fd39c43e4cfed27e032a4efb2bbba28e38 (patch) | |
tree | f51840d5607eba0db9262045e330a1c8b8393449 /page/default.go | |
parent | 9571ccc4d87907067df98edeaa78f0c167fcff43 (diff) |
add auth & pages
Diffstat (limited to 'page/default.go')
-rw-r--r-- | page/default.go | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/page/default.go b/page/default.go new file mode 100644 index 0000000..ea51acc --- /dev/null +++ b/page/default.go @@ -0,0 +1,88 @@ +package page + +import ( + "strings" + "text/template" +) + + +type page struct { + Title string + Body string +} + + +func buildPage(p page) (string, error) { + t, err := template.New("").Parse(` +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>{{ .Title }}</title> + </head> + <body> + {{ .Body }} + </body> +</html> + `) + if err != nil { + return "", err + } + + var b strings.Builder + + err = t.Execute(&b, p) + if err != nil { + return "", err + } + + return b.String(), nil +} + + +func DefaultLogin() (string, error) { + return buildPage(page{ + Title: "Login", + Body: ` + <form method="post"> + <label for="username">Username</label> + <input type="text" id="username" name="username"> + <br> + <label for="password">Password</label> + <input type="text" id="password" name="password"> + <br> + <input type="submit" value="Submit"> + </form> + `, + }) +} + + +func DefaultLoggedIn() (string, error) { + return buildPage(page{ + Title: "Logged In", + Body: ` + <h1>You are logged in.</h1> + <form method="get" action="/phlox/logout"> + <input type="submit" value="Log Out"> + </form> + `, + }) +} + + +func DefaultError404() (string, error) { + return buildPage(page{ + Title: "404 Not Found", + Body: "<h1>Error 404: Page not found</h1>", + }) +} + + +func DefaultError500() (string, error) { + return buildPage(page{ + Title: "500 Not Found", + Body: "<h1>Error 500: Page not found</h1>", + }) +} |