Add templates
This commit is contained in:
parent
8ef9e31446
commit
fe88320675
|
|
@ -10,5 +10,6 @@ RUN ["mkdir", "-p", "/opt/micropub"]
|
||||||
WORKDIR /opt/micropub
|
WORKDIR /opt/micropub
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
COPY --from=build-env /go/bin/eksterd /app/
|
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"]
|
ENTRYPOINT ["/app/eksterd"]
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -68,17 +69,21 @@ type authResponse struct {
|
||||||
Me string `json:"me"`
|
Me string `json:"me"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type indexPage struct {
|
||||||
|
Session session
|
||||||
|
}
|
||||||
|
|
||||||
func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
conn := pool.Get()
|
conn := pool.Get()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), 400)
|
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet {
|
||||||
if r.URL.Path == "/" {
|
if r.URL.Path == "/" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
|
|
@ -109,27 +114,12 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(w, "<h1>Ekster - Microsub server</h1>")
|
t, err := template.ParseFiles("templates/index.html", "templates/settings.html")
|
||||||
fmt.Fprintln(w, `<p><a href="/settings">Settings</a></p>`)
|
|
||||||
|
|
||||||
if sess.LoggedIn {
|
var page indexPage
|
||||||
fmt.Fprintf(w, "SUCCESS Me = %s", sess.Me)
|
page.Session = sess
|
||||||
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>
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
err = t.ExecuteTemplate(w, "index", page)
|
||||||
return
|
return
|
||||||
} else if r.URL.Path == "/auth/callback" {
|
} else if r.URL.Path == "/auth/callback" {
|
||||||
c, err := r.Cookie("session")
|
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