diff --git a/history/view.qtpl b/history/view.qtpl
index 150ba9f..aa7c882 100644
--- a/history/view.qtpl
+++ b/history/view.qtpl
@@ -56,22 +56,18 @@ WithRevisions returns an html representation of `revs` that is meant to be inser
{% for _, rev := range grp %}
- {%= rev.asHistoryEntry(hyphaName) %}
+
+
+ {%s rev.timeToDisplay() %}
+
+ {%s rev.Hash %}
+ {%s rev.Message %}
+ {% if rev.Username != "anon" %}
+ by {%s rev.Username %}
+ {% endif %}
+
{% endfor %}
{% endfor %}
{% endfunc %}
-
-{% func (rev *Revision) asHistoryEntry(hyphaName string) %}
-
-
- {%s rev.timeToDisplay() %}
-
- {%s rev.Hash %}
- {%s rev.Message %}
- {% if rev.Username != "anon" %}
- by {%s rev.Username %}
- {% endif %}
-
-{% endfunc %}
\ No newline at end of file
diff --git a/history/view.qtpl.go b/history/view.qtpl.go
index 796a527..9fcaabd 100644
--- a/history/view.qtpl.go
+++ b/history/view.qtpl.go
@@ -283,141 +283,102 @@ func StreamWithRevisions(qw422016 *qt422016.Writer, hyphaName string, revs []Rev
for _, rev := range grp {
//line history/view.qtpl:58
qw422016.N().S(`
- `)
-//line history/view.qtpl:59
- rev.streamasHistoryEntry(qw422016, hyphaName)
-//line history/view.qtpl:59
+
+
+ `)
+//line history/view.qtpl:61
+ qw422016.E().S(rev.timeToDisplay())
+//line history/view.qtpl:61
+ qw422016.N().S(`
+
+ `)
+//line history/view.qtpl:63
+ qw422016.E().S(rev.Hash)
+//line history/view.qtpl:63
+ qw422016.N().S(`
+ `)
+//line history/view.qtpl:64
+ qw422016.E().S(rev.Message)
+//line history/view.qtpl:64
+ qw422016.N().S(`
+ `)
+//line history/view.qtpl:65
+ if rev.Username != "anon" {
+//line history/view.qtpl:65
+ qw422016.N().S(`
+ by `)
+//line history/view.qtpl:66
+ qw422016.E().S(rev.Username)
+//line history/view.qtpl:66
+ qw422016.N().S(`
+ `)
+//line history/view.qtpl:67
+ }
+//line history/view.qtpl:67
qw422016.N().S(`
+
`)
-//line history/view.qtpl:60
+//line history/view.qtpl:69
}
-//line history/view.qtpl:60
+//line history/view.qtpl:69
qw422016.N().S(`
`)
-//line history/view.qtpl:63
+//line history/view.qtpl:72
}
-//line history/view.qtpl:63
+//line history/view.qtpl:72
qw422016.N().S(`
`)
-//line history/view.qtpl:64
+//line history/view.qtpl:73
}
-//line history/view.qtpl:64
+//line history/view.qtpl:73
func WriteWithRevisions(qq422016 qtio422016.Writer, hyphaName string, revs []Revision) {
-//line history/view.qtpl:64
+//line history/view.qtpl:73
qw422016 := qt422016.AcquireWriter(qq422016)
-//line history/view.qtpl:64
+//line history/view.qtpl:73
StreamWithRevisions(qw422016, hyphaName, revs)
-//line history/view.qtpl:64
+//line history/view.qtpl:73
qt422016.ReleaseWriter(qw422016)
-//line history/view.qtpl:64
+//line history/view.qtpl:73
}
-//line history/view.qtpl:64
+//line history/view.qtpl:73
func WithRevisions(hyphaName string, revs []Revision) string {
-//line history/view.qtpl:64
+//line history/view.qtpl:73
qb422016 := qt422016.AcquireByteBuffer()
-//line history/view.qtpl:64
+//line history/view.qtpl:73
WriteWithRevisions(qb422016, hyphaName, revs)
-//line history/view.qtpl:64
- qs422016 := string(qb422016.B)
-//line history/view.qtpl:64
- qt422016.ReleaseByteBuffer(qb422016)
-//line history/view.qtpl:64
- return qs422016
-//line history/view.qtpl:64
-}
-
-//line history/view.qtpl:66
-func (rev *Revision) streamasHistoryEntry(qw422016 *qt422016.Writer, hyphaName string) {
-//line history/view.qtpl:66
- qw422016.N().S(`
-
-
- `)
-//line history/view.qtpl:69
- qw422016.E().S(rev.timeToDisplay())
-//line history/view.qtpl:69
- qw422016.N().S(`
-
- `)
-//line history/view.qtpl:71
- qw422016.E().S(rev.Hash)
-//line history/view.qtpl:71
- qw422016.N().S(`
- `)
-//line history/view.qtpl:72
- qw422016.E().S(rev.Message)
-//line history/view.qtpl:72
- qw422016.N().S(`
- `)
//line history/view.qtpl:73
- if rev.Username != "anon" {
-//line history/view.qtpl:73
- qw422016.N().S(`
- by `)
-//line history/view.qtpl:74
- qw422016.E().S(rev.Username)
-//line history/view.qtpl:74
- qw422016.N().S(`
- `)
-//line history/view.qtpl:75
- }
-//line history/view.qtpl:75
- qw422016.N().S(`
-
-`)
-//line history/view.qtpl:77
-}
-
-//line history/view.qtpl:77
-func (rev *Revision) writeasHistoryEntry(qq422016 qtio422016.Writer, hyphaName string) {
-//line history/view.qtpl:77
- qw422016 := qt422016.AcquireWriter(qq422016)
-//line history/view.qtpl:77
- rev.streamasHistoryEntry(qw422016, hyphaName)
-//line history/view.qtpl:77
- qt422016.ReleaseWriter(qw422016)
-//line history/view.qtpl:77
-}
-
-//line history/view.qtpl:77
-func (rev *Revision) asHistoryEntry(hyphaName string) string {
-//line history/view.qtpl:77
- qb422016 := qt422016.AcquireByteBuffer()
-//line history/view.qtpl:77
- rev.writeasHistoryEntry(qb422016, hyphaName)
-//line history/view.qtpl:77
qs422016 := string(qb422016.B)
-//line history/view.qtpl:77
+//line history/view.qtpl:73
qt422016.ReleaseByteBuffer(qb422016)
-//line history/view.qtpl:77
+//line history/view.qtpl:73
return qs422016
-//line history/view.qtpl:77
+//line history/view.qtpl:73
}
diff --git a/settings/view.go b/settings/view.go
deleted file mode 100644
index 338447c..0000000
--- a/settings/view.go
+++ /dev/null
@@ -1,47 +0,0 @@
-package settings
-
-import (
- "embed"
- "github.com/bouncepaw/mycorrhiza/util"
- "github.com/bouncepaw/mycorrhiza/viewutil"
- "github.com/gorilla/mux"
- "net/http"
-
- "github.com/bouncepaw/mycorrhiza/user"
-)
-
-// TODO: translate untranslated strings
-const settingsTranslationRu = `
-{{define "change password"}}Change password{{end}}
-{{define "confirm password"}}Confirm password{{end}}
-{{define "current password"}}Current password{{end}}
-{{define "non local password change"}}Non-local accounts cannot have their passwords changed.{{end}}
-{{define "password"}}Password{{end}}
-{{define "submit"}}Submit{{end}}
-`
-
-var (
- //go:embed *.html
- fs embed.FS
- changePassowrdChain viewutil.Chain
-)
-
-func Init(rtr *mux.Router) {
- rtr.HandleFunc("/change-password", handlerUserChangePassword).Methods(http.MethodGet, http.MethodPost)
-
- changePassowrdChain = viewutil.CopyEnRuWith(fs, "view_change_password.html", settingsTranslationRu)
-}
-
-func changePasswordPage(meta viewutil.Meta, form util.FormData, u *user.User) {
- viewutil.ExecutePage(meta, changePassowrdChain, changePasswordData{
- BaseData: &viewutil.BaseData{},
- Form: form,
- U: u,
- })
-}
-
-type changePasswordData struct {
- *viewutil.BaseData
- Form util.FormData
- U *user.User
-}
diff --git a/web/pages.go b/web/pages.go
index e360895..71eda2f 100644
--- a/web/pages.go
+++ b/web/pages.go
@@ -8,7 +8,7 @@ import (
//go:embed views/*.html
var fs embed.FS
-var pageOrphans, pageBacklinks, pageUserList *newtmpl.Page
+var pageOrphans, pageBacklinks, pageUserList, pageChangePassword *newtmpl.Page
func initPages() {
pageOrphans = newtmpl.NewPage(fs, "views/orphans.html", map[string]string{
@@ -27,4 +27,12 @@ func initPages() {
"editors": "Редакторы",
"readers": "Читатели",
})
+ pageChangePassword = newtmpl.NewPage(fs, "views/change-password.html", map[string]string{
+ "change password": "Сменить пароль",
+ "confirm password": "Повторите пароль",
+ "current password": "Текущий пароль",
+ "non local password change": "Пароль можно поменять только местным аккаунтам. Telegram-аккаунтам нельзя.",
+ "password": "Пароль",
+ "submit": "Поменять",
+ })
}
diff --git a/settings/settings.go b/web/password.go
similarity index 89%
rename from settings/settings.go
rename to web/password.go
index fbb3eca..0317d1b 100644
--- a/settings/settings.go
+++ b/web/password.go
@@ -1,15 +1,14 @@
-package settings
+package web
import (
"fmt"
+ "github.com/bouncepaw/mycorrhiza/util"
+ "github.com/bouncepaw/mycorrhiza/viewutil"
"mime"
"net/http"
"reflect"
- "github.com/bouncepaw/mycorrhiza/viewutil"
-
"github.com/bouncepaw/mycorrhiza/user"
- "github.com/bouncepaw/mycorrhiza/util"
)
func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
@@ -49,6 +48,7 @@ func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
f = f.WithError(err)
}
} else {
+ // TODO: handle first attempt different
err := fmt.Errorf("incorrect password")
f = f.WithError(err)
}
@@ -58,5 +58,11 @@ func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
}
w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
- changePasswordPage(viewutil.MetaFrom(w, rq), f, u)
+ _ = pageChangePassword.RenderTo(
+ viewutil.MetaFrom(w, rq),
+ map[string]any{
+ "Form": f,
+ "U": u,
+ },
+ )
}
diff --git a/settings/view_change_password.html b/web/views/change-password.html
similarity index 100%
rename from settings/view_change_password.html
rename to web/views/change-password.html
diff --git a/web/web.go b/web/web.go
index c18b379..a3caf17 100644
--- a/web/web.go
+++ b/web/web.go
@@ -21,8 +21,6 @@ import (
"github.com/bouncepaw/mycorrhiza/hypview"
"github.com/bouncepaw/mycorrhiza/interwiki"
"github.com/bouncepaw/mycorrhiza/misc"
- "github.com/bouncepaw/mycorrhiza/settings"
-
"github.com/gorilla/mux"
"github.com/bouncepaw/mycorrhiza/cfg"
@@ -91,7 +89,7 @@ func Handler() http.Handler {
settingsRouter := r.PathPrefix("/settings").Subrouter()
// TODO: check if necessary?
//settingsRouter.Use(groupMiddleware("settings"))
- settings.Init(settingsRouter)
+ settingsRouter.HandleFunc("/change-password", handlerUserChangePassword).Methods(http.MethodGet, http.MethodPost)
}
// Index page