From 919a114f9985c8b096989a406dfc4da785699e97 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Tue, 11 Jul 2023 10:21:57 -0400 Subject: [PATCH] add missing handlers. fixes #31 --- public/style.css | 8 +++++--- public/utils.js | 3 +++ routes.go | 6 +++++- state.go | 3 ++- templates/frontpage.html | 4 ++-- templates/main.html | 4 ++-- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/public/style.css b/public/style.css index 48bde5a..b99d837 100644 --- a/public/style.css +++ b/public/style.css @@ -74,6 +74,7 @@ summary { color: #646464; } .comment .score { + clear:left; margin-right: 4px; overflow:hidden; } @@ -82,6 +83,9 @@ summary { overflow:hidden; max-width: 840px; } +.comment.hidden { + padding-bottom:5px; +} .comment.hidden .score { visibility: hidden; } @@ -266,9 +270,6 @@ form.savecomment { font-size: 10px; margin-right: 2px; } -.comment.hidden { - margin-bottom: 10px; -} .comment.hidden .meta a { color: gray; font-weight: 400; @@ -283,6 +284,7 @@ form.savecomment { .children .morecomments { } .morecomments { + clear: left; margin: 0px 0px 10px 0px; font-size: 10px; } diff --git a/public/utils.js b/public/utils.js index cd42e34..f1ca97d 100644 --- a/public/utils.js +++ b/public/utils.js @@ -55,6 +55,7 @@ function commentClick(e) { request(targ.target || "", params, function(res){ targ.outerHTML = res + setup() }, function(res){ e.target.disabled = "" @@ -99,6 +100,7 @@ function commentClick(e) { e.preventDefault() request(e.target.href+"&xhr",false, function(res){ targ.outerHTML = res + setup() }) return false } @@ -172,6 +174,7 @@ function formSubmit(e) { request(targ.target, params, function(res){ targ.outerHTML = res + setup() }, function(res){ e.submitter.disabled = "" diff --git a/routes.go b/routes.go index 7fe49eb..630291a 100644 --- a/routes.go +++ b/routes.go @@ -643,10 +643,14 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) q.Add("alert", alert) r.URL.RawQuery = q.Encode() http.Redirect(w, r, r.URL.String(), 301) + return } } if token != "" { state.GetUser(username) + if state.User == nil { + return + } setCookie(w, state.Host, "jwt", token) userid := strconv.Itoa(state.User.PersonView.Person.ID) setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid) @@ -663,7 +667,7 @@ func GetLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { return } state.GetSite() - if state.Site.SiteView.LocalSite.CaptchaEnabled { + if state.Site != nil && state.Site.SiteView.LocalSite.CaptchaEnabled { state.GetCaptcha() } m, _ := url.ParseQuery(r.URL.RawQuery) diff --git a/state.go b/state.go index ed13e37..33bc5b9 100644 --- a/state.go +++ b/state.go @@ -219,7 +219,8 @@ func (state *State) GetSite() { resp, err := state.Client.Site(context.Background(), types.GetSite{}) if err != nil { state.Status = http.StatusInternalServerError - state.Host = "" + state.Host = "." + state.Error = errors.New("site unreachable") return } state.Client.Token = token diff --git a/templates/frontpage.html b/templates/frontpage.html index deecf9f..39ec210 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -2,7 +2,7 @@ {{ if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}} - + @@ -56,6 +56,6 @@ {{ template "sidebar.html" . }} {{ end }} - + diff --git a/templates/main.html b/templates/main.html index 4d71963..713d722 100644 --- a/templates/main.html +++ b/templates/main.html @@ -3,7 +3,7 @@ {{if and .Posts .PostID }}{{ (index .Posts 0).Post.Name}} : {{.CommunityName}}{{else if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}} - +