Improve settings page, add logs page
This commit is contained in:
parent
330d4d70e5
commit
7156920798
|
@ -46,6 +46,9 @@ type settingsPage struct {
|
|||
Channels map[string]microsub.Channel
|
||||
Feeds map[string][]microsub.Feed
|
||||
}
|
||||
type logsPage struct {
|
||||
Session session
|
||||
}
|
||||
|
||||
func newMainHandler(backend *memoryBackend) (*mainHandler, error) {
|
||||
h := &mainHandler{Backend: backend}
|
||||
|
@ -141,6 +144,18 @@ func verifyAuthCode(code, redirectURI, authEndpoint string) (bool, *authResponse
|
|||
return false, nil, fmt.Errorf("ERROR: HTTP response code from authorization_endpoint (%s) %d \n", authEndpoint, resp.StatusCode)
|
||||
}
|
||||
|
||||
func isLoggedIn(backend *memoryBackend, sess *session) bool {
|
||||
if !sess.LoggedIn {
|
||||
return false
|
||||
}
|
||||
|
||||
if sess.Me != backend.Me {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
|
@ -210,7 +225,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
sessionVar := c.Value
|
||||
sess, err := loadSession(sessionVar, conn)
|
||||
|
||||
if !sess.LoggedIn {
|
||||
if !isLoggedIn(h.Backend, &sess) {
|
||||
w.WriteHeader(401)
|
||||
fmt.Fprintf(w, "Unauthorized")
|
||||
return
|
||||
|
@ -228,6 +243,30 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
return
|
||||
} else if r.URL.Path == "/logs" {
|
||||
c, err := r.Cookie("session")
|
||||
if err == http.ErrNoCookie {
|
||||
http.Redirect(w, r, "/", 302)
|
||||
return
|
||||
}
|
||||
sessionVar := c.Value
|
||||
sess, err := loadSession(sessionVar, conn)
|
||||
|
||||
if !isLoggedIn(h.Backend, &sess) {
|
||||
w.WriteHeader(401)
|
||||
fmt.Fprintf(w, "Unauthorized")
|
||||
return
|
||||
}
|
||||
|
||||
var page logsPage
|
||||
page.Session = sess
|
||||
|
||||
err = h.Templates.ExecuteTemplate(w, "logs.html", page)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
} else if r.URL.Path == "/settings" {
|
||||
c, err := r.Cookie("session")
|
||||
if err == http.ErrNoCookie {
|
||||
|
@ -237,7 +276,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
sessionVar := c.Value
|
||||
sess, err := loadSession(sessionVar, conn)
|
||||
|
||||
if !sess.LoggedIn {
|
||||
if !isLoggedIn(h.Backend, &sess) {
|
||||
w.WriteHeader(401)
|
||||
fmt.Fprintf(w, "Unauthorized")
|
||||
return
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
<a class="navbar-item" href="/settings">
|
||||
Settings
|
||||
</a>
|
||||
<a class="navbar-item" href="/logs">
|
||||
Logs
|
||||
</a>
|
||||
<a class="navbar-item" href="{{ .Session.Me }}">
|
||||
Profile
|
||||
</a>
|
||||
|
@ -38,17 +41,22 @@
|
|||
|
||||
<h1 class="title">Ekster - Microsub server</h1>
|
||||
|
||||
{{ if .Session.LoggedIn }}
|
||||
{{ end }}
|
||||
{{ $channel := index .Channels .CurrentChannel }}
|
||||
|
||||
<nav class="breadcrumb" aria-label="breadcrumbs">
|
||||
<ul>
|
||||
<li><a href="/settings">Settings</a></li>
|
||||
<li class="is-active"><a href="/setttings/channel?uid={{ .CurrentChannel }}">{{ $channel.Name }}</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<h2 class="subtitle">Channel</h2>
|
||||
<h2 class="subtitle">{{ $channel.Name }}</h2>
|
||||
|
||||
<div class="channel">
|
||||
{{ range index .Feeds .CurrentChannel }}
|
||||
<div class="feed box">
|
||||
<div class="name">
|
||||
<a href="{{ .URL }}">{{ or .Name "Untitled" }}</a>
|
||||
<a href="{{ .URL }}">{{ .URL }}</a>
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
<a class="navbar-item" href="/settings">
|
||||
Settings
|
||||
</a>
|
||||
<a class="navbar-item" href="/logs">
|
||||
Logs
|
||||
</a>
|
||||
<a class="navbar-item" href="{{ .Session.Me }}">
|
||||
Profile
|
||||
</a>
|
||||
|
|
50
templates/logs.html
Normal file
50
templates/logs.html
Normal file
|
@ -0,0 +1,50 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<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">
|
||||
|
||||
|
||||
<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="/logs">
|
||||
Logs
|
||||
</a>
|
||||
<a class="navbar-item" href="{{ .Session.Me }}">
|
||||
Profile
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
</nav>
|
||||
|
||||
<h1 class="title">Ekster - Microsub server</h1>
|
||||
|
||||
<h2 class="subtitle">Logs</h2>
|
||||
|
||||
<p>Logs</p>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
|
@ -29,6 +29,9 @@
|
|||
<a class="navbar-item" href="/settings">
|
||||
Settings
|
||||
</a>
|
||||
<a class="navbar-item" href="/logs">
|
||||
Logs
|
||||
</a>
|
||||
<a class="navbar-item" href="{{ .Session.Me }}">
|
||||
Profile
|
||||
</a>
|
||||
|
|
Loading…
Reference in New Issue
Block a user