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 {
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" {

View File

@ -9,35 +9,55 @@
<body>
<section class="section">
<div class="container">
<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 }}
<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>
<p><a href="/settings">Settings</a></p>
{{ if .Session.LoggedIn }}
SUCCESS Me = {{ .Session.Me }}
<h2 class="title">Logout</h2>
<form action="/auth/logout" method="post">
<button type="submit" class="button is-info">Logout</button>
</form>
<h2 class="title">Logout</h2>
<form action="/auth/logout" method="post">
<button type="submit" class="button is-info">Logout</button>
</form>
{{ else }}
<h2 class="title">Sign in to Ekster</h2>
<form action="/auth" method="post">
<div class="field">
<label class="label" for="url"></label>
<div class="control">
<input type="text" name="url" id="url" class="input" placeholder="https://example.com/">
<h2 class="title">Sign in to Ekster</h2>
<form action="/auth" method="post">
<div class="field">
<label class="label" for="url"></label>
<div class="control">
<input type="text" name="url" id="url" class="input" placeholder="https://example.com/">
</div>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-info">Login</button>
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-info">Login</button>
</div>
</div>
</div>
</form>
</form>
{{ end }}
</div>
</section>

View File

@ -1,27 +1,46 @@
<!DOCTYPE html>
<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>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ekster</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
</head>
<body>
<section class="section">
<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>
{{ 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>
</body>
</section>
</body>
</html>