Add templates
This commit is contained in:
parent
8ef9e31446
commit
fe88320675
|
@ -10,5 +10,6 @@ RUN ["mkdir", "-p", "/opt/micropub"]
|
|||
WORKDIR /opt/micropub
|
||||
EXPOSE 80
|
||||
COPY --from=build-env /go/bin/eksterd /app/
|
||||
COPY --from=build-env /go/bin/ek /app/
|
||||
RUN ["mkdir", "/app/templates"]
|
||||
COPY --from=build-env /go/src/github.com/pstuifzand/ekster/templates /app/templates
|
||||
ENTRYPOINT ["/app/eksterd"]
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -68,17 +69,21 @@ type authResponse struct {
|
|||
Me string `json:"me"`
|
||||
}
|
||||
|
||||
type indexPage struct {
|
||||
Session session
|
||||
}
|
||||
|
||||
func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
err := r.ParseForm()
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), 400)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method == http.MethodGet {
|
||||
if r.URL.Path == "/" {
|
||||
c, err := r.Cookie("session")
|
||||
|
@ -109,27 +114,12 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, "<h1>Ekster - Microsub server</h1>")
|
||||
fmt.Fprintln(w, `<p><a href="/settings">Settings</a></p>`)
|
||||
t, err := template.ParseFiles("templates/index.html", "templates/settings.html")
|
||||
|
||||
if sess.LoggedIn {
|
||||
fmt.Fprintf(w, "SUCCESS Me = %s", sess.Me)
|
||||
fmt.Fprintln(w, `
|
||||
<h2>Logout</h2>
|
||||
<form action="/auth/logout" method="post">
|
||||
<button type="submit">Logout</button>
|
||||
</form>
|
||||
`)
|
||||
} else {
|
||||
fmt.Fprintln(w, `
|
||||
<h2>Sign in to Ekster</h2>
|
||||
<form action="/auth" method="post">
|
||||
<input type="text" name="url" placeholder="https://example.com/">
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
`)
|
||||
}
|
||||
var page indexPage
|
||||
page.Session = sess
|
||||
|
||||
err = t.ExecuteTemplate(w, "index", page)
|
||||
return
|
||||
} else if r.URL.Path == "/auth/callback" {
|
||||
c, err := r.Cookie("session")
|
||||
|
|
23
templates/index.html
Normal file
23
templates/index.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Ekster</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ekster - Microsub server</h1>
|
||||
<p><a href="/settings">Settings</a></p>
|
||||
|
||||
{{ if .Session.LoggedIn }}
|
||||
|
||||
SUCCESS Me = {{ .Session.Me }}
|
||||
<h2>Logout</h2>
|
||||
<form action="/auth/logout" method="post">
|
||||
<button type="submit">Logout</button>
|
||||
</form>
|
||||
{{ else }}
|
||||
<h2>Sign in to Ekster</h2>
|
||||
<form action="/auth" method="post">
|
||||
<input type="text" name="url" placeholder="https://example.com/">
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
27
templates/settings.html
Normal file
27
templates/settings.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Settings - Ekster</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin:0; padding:0; }
|
||||
body {
|
||||
background: #efefef;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.container {
|
||||
padding: 12px;
|
||||
background: white;
|
||||
max-width: 800px;
|
||||
margin: 30px auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Ekster</h1>
|
||||
<h2>Settings</h2>
|
||||
|
||||
<p>Not yet implemented</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user