2021-04-12 17:40:43 +00:00
|
|
|
{% import "net/http" %}
|
2022-04-02 08:00:10 +00:00
|
|
|
{% import "sort" %}
|
2021-05-09 09:36:39 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
2021-09-06 17:46:34 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
2022-04-02 08:00:10 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/user" %}
|
2020-11-14 10:39:18 +00:00
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func Register(rq *http.Request) %}
|
2021-09-06 17:46:34 +00:00
|
|
|
{% code
|
|
|
|
lc := l18n.FromRequest(rq)
|
|
|
|
%}
|
2021-04-12 17:40:43 +00:00
|
|
|
<div class="layout">
|
|
|
|
<main class="main-width">
|
|
|
|
<section>
|
2021-07-02 08:20:03 +00:00
|
|
|
{% if cfg.AllowRegistration %}
|
2021-04-12 17:40:43 +00:00
|
|
|
<form class="modal" method="post" action="/register?{%s rq.URL.RawQuery %}" id="register-form" enctype="multipart/form-data" autocomplete="off">
|
|
|
|
<fieldset class="modal__fieldset">
|
2021-09-06 17:46:34 +00:00
|
|
|
<legend class="modal__title">{%s lc.Get("auth.register_header", &l18n.Replacements{"name": cfg.WikiName}) %}</legend>
|
2021-04-12 17:40:43 +00:00
|
|
|
|
2021-09-06 17:46:34 +00:00
|
|
|
<label for="register-form__username">{%s lc.Get("auth.username") %}</label>
|
2021-04-12 17:40:43 +00:00
|
|
|
<br>
|
|
|
|
<input type="text" required autofocus id="login-form__username" name="username">
|
|
|
|
<br>
|
2021-09-06 17:46:34 +00:00
|
|
|
<label for="login-form__password">{%s lc.Get("auth.password") %}</label>
|
2021-04-12 17:40:43 +00:00
|
|
|
<br>
|
|
|
|
<input type="password" required name="password">
|
2021-09-06 17:46:34 +00:00
|
|
|
<p>{%s lc.Get("auth.password_tip") %}</p>
|
|
|
|
<p>{%s lc.Get("auth.cookie_tip") %}</p>
|
|
|
|
<button class="btn" type="submit" value="Register">{%s lc.Get("auth.register_button") %}</button>
|
|
|
|
<a class="btn btn_weak" href="/{%s rq.URL.RawQuery %}">{%s lc.Get("ui.cancel") %}</a>
|
2021-04-12 17:40:43 +00:00
|
|
|
</fieldset>
|
|
|
|
</form>
|
2022-03-20 21:24:40 +00:00
|
|
|
{%= telegramWidget(lc) %}
|
2021-07-02 08:20:03 +00:00
|
|
|
{% elseif cfg.UseAuth %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p>{%s lc.Get("auth.noregister") %}</p>
|
|
|
|
<p><a href="/{%s rq.URL.RawQuery %}">← {%s lc.Get("auth.go_back") %}</a></p>
|
2021-04-12 17:40:43 +00:00
|
|
|
{% else %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p>{%s lc.Get("auth.noauth") %}</p>
|
|
|
|
<p><a href="/{%s rq.URL.RawQuery %}">← {%s lc.Get("auth.go_back") %}</a></p>
|
2021-04-12 17:40:43 +00:00
|
|
|
{% endif %}
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
{% endfunc %}
|
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func Login(lc *l18n.Localizer) %}
|
2021-01-26 05:41:57 +00:00
|
|
|
<div class="layout">
|
|
|
|
<main class="main-width">
|
2020-11-14 10:39:18 +00:00
|
|
|
<section>
|
2021-07-02 08:20:03 +00:00
|
|
|
{% if cfg.UseAuth %}
|
2021-12-30 21:07:39 +00:00
|
|
|
<form class="modal" method="post" action="/login" id="login-form" enctype="multipart/form-data" autocomplete="on">
|
2021-02-23 14:36:12 +00:00
|
|
|
<fieldset class="modal__fieldset">
|
2021-09-06 17:46:34 +00:00
|
|
|
<legend class="modal__title">{%s lc.Get("auth.login_header", &l18n.Replacements{"name": cfg.WikiName}) %}</legend>
|
|
|
|
<label for="login-form__username">{%s lc.Get("auth.username") %}</label>
|
2021-02-23 14:36:12 +00:00
|
|
|
<br>
|
|
|
|
<input type="text" required autofocus id="login-form__username" name="username" autocomplete="username">
|
|
|
|
<br>
|
2021-09-06 17:46:34 +00:00
|
|
|
<label for="login-form__password">{%s lc.Get("auth.password") %}</label>
|
2021-02-23 14:36:12 +00:00
|
|
|
<br>
|
|
|
|
<input type="password" required name="password" autocomplete="current-password">
|
2021-09-06 17:46:34 +00:00
|
|
|
<p>{%s lc.Get("auth.cookie_tip") %}</p>
|
|
|
|
<button class="btn" type="submit" value="Log in">{%s lc.Get("auth.login_button") %}</button>
|
|
|
|
<a class="btn btn_weak" href="/">{%s lc.Get("ui.cancel") %}</a>
|
2020-11-14 10:39:18 +00:00
|
|
|
</fieldset>
|
|
|
|
</form>
|
2022-03-20 21:24:40 +00:00
|
|
|
{%= telegramWidget(lc) %}
|
2020-11-14 10:39:18 +00:00
|
|
|
{% else %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p>{%s lc.Get("auth.noauth") %}</p>
|
|
|
|
<p><a class="btn btn_weak" href="/">← {%s lc.Get("auth.go_home") %}</a></p>
|
2020-11-14 10:39:18 +00:00
|
|
|
{% endif %}
|
|
|
|
</section>
|
|
|
|
</main>
|
2021-01-26 05:41:57 +00:00
|
|
|
</div>
|
2020-11-14 10:39:18 +00:00
|
|
|
{% endfunc %}
|
|
|
|
|
2021-07-14 19:51:55 +00:00
|
|
|
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.
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func telegramWidget(lc *l18n.Localizer) %}
|
2021-07-14 19:51:55 +00:00
|
|
|
{% if cfg.TelegramEnabled %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p class="telegram-notice">{%s lc.Get("auth.telegram_tip") %}</p>
|
2021-07-14 19:51:55 +00:00
|
|
|
<script async src="https://telegram.org/js/telegram-widget.js?15" data-telegram-login="{%s cfg.TelegramBotName %}" data-size="medium" data-userpic="false" data-auth-url="{%s cfg.URL %}/telegram-login"></script>
|
|
|
|
{% endif %}
|
|
|
|
{% endfunc %}
|
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func LoginError(err string, lc *l18n.Localizer) %}
|
2021-01-26 05:41:57 +00:00
|
|
|
<div class="layout">
|
|
|
|
<main class="main-width">
|
2020-11-14 10:39:18 +00:00
|
|
|
<section>
|
|
|
|
{% switch err %}
|
|
|
|
{% case "unknown username" %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p class="error">{%s lc.Get("auth.error_username") %}</p>
|
2020-11-14 10:39:18 +00:00
|
|
|
{% case "wrong password" %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p class="error">{%s lc.Get("auth.error_password") %}</p>
|
2020-11-14 10:39:18 +00:00
|
|
|
{% default %}
|
|
|
|
<p class="error">{%s err %}</p>
|
|
|
|
{% endswitch %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p><a href="/login">← {%s lc.Get("auth.try_again") %}</a></p>
|
2020-11-14 10:39:18 +00:00
|
|
|
</section>
|
|
|
|
</main>
|
2021-01-26 05:41:57 +00:00
|
|
|
</div>
|
2020-11-14 10:39:18 +00:00
|
|
|
{% endfunc %}
|
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func Logout(can bool, lc *l18n.Localizer) %}
|
2021-01-26 05:41:57 +00:00
|
|
|
<div class="layout">
|
|
|
|
<main class="main-width">
|
2020-11-14 13:03:06 +00:00
|
|
|
<section>
|
|
|
|
{% if can %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<h1>{%s lc.Get("auth.logout_header") %}</h1>
|
2021-12-30 21:07:39 +00:00
|
|
|
<form method="POST" action="/logout">
|
|
|
|
<input class="btn btn_accent" type="submit" value="{%s lc.Get("auth.logout_button") %}"/>
|
|
|
|
<a class="btn btn_weak" href="/">{%s lc.Get("auth.go_home") %}</a>
|
|
|
|
</form>
|
2020-11-14 13:03:06 +00:00
|
|
|
{% else %}
|
2021-09-06 17:46:34 +00:00
|
|
|
<p>{%s lc.Get("auth.logout_anon") %}</p>
|
|
|
|
<p><a href="/login">{%s lc.Get("auth.login_title") %}</a></p>
|
|
|
|
<p><a href="/">← {%s lc.Get("auth.go_home") %}</a></p>
|
2020-11-14 13:03:06 +00:00
|
|
|
{% endif %}
|
|
|
|
</section>
|
|
|
|
</main>
|
2021-01-26 05:41:57 +00:00
|
|
|
</div>
|
2020-11-14 13:03:06 +00:00
|
|
|
{% endfunc %}
|
2021-07-09 11:47:50 +00:00
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func Lock(lc *l18n.Localizer) %}
|
2021-07-09 11:47:50 +00:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2021-09-06 17:46:34 +00:00
|
|
|
<title>🔒 {%s lc.Get("auth.lock_title") %}</title>
|
2021-07-09 11:47:50 +00:00
|
|
|
<link rel="shortcut icon" href="/static/favicon.ico">
|
|
|
|
<link rel="stylesheet" href="/static/style.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<main class="locked-notice">
|
|
|
|
<section class="locked-notice__message">
|
|
|
|
<p class="locked-notice__lock">🔒</p>
|
2021-09-06 17:46:34 +00:00
|
|
|
<h1 class="locked-notice__title">{%s lc.Get("auth.lock_title") %}</h1>
|
2021-12-30 21:07:39 +00:00
|
|
|
<form class="locked-notice__login-form" method="post" action="/login" id="login-form" enctype="multipart/form-data" autocomplete="on">
|
2021-09-06 17:46:34 +00:00
|
|
|
<label for="login-form__username">{%s lc.Get("auth.username") %}</label>
|
2021-07-24 11:09:39 +00:00
|
|
|
<br>
|
|
|
|
<input type="text" required autofocus id="login-form__username" name="username" autocomplete="username">
|
|
|
|
<br>
|
2021-09-06 17:46:34 +00:00
|
|
|
<label for="login-form__password">{%s lc.Get("auth.password") %}</label>
|
2021-07-24 11:09:39 +00:00
|
|
|
<br>
|
|
|
|
<input type="password" required name="password" autocomplete="current-password">
|
|
|
|
<br>
|
2021-09-06 17:46:34 +00:00
|
|
|
<button class="btn" type="submit" value="Log in">{%s lc.Get("auth.login_button") %}</button>
|
2021-07-24 11:09:39 +00:00
|
|
|
</form>
|
2022-03-20 21:24:40 +00:00
|
|
|
{%= telegramWidget(lc) %}
|
2021-07-09 11:47:50 +00:00
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</body>
|
|
|
|
</html>
|
2021-07-14 19:51:55 +00:00
|
|
|
{% endfunc %}
|
2022-04-02 08:00:10 +00:00
|
|
|
|
|
|
|
{% 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) %}
|
|
|
|
<div class="layout">
|
|
|
|
<main class="main-width user-list">
|
|
|
|
{% 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)
|
|
|
|
%}
|
|
|
|
<h1>{%s get("heading") %}</h1>
|
|
|
|
<section>
|
|
|
|
<h2>{%s get("administrators") %}</h2>
|
|
|
|
<ol>{% for _, name := range admins %}
|
|
|
|
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
|
|
|
|
{% endfor %}</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<h2>{%s get("moderators") %}</h2>
|
|
|
|
<ol>{% for _, name := range moderators %}
|
|
|
|
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
|
|
|
|
{% endfor %}</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<h2>{%s get("editors") %}</h2>
|
|
|
|
<ol>{% for _, name := range editors %}
|
|
|
|
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
|
|
|
|
{% endfor %}</ol>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
{% endfunc %}
|