{% import "net/http" %} {% import "sort" %} {% import "github.com/bouncepaw/mycorrhiza/cfg" %} {% import "github.com/bouncepaw/mycorrhiza/l18n" %} {% import "github.com/bouncepaw/mycorrhiza/user" %} {% func Register(rq *http.Request) %} {% code lc := l18n.FromRequest(rq) %}
{% if cfg.AllowRegistration %} {%= telegramWidget(lc) %} {% elseif cfg.UseAuth %}

{%s lc.Get("auth.noregister") %}

← {%s lc.Get("auth.go_back") %}

{% else %}

{%s lc.Get("auth.noauth") %}

← {%s lc.Get("auth.go_back") %}

{% endif %}
{% endfunc %} {% func Login(lc *l18n.Localizer) %}
{% if cfg.UseAuth %} {%= telegramWidget(lc) %} {% else %}

{%s lc.Get("auth.noauth") %}

← {%s lc.Get("auth.go_home") %}

{% endif %}
{% endfunc %} Telegram auth widget was requested by Yogurt. As you can see, we don't offer user administrators control over it. Of course we don't. {% func telegramWidget(lc *l18n.Localizer) %} {% if cfg.TelegramEnabled %}

{%s lc.Get("auth.telegram_tip") %}

{% endif %} {% endfunc %} {% func LoginError(err string, lc *l18n.Localizer) %}
{% switch err %} {% case "unknown username" %}

{%s lc.Get("auth.error_username") %}

{% case "wrong password" %}

{%s lc.Get("auth.error_password") %}

{% default %}

{%s err %}

{% endswitch %}

← {%s lc.Get("auth.try_again") %}

{% endfunc %} {% func Logout(can bool, lc *l18n.Localizer) %}
{% if can %}

{%s lc.Get("auth.logout_header") %}

{%s lc.Get("auth.go_home") %}
{% else %}

{%s lc.Get("auth.logout_anon") %}

{%s lc.Get("auth.login_title") %}

← {%s lc.Get("auth.go_home") %}

{% endif %}
{% endfunc %} {% func Lock(lc *l18n.Localizer) %} 🔒 {%s lc.Get("auth.lock_title") %}

🔒

{%s lc.Get("auth.lock_title") %}

{%= telegramWidget(lc) %}
{% endfunc %} {% code var userListL10n = map[string]l10nEntry{ "heading": en("List of users").ru("Список пользователей"), "administrators": en("Administrators").ru("Администраторы"), "moderators": en("Moderators").ru("Модераторы"), "editors": en("Editors").ru("Редакторы"), } %} {% func UserList(lc *l18n.Localizer) %}
{% code var get = func(key string) string { return userListL10n[key].get(lc.Locale) } var ( admins = make([]string, 0) moderators = make([]string, 0) editors = make([]string, 0) ) for u := range user.YieldUsers() { switch u.Group { // What if we place the users into sorted slices? case "admin": admins = append(admins, u.Name) case "moderator": moderators = append(moderators, u.Name) case "editor", "trusted": editors = append(editors, u.Name) } } sort.Strings(admins) sort.Strings(moderators) sort.Strings(editors) %}

{%s get("heading") %}

{%s get("administrators") %}

    {% for _, name := range admins %}
  1. {%s name %}
  2. {% endfor %}

{%s get("moderators") %}

    {% for _, name := range moderators %}
  1. {%s name %}
  2. {% endfor %}

{%s get("editors") %}

    {% for _, name := range editors %}
  1. {%s name %}
  2. {% endfor %}
{% endfunc %}