mirror of https://github.com/jlelse/GoBlog
Small improvements to editor and captcha
This commit is contained in:
parent
9e423526bd
commit
33e9d53a93
|
@ -41,6 +41,7 @@ func (a *goBlog) captchaMiddleware(next http.Handler) http.Handler {
|
|||
b = []byte(r.PostForm.Encode())
|
||||
}
|
||||
a.renderWithStatusCode(w, r, http.StatusUnauthorized, templateCaptcha, &renderData{
|
||||
BlogString: r.Context().Value(blogKey).(string),
|
||||
Data: map[string]string{
|
||||
"captchamethod": r.Method,
|
||||
"captchaheaders": base64.StdEncoding.EncodeToString(h),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -42,7 +43,7 @@ func Test_captchaMiddleware(t *testing.T) {
|
|||
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
h.ServeHTTP(rec, req)
|
||||
h.ServeHTTP(rec, req.WithContext(context.WithValue(req.Context(), blogKey, "en")))
|
||||
|
||||
res := rec.Result()
|
||||
resBody, _ := io.ReadAll(res.Body)
|
||||
|
|
|
@ -28,13 +28,6 @@ func (a *goBlog) serveEditorPost(w http.ResponseWriter, r *http.Request) {
|
|||
blog := r.Context().Value(blogKey).(string)
|
||||
if action := r.FormValue("editoraction"); action != "" {
|
||||
switch action {
|
||||
case "loaddelete":
|
||||
a.render(w, r, templateEditor, &renderData{
|
||||
BlogString: blog,
|
||||
Data: map[string]interface{}{
|
||||
"DeleteURL": r.FormValue("url"),
|
||||
},
|
||||
})
|
||||
case "loadupdate":
|
||||
parsedURL, err := url.Parse(r.FormValue("url"))
|
||||
if err != nil {
|
||||
|
|
2
go.mod
2
go.mod
|
@ -74,7 +74,7 @@ require (
|
|||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.2.0 // indirect
|
||||
github.com/tdewolff/parse/v2 v2.5.19 // indirect
|
||||
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
|
||||
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -529,8 +529,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e h1:XMgFehsDnnLGtjvjOfqWSUzt0alpTR1RSEuznObga2c=
|
||||
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b h1:S7hKs0Flbq0bbc9xgYt4stIEG1zNDFqyrPwAX2Wj/sE=
|
||||
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
{{ define "title" }}
|
||||
<title>{{ string .Blog.Lang "captcha" }} - {{ mdtitle .Blog.Title }}</title>
|
||||
<title>{{ mdtitle .Blog.Title }}</title>
|
||||
{{ end }}
|
||||
|
||||
{{ define "main" }}
|
||||
<main>
|
||||
<h1>{{ string .Blog.Lang "captcha" }}</h1>
|
||||
<img src="/captcha/{{ .Data.captchaid }}.png" class="captchaimg">
|
||||
<p><img src="/captcha/{{ .Data.captchaid }}.png" class="captchaimg"></p>
|
||||
<form class="fw p" method="post">
|
||||
<input type="hidden" name="captchaaction" value="captcha">
|
||||
<input type="hidden" name="captchamethod" value="{{ .Data.captchamethod }}">
|
||||
|
|
|
@ -12,30 +12,15 @@
|
|||
<textarea name="content" class="monospace h400p formcache" id="create-input">{{ editortemplate .BlogString }}</textarea>
|
||||
<input type="submit" value="{{ string .Blog.Lang "create" }}">
|
||||
</form>
|
||||
{{ if .Data.UpdatePostURL }}
|
||||
<h2 id="update">{{ string .Blog.Lang "update" }}</h2>
|
||||
<form class="fw p" method="post" action="#update">
|
||||
{{ if .Data.UpdatePostURL }}
|
||||
<input type="hidden" name="editoraction" value="updatepost">
|
||||
<input type="hidden" name="url" value="{{ .Data.UpdatePostURL }}">
|
||||
<textarea name="content" class="monospace h400p">{{ .Data.UpdatePostContent }}</textarea>
|
||||
{{ else }}
|
||||
<input type="hidden" name="editoraction" value="loadupdate">
|
||||
<input type="url" name="url" placeholder="URL">
|
||||
{{ end }}
|
||||
<input type="hidden" name="editoraction" value="updatepost">
|
||||
<input type="hidden" name="url" value="{{ .Data.UpdatePostURL }}">
|
||||
<textarea name="content" class="monospace h400p">{{ .Data.UpdatePostContent }}</textarea>
|
||||
<input type="submit" value="{{ string .Blog.Lang "update" }}">
|
||||
</form>
|
||||
<h2 id="delete">{{ string .Blog.Lang "delete" }}</h2>
|
||||
<form class="fw p" method="post" action="#delete">
|
||||
{{ if .Data.DeleteURL }}
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="url" name="url" placeholder="URL" value="{{ .Data.DeleteURL }}">
|
||||
<input type="submit" value="{{ string .Blog.Lang "confirmdelete" }}">
|
||||
{{ else }}
|
||||
<input type="hidden" name="editoraction" value="loaddelete">
|
||||
<input type="url" name="url" placeholder="URL">
|
||||
<input type="submit" value="{{ string .Blog.Lang "delete" }}">
|
||||
{{ end }}
|
||||
</form>
|
||||
{{ end }}
|
||||
<h2>{{ string .Blog.Lang "posts" }}</h2>
|
||||
<p><a href="{{ .Blog.RelativePath "/editor/drafts" }}">{{ string .Blog.Lang "drafts" }}</a></p>
|
||||
<p><a href="{{ .Blog.RelativePath "/editor/private" }}">{{ string .Blog.Lang "privateposts" }}</a></p>
|
||||
|
|
|
@ -28,11 +28,12 @@
|
|||
<input type="hidden" name="url" value="{{ .Canonical }}">
|
||||
<input type="submit" value="{{ string .Blog.Lang "update" }}">
|
||||
</form>
|
||||
<form class="in" method="post" action="{{ .Blog.RelativePath "/editor" }}#delete">
|
||||
<input type="hidden" name="editoraction" value="loaddelete">
|
||||
<form class="in" method="post" action="{{ .Blog.RelativePath "/editor" }}">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="url" value="{{ .Canonical }}">
|
||||
<input type="submit" value="{{ string .Blog.Lang "delete" }}">
|
||||
<input type="submit" value="{{ string .Blog.Lang "delete" }}" class="confirm" data-confirmmessage="{{ string .Blog.Lang "confirmdelete" }}">
|
||||
</form>
|
||||
<script defer src="{{ asset "js/formconfirm.js" }}"></script>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ if .CommentsEnabled }}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
acommentby: "Ein Kommentar von"
|
||||
captchainstructions: "Bitte gib die Ziffern aus dem oberen Bild ein"
|
||||
chars: "Buchstaben"
|
||||
comment: "Kommentar"
|
||||
comments: "Kommentare"
|
||||
|
@ -44,6 +45,7 @@ share: "Online teilen"
|
|||
shorturl: "Kurz-Link:"
|
||||
speak: "Vorlesen"
|
||||
stopspeak: "Vorlesen stoppen"
|
||||
submit: "Abschicken"
|
||||
total: "Gesamt"
|
||||
translate: "Übersetzen"
|
||||
translations: "Übersetzungen"
|
||||
|
|
|
@ -2,7 +2,6 @@ acommentby: "A comment by"
|
|||
approve: "Approve"
|
||||
approved: "Approved"
|
||||
authenticate: "Authenticate"
|
||||
captcha: "Captcha"
|
||||
captchainstructions: "Please enter the digits from the image above"
|
||||
chars: "Characters"
|
||||
comment: "Comment"
|
||||
|
|
Loading…
Reference in New Issue