summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Minko <vitaly.minko@gmail.com>2019-06-01 09:25:06 +0300
committerVitaly Minko <vitaly.minko@gmail.com>2019-06-01 09:25:06 +0300
commitfdf87d122aad0045e3d5c3923f8dd2a90910d5ee (patch)
tree2cf95fd1d086972a3b0c6e5c54003c92e7f96177
parentb625be8b62f93708a00eb7c7efc1f123aaa99215 (diff)
Improved HTML templates for /board and /thread.
-rw-r--r--cmd/dscuss-web/controller/board_handlers.go18
-rw-r--r--cmd/dscuss-web/controller/common_data.go8
-rw-r--r--cmd/dscuss-web/controller/login_handlers.go9
-rw-r--r--cmd/dscuss-web/controller/thread_handlers.go4
-rw-r--r--cmd/dscuss-web/main.go1
-rw-r--r--cmd/dscuss-web/static/css.go23
-rw-r--r--cmd/dscuss-web/view/base.go8
-rw-r--r--cmd/dscuss-web/view/board.go22
-rw-r--r--cmd/dscuss-web/view/login.go2
-rw-r--r--cmd/dscuss-web/view/templates.go3
-rw-r--r--cmd/dscuss-web/view/thread.go8
-rw-r--r--config.go1
-rw-r--r--dscuss.go2
-rw-r--r--p2p/dht_crawler.go2
14 files changed, 68 insertions, 43 deletions
diff --git a/cmd/dscuss-web/controller/board_handlers.go b/cmd/dscuss-web/controller/board_handlers.go
index 65f36c6..1faae95 100644
--- a/cmd/dscuss-web/controller/board_handlers.go
+++ b/cmd/dscuss-web/controller/board_handlers.go
@@ -29,12 +29,14 @@ import (
func boardHandler(w http.ResponseWriter, r *http.Request, l *dscuss.LoginHandle, s *Session) {
type Thread struct {
- ID string
- Topic string
- Subject string
- DateWritten string
- AuthorName string
- AuthorID string
+ ID string
+ Topic string
+ Subject string
+ Text string
+ DateWritten string
+ AuthorName string
+ AuthorID string
+ AuthorShortID string
}
var validURI = regexp.MustCompile("^/board(topic=[a-z,]*)?$")
m := validURI.FindStringSubmatch(r.URL.Path)
@@ -42,7 +44,7 @@ func boardHandler(w http.ResponseWriter, r *http.Request, l *dscuss.LoginHandle,
http.NotFound(w, r)
return
}
- topicStr := r.FormValue("topic")
+ topicStr := r.URL.Query().Get("topic")
var err error
var topic subs.Topic
if topicStr != "" {
@@ -71,8 +73,10 @@ func boardHandler(w http.ResponseWriter, r *http.Request, l *dscuss.LoginHandle,
t.ID = msg.ID().String()
t.Topic = msg.Topic.String()
t.Subject = msg.Subject
+ t.Text = msg.Text
t.DateWritten = msg.DateWritten.Format(time.RFC3339)
t.AuthorID = msg.AuthorID.String()
+ t.AuthorShortID = msg.AuthorID.Shorten()
t.AuthorName = userName(l, &msg.AuthorID)
}
diff --git a/cmd/dscuss-web/controller/common_data.go b/cmd/dscuss-web/controller/common_data.go
index 8ea106a..d2de748 100644
--- a/cmd/dscuss-web/controller/common_data.go
+++ b/cmd/dscuss-web/controller/common_data.go
@@ -20,6 +20,7 @@ import (
"html/template"
"net/http"
"net/url"
+ "strings"
"vminko.org/dscuss"
"vminko.org/dscuss/cmd/dscuss-web/config"
)
@@ -28,9 +29,11 @@ type CommonData struct {
CSRF string
OwnerName string
OwnerID string
+ OwnerShortID string
NodeName string
PageTitle string
CurrentURL template.URL
+ ShowLogin bool
IsWritingPermitted bool
}
@@ -39,13 +42,15 @@ func readCommonData(r *http.Request, s *Session, l *dscuss.LoginHandle) *CommonD
res := CommonData{
CSRF: s.CSRFToken,
NodeName: cfg.NodeName,
- IsWritingPermitted: false,
CurrentURL: "/",
+ IsWritingPermitted: false,
+ ShowLogin: true,
}
if s.IsAuthenticated {
u := l.GetLoggedUser()
res.OwnerName = u.Nickname
res.OwnerID = u.ID().String()
+ res.OwnerShortID = u.ID().Shorten()
res.IsWritingPermitted = true
}
if r.URL.Path != "" {
@@ -54,6 +59,7 @@ func readCommonData(r *http.Request, s *Session, l *dscuss.LoginHandle) *CommonD
currentURL = currentURL + "?" + r.URL.RawQuery
}
res.CurrentURL = template.URL(url.QueryEscape(currentURL))
+ res.ShowLogin = !strings.HasPrefix(currentURL, "/login")
}
return &res
}
diff --git a/cmd/dscuss-web/controller/login_handlers.go b/cmd/dscuss-web/controller/login_handlers.go
index 98ef891..9fc4141 100644
--- a/cmd/dscuss-web/controller/login_handlers.go
+++ b/cmd/dscuss-web/controller/login_handlers.go
@@ -31,13 +31,18 @@ const (
)
func loginHandler(w http.ResponseWriter, r *http.Request, l *dscuss.LoginHandle, s *Session) {
- var validURI = regexp.MustCompile("^/login(next=[a-z,\\/]*)?$")
+ var validURI = regexp.MustCompile("^/login(next=[a-zA-Z0-9\\/+=]+)?$")
m := validURI.FindStringSubmatch(r.URL.Path)
if m == nil {
http.NotFound(w, r)
return
}
- redirectURL, err := url.QueryUnescape(r.FormValue("next"))
+ var err error
+ redirectURL := r.FormValue("next")
+ // FormValue() returns URL-decoded value for GET methods
+ if r.Method == "POST" {
+ redirectURL, err = url.QueryUnescape(r.FormValue("next"))
+ }
if err != nil || redirectURL == "" || redirectURL[0] != '/' {
redirectURL = "/"
}
diff --git a/cmd/dscuss-web/controller/thread_handlers.go b/cmd/dscuss-web/controller/thread_handlers.go
index 649b37d..da41b67 100644
--- a/cmd/dscuss-web/controller/thread_handlers.go
+++ b/cmd/dscuss-web/controller/thread_handlers.go
@@ -83,13 +83,13 @@ func (tc *ThreadComposer) Handle(n *thread.Node) bool {
}
func threadHandler(w http.ResponseWriter, r *http.Request, l *dscuss.LoginHandle, s *Session) {
- var validURI = regexp.MustCompile("^/thread(id=[a-zA-Z0-9/+=]{32})?$")
+ var validURI = regexp.MustCompile("^/thread(id=[a-zA-Z0-9\\/+=]{32})?$")
m := validURI.FindStringSubmatch(r.URL.Path)
if m == nil {
http.NotFound(w, r)
return
}
- idStr := r.FormValue("id")
+ idStr := r.URL.Query().Get("id")
var tid entity.ID
err := tid.ParseString(idStr)
if err != nil {
diff --git a/cmd/dscuss-web/main.go b/cmd/dscuss-web/main.go
index 3337031..d3fa3b4 100644
--- a/cmd/dscuss-web/main.go
+++ b/cmd/dscuss-web/main.go
@@ -122,6 +122,7 @@ func main() {
http.HandleFunc("/board", controller.MakeBoardHandler(loginHandle))
http.HandleFunc("/login", controller.MakeLoginHandler(loginHandle))
http.HandleFunc("/logout", controller.LogoutHandler)
+ http.HandleFunc("/thread", controller.MakeThreadHandler(loginHandle))
http.HandleFunc("/", controller.MakeRootHandler(loginHandle))
log.Debugf("Starting HTTP server on port %d\n", webPort)
diff --git a/cmd/dscuss-web/static/css.go b/cmd/dscuss-web/static/css.go
index 02e32b1..2c8314c 100644
--- a/cmd/dscuss-web/static/css.go
+++ b/cmd/dscuss-web/static/css.go
@@ -143,10 +143,10 @@ a:visited {
#navright {
float: right;
}
-.muted {
+.dimmed {
color: darkgrey;
}
-.muted a, .muted a:link, .muted a:hover, .muted a:visited, .muted a:active {
+.dimmed a, .dimmed a:link, .dimmed a:hover, .dimmed a:visited, .dimmed a:active {
color: grey;
}
.row {
@@ -204,26 +204,23 @@ textarea {
#subtitle {
margin-top: 0px;
}
-.comment p:first-child {
+.message p:first-child {
margin-top: 10px;
}
-.comment-row {
+.message-row, .thread-row {
margin-bottom: 30px;
}
-.comment-title {
- font-size: 90%;
-}
-.topic-row {
-
+.underline, .topic {
+ font-size: 75%;
}
.alert {
color: red;
}
-a, .muted, h3, .comment p {
+a, .dimmed, h3, .message p {
word-wrap: break-word;
}
-.muted .link-button {
+.dimmed .link-button {
border: none;
outline: none;
background: none;
@@ -234,10 +231,10 @@ a, .muted, h3, .comment p {
font-family: inherit;
font-size: inherit;
}
-.muted .link-button:focus {
+.dimmed .link-button:focus {
outline: none;
}
-.muted .link-button:active {
+.dimmed .link-button:active {
color: grey;
}
`
diff --git a/cmd/dscuss-web/view/base.go b/cmd/dscuss-web/view/base.go
index 221e6f6..3aa147e 100644
--- a/cmd/dscuss-web/view/base.go
+++ b/cmd/dscuss-web/view/base.go
@@ -42,9 +42,11 @@ const baseHTML = `
</div>
<div id="navright">
{{ if .Common.OwnerName }}
- {{ .Common.OwnerName }} ({{ .Common.OwnerID }}) <a href="/logout">Logout</a>
+ {{ .Common.OwnerName }}-{{ .Common.OwnerShortID }} <a href="/logout">Logout</a>
{{ else }}
- <a href="/login?next={{ .Common.CurrentURL }}">Login</a>
+ {{ if .Common.ShowLogin }}
+ <a href="/login?next={{ .Common.CurrentURL }}">Login</a>
+ {{ end }}
{{ end }}
</div>
</div>
@@ -58,3 +60,5 @@ const baseHTML = `
</body>
</html>
`
+
+/* vim: set filetype=html: */
diff --git a/cmd/dscuss-web/view/board.go b/cmd/dscuss-web/view/board.go
index d5e1383..ba35297 100644
--- a/cmd/dscuss-web/view/board.go
+++ b/cmd/dscuss-web/view/board.go
@@ -30,25 +30,27 @@ all topics
{{ if .Threads }}
{{ range .Threads }}
+<hr class="sep">
<div class="thread-row" id="thread-{{ .ID }}">
- <div><a href="/thread?id={{ .ID }}">{{ .Subject }}</a></div>
- <div class="muted">
- ID: {{ .ID }}
- </div>
- <div class="muted">
- Topic: <a href="/board?topic={{ .Topic }}">{{ .Topic }}</a>
+ <div>
+ <a href="/thread?id={{ .ID }}">{{ .Subject }}</a>
+ {{ if not $.Topic }}
+ <span class="topic">in <a class="topic" href="/board?topic={{ .Topic }}">{{ .Topic }}</a></span>
+ {{ end }}
</div>
- <div class="muted">
- by {{ .AuthorName }}" ( {{ .AuthorID }} ) at {{ .DateWritten }}
+ <div class="message">{{ .Text }}</div>
+ <div class="dimmed underline">
+ by {{ .AuthorName }}-{{ .AuthorShortID }} {{ .DateWritten }}
</div>
</div>
-<hr class="sep">
{{ end }}
{{ else }}
<div class="row">
- <div class="muted">No threads to show.</div>
+ <div class="dimmed">No threads to show.</div>
</div>
{{ end }}
{{ end }}
`
+
+/* vim: set filetype=html: */
diff --git a/cmd/dscuss-web/view/login.go b/cmd/dscuss-web/view/login.go
index 30ccb9b..3a4ec25 100644
--- a/cmd/dscuss-web/view/login.go
+++ b/cmd/dscuss-web/view/login.go
@@ -37,3 +37,5 @@ const loginHTML = `
</form>
{{ end }}`
+
+/* vim: set filetype=html: */
diff --git a/cmd/dscuss-web/view/templates.go b/cmd/dscuss-web/view/templates.go
index 6d698c1..7a7c5be 100644
--- a/cmd/dscuss-web/view/templates.go
+++ b/cmd/dscuss-web/view/templates.go
@@ -36,8 +36,9 @@ var templates templateMap = make(map[string]*template.Template)
func init() {
base := template.Must(template.New("base").Parse(baseHTML))
- templates.Add(base, "board", boardHTML)
templates.Add(base, "login", loginHTML)
+ templates.Add(base, "board", boardHTML)
+ templates.Add(base, "thread", threadHTML)
}
func Render(w http.ResponseWriter, tmplName string, data interface{}) {
diff --git a/cmd/dscuss-web/view/thread.go b/cmd/dscuss-web/view/thread.go
index 0796d34..cfd8f4c 100644
--- a/cmd/dscuss-web/view/thread.go
+++ b/cmd/dscuss-web/view/thread.go
@@ -27,10 +27,10 @@ const threadHTML = `
{{end}}
<h2 id="title"><a href="/thread?id={{ .ThreadID }}">{{ .Subject }}</a></h2>
-in <a href="/board?topic={{ .Topic }}">{{ .Topic }}</a>
+<span class="topic">in <a href="/board?topic={{ .Topic }}">{{ .Topic }}</a></span>
<div class="message-row">
<div class="message">{{ .Text }}</div>
- <div class="dimmed message-underline">
+ <div class="dimmed underline">
by <a href="/user?u={{ .AuthorID }}">{{ .AuthorName }}-{{ .AuthorShortID }}</a> {{ .DateWritten }}
{{ if .Common.IsWritingPermitted }}
| <a href="/ban?id={{ .AuthorID }}">ban</a>
@@ -46,7 +46,7 @@ in <a href="/board?topic={{ .Topic }}">{{ .Topic }}</a>
<div class="message-row" id="message-{{ .ID }}">
<b>{{ .Subject }}</b>
<div class="message">{{ .Text }}</div>
- <div class="dimmed message-underline">
+ <div class="dimmed underline">
by <a href="/user?u={{ .AuthorID }}">{{ .AuthorName }}-{{ .AuthorShortID }}</a>
<a href="/lsop?id={{ .ID }}">{{ .DateWritten }}</a>
{{ if $.Common.IsWritingPermitted }}
@@ -76,3 +76,5 @@ in <a href="/board?topic={{ .Topic }}">{{ .Topic }}</a>
{{ end }}
{{ end }}`
+
+/* vim: set filetype=html: */
diff --git a/config.go b/config.go
index 69edf85..d6fbe3a 100644
--- a/config.go
+++ b/config.go
@@ -32,6 +32,7 @@ type NetworkConfig struct {
Address string
Port int
AddressProvider string
+ DHTAddress string
DHTPort int
DHTBootstrap string
MaxInConnCount uint32
diff --git a/dscuss.go b/dscuss.go
index 5e3ad13..f5c0440 100644
--- a/dscuss.go
+++ b/dscuss.go
@@ -176,7 +176,7 @@ func Login(nickname string) (*LoginHandle, error) {
aps = append(aps, ap)
case "dht":
ap := p2p.NewDHTCrawler(
- cfg.Network.Address,
+ cfg.Network.DHTAddress,
cfg.Network.DHTPort,
cfg.Network.DHTBootstrap,
cfg.Network.Port,
diff --git a/p2p/dht_crawler.go b/p2p/dht_crawler.go
index 3d06428..cd538d4 100644
--- a/p2p/dht_crawler.go
+++ b/p2p/dht_crawler.go
@@ -76,7 +76,7 @@ func (dc *DHTCrawler) Start() {
log.Fatal("Attempt to start providing addresses when AddressConsumer is not set")
}
cfg := dht.NewConfig()
- //cfg.Address = dc.addr
+ cfg.Address = dc.addr
cfg.Port = dc.port
cfg.RateLimit = -1
cfg.ClientPerMinuteLimit = 10000