From 076a0faea3f7004925fa72ea647a38f77b407ad1 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Wed, 11 Jul 2018 11:00:06 +0200 Subject: [PATCH] Create start of settings page --- cmd/eksterd/main.go | 43 +++++++++++++++++++++++++-- templates/index.html | 66 +++++++++++++++++++++++++++-------------- templates/settings.html | 63 +++++++++++++++++++++++++-------------- 3 files changed, 125 insertions(+), 47 deletions(-) diff --git a/cmd/eksterd/main.go b/cmd/eksterd/main.go index c245f4c..426a3ce 100644 --- a/cmd/eksterd/main.go +++ b/cmd/eksterd/main.go @@ -72,6 +72,9 @@ type authResponse struct { type indexPage struct { Session session } +type settingsPage struct { + Session session +} func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { conn := pool.Get() @@ -115,8 +118,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } t, err := template.ParseFiles( - os.Getenv("EKSTER_TEMPLATES")+"/index.html", - os.Getenv("EKSTER_TEMPLATES")+"/settings.html", + os.Getenv("EKSTER_TEMPLATES") + "/index.html", ) if err != nil { fmt.Fprintf(w, "ERROR: %q\n", err) @@ -204,6 +206,43 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "ERROR: HTTP response code from authorization_endpoint (%s) %d \n", sess.AuthorizationEndpoint, resp.StatusCode) return } + } else if r.URL.Path == "/settings" { + c, err := r.Cookie("session") + if err == http.ErrNoCookie { + http.Redirect(w, r, "/", 302) + return + } + sessionVar := c.Value + var sess session + sessionKey := "session:" + sessionVar + data, err := redis.Values(conn.Do("HGETALL", sessionKey)) + if err != nil { + fmt.Fprintf(w, "ERROR: %q\n", err) + return + } + err = redis.ScanStruct(data, &sess) + if err != nil { + fmt.Fprintf(w, "ERROR: %q\n", err) + return + } + + t, err := template.ParseFiles( + os.Getenv("EKSTER_TEMPLATES") + "/settings.html", + ) + if err != nil { + fmt.Fprintf(w, "ERROR: %q\n", err) + return + } + + var page settingsPage + page.Session = sess + + err = t.ExecuteTemplate(w, "settings.html", page) + if err != nil { + fmt.Fprintf(w, "ERROR: %q\n", err) + return + } + return } } else if r.Method == http.MethodPost { if r.URL.Path == "/auth" { diff --git a/templates/index.html b/templates/index.html index 876df61..7a74b96 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,35 +9,55 @@
+ + + +

Ekster - Microsub server

-

Settings

- {{ if .Session.LoggedIn }} - - SUCCESS Me = {{ .Session.Me }} - -

Logout

- -
- -
+

Logout

+
+ +
{{ else }} -

Sign in to Ekster

- -
-
- -
- +

Sign in to Ekster

+ +
+ +
+ +
-
-
-
- +
+
+ +
-
- + {{ end }}
diff --git a/templates/settings.html b/templates/settings.html index f17ecf3..e0c3998 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -1,27 +1,46 @@ + - - Settings - Ekster - - - - + + + +Ekster + + + +
-

Ekster

-

Settings

-

Not yet implemented

+ + + +

Ekster - Microsub server

+ + {{ if .Session.LoggedIn }} + {{ end }}
- +
+