Move change password and translate it
This commit is contained in:
parent
65989c1db1
commit
42da5cced2
@ -56,14 +56,6 @@ WithRevisions returns an html representation of `revs` that is meant to be inser
|
|||||||
</a>
|
</a>
|
||||||
<ul class="history__entries">
|
<ul class="history__entries">
|
||||||
{% for _, rev := range grp %}
|
{% for _, rev := range grp %}
|
||||||
{%= rev.asHistoryEntry(hyphaName) %}
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
{% endfor %}
|
|
||||||
{% endfunc %}
|
|
||||||
|
|
||||||
{% func (rev *Revision) asHistoryEntry(hyphaName string) %}
|
|
||||||
<li class="history__entry">
|
<li class="history__entry">
|
||||||
<a class="history-entry" href="/rev/{%s rev.Hash %}/{%s hyphaName %}">
|
<a class="history-entry" href="/rev/{%s rev.Hash %}/{%s hyphaName %}">
|
||||||
<time class="history-entry__time">{%s rev.timeToDisplay() %}</time>
|
<time class="history-entry__time">{%s rev.timeToDisplay() %}</time>
|
||||||
@ -74,4 +66,8 @@ WithRevisions returns an html representation of `revs` that is meant to be inser
|
|||||||
<span class="history-entry__author">by <a href="/hypha/{%s cfg.UserHypha %}/{%s rev.Username %}" rel="author">{%s rev.Username %}</a></span>
|
<span class="history-entry__author">by <a href="/hypha/{%s cfg.UserHypha %}/{%s rev.Username %}" rel="author">{%s rev.Username %}</a></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
{% endfor %}
|
||||||
{% endfunc %}
|
{% endfunc %}
|
||||||
@ -283,141 +283,102 @@ func StreamWithRevisions(qw422016 *qt422016.Writer, hyphaName string, revs []Rev
|
|||||||
for _, rev := range grp {
|
for _, rev := range grp {
|
||||||
//line history/view.qtpl:58
|
//line history/view.qtpl:58
|
||||||
qw422016.N().S(`
|
qw422016.N().S(`
|
||||||
|
<li class="history__entry">
|
||||||
|
<a class="history-entry" href="/rev/`)
|
||||||
|
//line history/view.qtpl:60
|
||||||
|
qw422016.E().S(rev.Hash)
|
||||||
|
//line history/view.qtpl:60
|
||||||
|
qw422016.N().S(`/`)
|
||||||
|
//line history/view.qtpl:60
|
||||||
|
qw422016.E().S(hyphaName)
|
||||||
|
//line history/view.qtpl:60
|
||||||
|
qw422016.N().S(`">
|
||||||
|
<time class="history-entry__time">`)
|
||||||
|
//line history/view.qtpl:61
|
||||||
|
qw422016.E().S(rev.timeToDisplay())
|
||||||
|
//line history/view.qtpl:61
|
||||||
|
qw422016.N().S(`</time>
|
||||||
|
</a>
|
||||||
|
<span class="history-entry__hash"><a href="/primitive-diff/`)
|
||||||
|
//line history/view.qtpl:63
|
||||||
|
qw422016.E().S(rev.Hash)
|
||||||
|
//line history/view.qtpl:63
|
||||||
|
qw422016.N().S(`/`)
|
||||||
|
//line history/view.qtpl:63
|
||||||
|
qw422016.E().S(hyphaName)
|
||||||
|
//line history/view.qtpl:63
|
||||||
|
qw422016.N().S(`">`)
|
||||||
|
//line history/view.qtpl:63
|
||||||
|
qw422016.E().S(rev.Hash)
|
||||||
|
//line history/view.qtpl:63
|
||||||
|
qw422016.N().S(`</a></span>
|
||||||
|
<span class="history-entry__msg">`)
|
||||||
|
//line history/view.qtpl:64
|
||||||
|
qw422016.E().S(rev.Message)
|
||||||
|
//line history/view.qtpl:64
|
||||||
|
qw422016.N().S(`</span>
|
||||||
`)
|
`)
|
||||||
//line history/view.qtpl:59
|
//line history/view.qtpl:65
|
||||||
rev.streamasHistoryEntry(qw422016, hyphaName)
|
if rev.Username != "anon" {
|
||||||
//line history/view.qtpl:59
|
//line history/view.qtpl:65
|
||||||
qw422016.N().S(`
|
qw422016.N().S(`
|
||||||
|
<span class="history-entry__author">by <a href="/hypha/`)
|
||||||
|
//line history/view.qtpl:66
|
||||||
|
qw422016.E().S(cfg.UserHypha)
|
||||||
|
//line history/view.qtpl:66
|
||||||
|
qw422016.N().S(`/`)
|
||||||
|
//line history/view.qtpl:66
|
||||||
|
qw422016.E().S(rev.Username)
|
||||||
|
//line history/view.qtpl:66
|
||||||
|
qw422016.N().S(`" rel="author">`)
|
||||||
|
//line history/view.qtpl:66
|
||||||
|
qw422016.E().S(rev.Username)
|
||||||
|
//line history/view.qtpl:66
|
||||||
|
qw422016.N().S(`</a></span>
|
||||||
`)
|
`)
|
||||||
//line history/view.qtpl:60
|
//line history/view.qtpl:67
|
||||||
}
|
}
|
||||||
//line history/view.qtpl:60
|
//line history/view.qtpl:67
|
||||||
|
qw422016.N().S(`
|
||||||
|
</li>
|
||||||
|
`)
|
||||||
|
//line history/view.qtpl:69
|
||||||
|
}
|
||||||
|
//line history/view.qtpl:69
|
||||||
qw422016.N().S(`
|
qw422016.N().S(`
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
`)
|
`)
|
||||||
//line history/view.qtpl:63
|
//line history/view.qtpl:72
|
||||||
}
|
}
|
||||||
//line history/view.qtpl:63
|
//line history/view.qtpl:72
|
||||||
qw422016.N().S(`
|
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) {
|
func WriteWithRevisions(qq422016 qtio422016.Writer, hyphaName string, revs []Revision) {
|
||||||
//line history/view.qtpl:64
|
//line history/view.qtpl:73
|
||||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||||
//line history/view.qtpl:64
|
//line history/view.qtpl:73
|
||||||
StreamWithRevisions(qw422016, hyphaName, revs)
|
StreamWithRevisions(qw422016, hyphaName, revs)
|
||||||
//line history/view.qtpl:64
|
//line history/view.qtpl:73
|
||||||
qt422016.ReleaseWriter(qw422016)
|
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 {
|
func WithRevisions(hyphaName string, revs []Revision) string {
|
||||||
//line history/view.qtpl:64
|
//line history/view.qtpl:73
|
||||||
qb422016 := qt422016.AcquireByteBuffer()
|
qb422016 := qt422016.AcquireByteBuffer()
|
||||||
//line history/view.qtpl:64
|
//line history/view.qtpl:73
|
||||||
WriteWithRevisions(qb422016, hyphaName, revs)
|
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(`
|
|
||||||
<li class="history__entry">
|
|
||||||
<a class="history-entry" href="/rev/`)
|
|
||||||
//line history/view.qtpl:68
|
|
||||||
qw422016.E().S(rev.Hash)
|
|
||||||
//line history/view.qtpl:68
|
|
||||||
qw422016.N().S(`/`)
|
|
||||||
//line history/view.qtpl:68
|
|
||||||
qw422016.E().S(hyphaName)
|
|
||||||
//line history/view.qtpl:68
|
|
||||||
qw422016.N().S(`">
|
|
||||||
<time class="history-entry__time">`)
|
|
||||||
//line history/view.qtpl:69
|
|
||||||
qw422016.E().S(rev.timeToDisplay())
|
|
||||||
//line history/view.qtpl:69
|
|
||||||
qw422016.N().S(`</time>
|
|
||||||
</a>
|
|
||||||
<span class="history-entry__hash"><a href="/primitive-diff/`)
|
|
||||||
//line history/view.qtpl:71
|
|
||||||
qw422016.E().S(rev.Hash)
|
|
||||||
//line history/view.qtpl:71
|
|
||||||
qw422016.N().S(`/`)
|
|
||||||
//line history/view.qtpl:71
|
|
||||||
qw422016.E().S(hyphaName)
|
|
||||||
//line history/view.qtpl:71
|
|
||||||
qw422016.N().S(`">`)
|
|
||||||
//line history/view.qtpl:71
|
|
||||||
qw422016.E().S(rev.Hash)
|
|
||||||
//line history/view.qtpl:71
|
|
||||||
qw422016.N().S(`</a></span>
|
|
||||||
<span class="history-entry__msg">`)
|
|
||||||
//line history/view.qtpl:72
|
|
||||||
qw422016.E().S(rev.Message)
|
|
||||||
//line history/view.qtpl:72
|
|
||||||
qw422016.N().S(`</span>
|
|
||||||
`)
|
|
||||||
//line history/view.qtpl:73
|
//line history/view.qtpl:73
|
||||||
if rev.Username != "anon" {
|
|
||||||
//line history/view.qtpl:73
|
|
||||||
qw422016.N().S(`
|
|
||||||
<span class="history-entry__author">by <a href="/hypha/`)
|
|
||||||
//line history/view.qtpl:74
|
|
||||||
qw422016.E().S(cfg.UserHypha)
|
|
||||||
//line history/view.qtpl:74
|
|
||||||
qw422016.N().S(`/`)
|
|
||||||
//line history/view.qtpl:74
|
|
||||||
qw422016.E().S(rev.Username)
|
|
||||||
//line history/view.qtpl:74
|
|
||||||
qw422016.N().S(`" rel="author">`)
|
|
||||||
//line history/view.qtpl:74
|
|
||||||
qw422016.E().S(rev.Username)
|
|
||||||
//line history/view.qtpl:74
|
|
||||||
qw422016.N().S(`</a></span>
|
|
||||||
`)
|
|
||||||
//line history/view.qtpl:75
|
|
||||||
}
|
|
||||||
//line history/view.qtpl:75
|
|
||||||
qw422016.N().S(`
|
|
||||||
</li>
|
|
||||||
`)
|
|
||||||
//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)
|
qs422016 := string(qb422016.B)
|
||||||
//line history/view.qtpl:77
|
//line history/view.qtpl:73
|
||||||
qt422016.ReleaseByteBuffer(qb422016)
|
qt422016.ReleaseByteBuffer(qb422016)
|
||||||
//line history/view.qtpl:77
|
//line history/view.qtpl:73
|
||||||
return qs422016
|
return qs422016
|
||||||
//line history/view.qtpl:77
|
//line history/view.qtpl:73
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
|
||||||
}
|
|
||||||
10
web/pages.go
10
web/pages.go
@ -8,7 +8,7 @@ import (
|
|||||||
//go:embed views/*.html
|
//go:embed views/*.html
|
||||||
var fs embed.FS
|
var fs embed.FS
|
||||||
|
|
||||||
var pageOrphans, pageBacklinks, pageUserList *newtmpl.Page
|
var pageOrphans, pageBacklinks, pageUserList, pageChangePassword *newtmpl.Page
|
||||||
|
|
||||||
func initPages() {
|
func initPages() {
|
||||||
pageOrphans = newtmpl.NewPage(fs, "views/orphans.html", map[string]string{
|
pageOrphans = newtmpl.NewPage(fs, "views/orphans.html", map[string]string{
|
||||||
@ -27,4 +27,12 @@ func initPages() {
|
|||||||
"editors": "Редакторы",
|
"editors": "Редакторы",
|
||||||
"readers": "Читатели",
|
"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": "Поменять",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
package settings
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
||||||
@ -49,6 +48,7 @@ func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
|||||||
f = f.WithError(err)
|
f = f.WithError(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: handle first attempt different
|
||||||
err := fmt.Errorf("incorrect password")
|
err := fmt.Errorf("incorrect password")
|
||||||
f = f.WithError(err)
|
f = f.WithError(err)
|
||||||
}
|
}
|
||||||
@ -58,5 +58,11 @@ func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
|||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
|
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,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@ -21,8 +21,6 @@ import (
|
|||||||
"github.com/bouncepaw/mycorrhiza/hypview"
|
"github.com/bouncepaw/mycorrhiza/hypview"
|
||||||
"github.com/bouncepaw/mycorrhiza/interwiki"
|
"github.com/bouncepaw/mycorrhiza/interwiki"
|
||||||
"github.com/bouncepaw/mycorrhiza/misc"
|
"github.com/bouncepaw/mycorrhiza/misc"
|
||||||
"github.com/bouncepaw/mycorrhiza/settings"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
@ -91,7 +89,7 @@ func Handler() http.Handler {
|
|||||||
settingsRouter := r.PathPrefix("/settings").Subrouter()
|
settingsRouter := r.PathPrefix("/settings").Subrouter()
|
||||||
// TODO: check if necessary?
|
// TODO: check if necessary?
|
||||||
//settingsRouter.Use(groupMiddleware("settings"))
|
//settingsRouter.Use(groupMiddleware("settings"))
|
||||||
settings.Init(settingsRouter)
|
settingsRouter.HandleFunc("/change-password", handlerUserChangePassword).Methods(http.MethodGet, http.MethodPost)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index page
|
// Index page
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user