Create start of settings page

This commit is contained in:
Peter Stuifzand 2018-07-11 11:00:06 +02:00
parent cad14ac461
commit 076a0faea3
3 changed files with 125 additions and 47 deletions

View File

@ -72,6 +72,9 @@ type authResponse struct {
type indexPage struct { type indexPage struct {
Session session Session session
} }
type settingsPage 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()
@ -115,8 +118,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
t, err := template.ParseFiles( t, err := template.ParseFiles(
os.Getenv("EKSTER_TEMPLATES")+"/index.html", os.Getenv("EKSTER_TEMPLATES") + "/index.html",
os.Getenv("EKSTER_TEMPLATES")+"/settings.html",
) )
if err != nil { if err != nil {
fmt.Fprintf(w, "ERROR: %q\n", err) 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) fmt.Fprintf(w, "ERROR: HTTP response code from authorization_endpoint (%s) %d \n", sess.AuthorizationEndpoint, resp.StatusCode)
return 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 { } else if r.Method == http.MethodPost {
if r.URL.Path == "/auth" { if r.URL.Path == "/auth" {

View File

@ -9,22 +9,42 @@
<body> <body>
<section class="section"> <section class="section">
<div class="container"> <div class="container">
<h1 class="title">Ekster - Microsub server</h1>
<p><a href="/settings">Settings</a></p>
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="/">
Ekster
</a>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="menu">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
{{ if .Session.LoggedIn }} {{ if .Session.LoggedIn }}
<div id="menu" class="navbar-menu">
<a class="navbar-item" href="/settings">
Settings
</a>
<a class="navbar-item" href="{{ .Session.Me }}">
Profile
</a>
</div>
{{ end }}
</nav>
SUCCESS Me = {{ .Session.Me }} <h1 class="title">Ekster - Microsub server</h1>
{{ if .Session.LoggedIn }}
<h2 class="title">Logout</h2> <h2 class="title">Logout</h2>
<form action="/auth/logout" method="post"> <form action="/auth/logout" method="post">
<button type="submit" class="button is-info">Logout</button> <button type="submit" class="button is-info">Logout</button>
</form> </form>
{{ else }} {{ else }}
<h2 class="title">Sign in to Ekster</h2> <h2 class="title">Sign in to Ekster</h2>
<form action="/auth" method="post"> <form action="/auth" method="post">
<div class="field"> <div class="field">
<label class="label" for="url"></label> <label class="label" for="url"></label>

View File

@ -1,27 +1,46 @@
<!DOCTYPE html>
<html> <html>
<head> <head>
<title>Settings - Ekster</title> <meta charset="utf-8">
<style> <meta name="viewport" content="width=device-width, initial-scale=1">
* { box-sizing: border-box; margin:0; padding:0; } <title>Ekster</title>
body { <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
background: #efefef; </head>
font-family: sans-serif; <body>
} <section class="section">
.container {
padding: 12px;
background: white;
max-width: 800px;
margin: 30px auto;
}
</style>
</head>
<body>
<div class="container"> <div class="container">
<h1>Ekster</h1>
<h2>Settings</h2>
<p>Not yet implemented</p>
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="/">
Ekster
</a>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="menu">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div> </div>
</body>
{{ if .Session.LoggedIn }}
<div id="menu" class="navbar-menu">
<a class="navbar-item" href="/settings">
Settings
</a>
<a class="navbar-item" href="{{ .Session.Me }}">
Profile
</a>
</div>
{{ end }}
</nav>
<h1 class="title">Ekster - Microsub server</h1>
{{ if .Session.LoggedIn }}
{{ end }}
</div>
</section>
</body>
</html> </html>