{%s lc.Get("auth.noregister") %}
-← {%s lc.Get("auth.go_back") %}
- {% else %} -{%s lc.Get("auth.noauth") %}
- - {% endif %} -diff --git a/auth/auth.qtpl b/auth/auth.qtpl
deleted file mode 100644
index 1a27ce7..0000000
--- a/auth/auth.qtpl
+++ /dev/null
@@ -1,143 +0,0 @@
-{% import "net/http" %}
-{% import "github.com/bouncepaw/mycorrhiza/internal/cfg" %}
-{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
-
-{% func Register(rq *http.Request) %}
-{% code
- lc := l18n.FromRequest(rq)
-%}
- {%s lc.Get("auth.noregister") %} ← {%s lc.Get("auth.go_back") %} {%s lc.Get("auth.noauth") %} {%s lc.Get("auth.noauth") %}
{%s lc.Get("auth.telegram_tip") %}
- -{% endif %} -{% endfunc %} - -{% func LoginError(err string, lc *l18n.Localizer) %} -{%s lc.Get("auth.error_username") %}
- {% case "wrong password" %} -{%s lc.Get("auth.error_password") %}
- {% default %} -{%s err %}
- {% endswitch %} - -{%s lc.Get("auth.logout_anon") %}
- - - {% endif %} -`) -//line auth/auth.qtpl:31 - qw422016.E().S(lc.Get("auth.noregister")) -//line auth/auth.qtpl:31 - qw422016.N().S(`
- - `) -//line auth/auth.qtpl:33 - } else { -//line auth/auth.qtpl:33 - qw422016.N().S(` -`) -//line auth/auth.qtpl:34 - qw422016.E().S(lc.Get("auth.noauth")) -//line auth/auth.qtpl:34 - qw422016.N().S(`
- - `) -//line auth/auth.qtpl:36 - } -//line auth/auth.qtpl:36 - qw422016.N().S(` -`) -//line auth/auth.qtpl:62 - qw422016.E().S(lc.Get("auth.noauth")) -//line auth/auth.qtpl:62 - qw422016.N().S(`
- - `) -//line auth/auth.qtpl:64 - } -//line auth/auth.qtpl:64 - qw422016.N().S(` -`) -//line auth/auth.qtpl:72 - qw422016.E().S(lc.Get("auth.telegram_tip")) -//line auth/auth.qtpl:72 - qw422016.N().S(`
- -`) -//line auth/auth.qtpl:74 - } -//line auth/auth.qtpl:74 - qw422016.N().S(` -`) -//line auth/auth.qtpl:75 -} - -//line auth/auth.qtpl:75 -func writetelegramWidget(qq422016 qtio422016.Writer, lc *l18n.Localizer) { -//line auth/auth.qtpl:75 - qw422016 := qt422016.AcquireWriter(qq422016) -//line auth/auth.qtpl:75 - streamtelegramWidget(qw422016, lc) -//line auth/auth.qtpl:75 - qt422016.ReleaseWriter(qw422016) -//line auth/auth.qtpl:75 -} - -//line auth/auth.qtpl:75 -func telegramWidget(lc *l18n.Localizer) string { -//line auth/auth.qtpl:75 - qb422016 := qt422016.AcquireByteBuffer() -//line auth/auth.qtpl:75 - writetelegramWidget(qb422016, lc) -//line auth/auth.qtpl:75 - qs422016 := string(qb422016.B) -//line auth/auth.qtpl:75 - qt422016.ReleaseByteBuffer(qb422016) -//line auth/auth.qtpl:75 - return qs422016 -//line auth/auth.qtpl:75 -} - -//line auth/auth.qtpl:77 -func StreamLoginError(qw422016 *qt422016.Writer, err string, lc *l18n.Localizer) { -//line auth/auth.qtpl:77 - qw422016.N().S(` -`) -//line auth/auth.qtpl:82 - qw422016.E().S(lc.Get("auth.error_username")) -//line auth/auth.qtpl:82 - qw422016.N().S(`
- `) -//line auth/auth.qtpl:83 - case "wrong password": -//line auth/auth.qtpl:83 - qw422016.N().S(` -`) -//line auth/auth.qtpl:84 - qw422016.E().S(lc.Get("auth.error_password")) -//line auth/auth.qtpl:84 - qw422016.N().S(`
- `) -//line auth/auth.qtpl:85 - default: -//line auth/auth.qtpl:85 - qw422016.N().S(` -`) -//line auth/auth.qtpl:86 - qw422016.E().S(err) -//line auth/auth.qtpl:86 - qw422016.N().S(`
- `) -//line auth/auth.qtpl:87 - } -//line auth/auth.qtpl:87 - qw422016.N().S(` - -`) -//line auth/auth.qtpl:103 - qw422016.E().S(lc.Get("auth.logout_anon")) -//line auth/auth.qtpl:103 - qw422016.N().S(`
- - - `) -//line auth/auth.qtpl:106 - } -//line auth/auth.qtpl:106 - qw422016.N().S(` -{{block "error username" .}}Unknown username.{{end}}
+ {{else if .ErrWrongPassword}} +{{block "error password" .}}Wrong password.{{end}}
+ {{else if .ErrTelegram}} +{{block "error telegram" .}}Could not authorize using Telegram.{{end}}
+ {{else if .Err}} +{{.Err}}
+ {{end}} + + + {{template "telegram widget" .}} + {{else}} +{{block "auth disabled" .}}Authentication is disabled. You can make edits anonymously.{{end}}
+ + {{end}} +{{block "cannot log out anon" .}}You cannot log out because you are not logged in.{{end}}
+ + + {{end}} +{%s lc.Get("auth.noregister") %}
+← {%s lc.Get("auth.go_back") %}
+ {{else}} +{%s lc.Get("auth.noauth") %}
+ + {{end}} +{{block "telegram tip" .}}You can log in using Telegram. It only works if you have set your @username in Telegram and this username is free on this wiki.{{end}}
+ + {{end}} +{{end}} diff --git a/web/web.go b/web/web.go index 44020ca..2887914 100644 --- a/web/web.go +++ b/web/web.go @@ -5,17 +5,17 @@ import ( "errors" "fmt" "github.com/bouncepaw/mycorrhiza/internal/cfg" - user2 "github.com/bouncepaw/mycorrhiza/internal/user" + "github.com/bouncepaw/mycorrhiza/internal/user" "github.com/bouncepaw/mycorrhiza/l18n" - viewutil2 "github.com/bouncepaw/mycorrhiza/web/viewutil" + "github.com/bouncepaw/mycorrhiza/web/viewutil" "io" "log" + "log/slog" "mime" "net/http" "net/url" "strings" - "github.com/bouncepaw/mycorrhiza/auth" "github.com/bouncepaw/mycorrhiza/categories" "github.com/bouncepaw/mycorrhiza/help" "github.com/bouncepaw/mycorrhiza/history/histweb" @@ -63,7 +63,7 @@ func Handler() http.Handler { r := router.PathPrefix("").Subrouter() r.Use(func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, rq *http.Request) { - user := user2.FromRequest(rq) + user := user.FromRequest(rq) if !user.ShowLockMaybe(w, rq) { next.ServeHTTP(w, rq) } @@ -117,7 +117,7 @@ func Handler() http.Handler { func groupMiddleware(group string) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, rq *http.Request) { - if cfg.UseAuth && user2.CanProceed(rq, group) { + if cfg.UseAuth && user.CanProceed(rq, group) { next.ServeHTTP(w, rq) return } @@ -133,8 +133,8 @@ func groupMiddleware(group string) func(http.Handler) http.Handler { // Auth func handlerUserList(w http.ResponseWriter, rq *http.Request) { - admins, moderators, editors, readers := user2.UsersInGroups() - _ = pageUserList.RenderTo(viewutil2.MetaFrom(w, rq), + admins, moderators, editors, readers := user.UsersInGroups() + _ = pageUserList.RenderTo(viewutil.MetaFrom(w, rq), map[string]any{ "Admins": admins, "Moderators": moderators, @@ -144,53 +144,47 @@ func handlerUserList(w http.ResponseWriter, rq *http.Request) { } func handlerLock(w http.ResponseWriter, rq *http.Request) { - _, _ = io.WriteString(w, auth.Lock(l18n.FromRequest(rq))) + _ = pageAuthLock.RenderTo(viewutil.MetaFrom(w, rq), map[string]any{}) } // handlerRegister displays the register form (GET) or registers the user (POST). func handlerRegister(w http.ResponseWriter, rq *http.Request) { - lc := l18n.FromRequest(rq) util.PrepareRq(rq) if rq.Method == http.MethodGet { - _, _ = io.WriteString( - w, - viewutil2.Base( - viewutil2.MetaFrom(w, rq), - lc.Get("auth.register_title"), - auth.Register(rq), - map[string]string{}, - ), - ) + slog.Info("Showing registration form") + _ = pageAuthRegister.RenderTo(viewutil.MetaFrom(w, rq), map[string]any{ + "UseAuth": cfg.UseAuth, + "AllowRegistration": cfg.AllowRegistration, + "RawQuery": rq.URL.RawQuery, + "WikiName": cfg.WikiName, + }) return } var ( username = rq.PostFormValue("username") password = rq.PostFormValue("password") - err = user2.Register(username, password, "editor", "local", false) + err = user.Register(username, password, "editor", "local", false) ) if err != nil { - log.Printf("Failed to register ‘%s’: %s", username, err.Error()) + slog.Info("Failed to register", "username", username, "err", err.Error()) w.Header().Set("Content-Type", mime.TypeByExtension(".html")) w.WriteHeader(http.StatusBadRequest) - _, _ = io.WriteString( - w, - viewutil2.Base( - viewutil2.MetaFrom(w, rq), - lc.Get("auth.register_title"), - fmt.Sprintf( - `%s
%s
%s
%s
%s