mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-31 12:16:15 +00:00
51f5ebf46d
GET /login and POST /login-data are merged into /login. GET /logout and POST /logout-confirm are merged into /logout. The logout form now looks more consistent with other forms. Used io.WriteString instead of Fprint where it wasn't like that for some reason.
151 lines
5.6 KiB
Plaintext
151 lines
5.6 KiB
Plaintext
{% import "net/http" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
|
|
|
{% func RegisterHTML(rq *http.Request) %}
|
|
{% code
|
|
lc := l18n.FromRequest(rq)
|
|
%}
|
|
<div class="layout">
|
|
<main class="main-width">
|
|
<section>
|
|
{% if cfg.AllowRegistration %}
|
|
<form class="modal" method="post" action="/register?{%s rq.URL.RawQuery %}" id="register-form" enctype="multipart/form-data" autocomplete="off">
|
|
<fieldset class="modal__fieldset">
|
|
<legend class="modal__title">{%s lc.Get("auth.register_header", &l18n.Replacements{"name": cfg.WikiName}) %}</legend>
|
|
|
|
<label for="register-form__username">{%s lc.Get("auth.username") %}</label>
|
|
<br>
|
|
<input type="text" required autofocus id="login-form__username" name="username">
|
|
<br>
|
|
<label for="login-form__password">{%s lc.Get("auth.password") %}</label>
|
|
<br>
|
|
<input type="password" required name="password">
|
|
<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>
|
|
</fieldset>
|
|
</form>
|
|
{%= telegramWidgetHTML(lc) %}
|
|
{% elseif cfg.UseAuth %}
|
|
<p>{%s lc.Get("auth.noregister") %}</p>
|
|
<p><a href="/{%s rq.URL.RawQuery %}">← {%s lc.Get("auth.go_back") %}</a></p>
|
|
{% else %}
|
|
<p>{%s lc.Get("auth.noauth") %}</p>
|
|
<p><a href="/{%s rq.URL.RawQuery %}">← {%s lc.Get("auth.go_back") %}</a></p>
|
|
{% endif %}
|
|
</section>
|
|
</main>
|
|
</div>
|
|
{% endfunc %}
|
|
|
|
{% func LoginHTML(lc *l18n.Localizer) %}
|
|
<div class="layout">
|
|
<main class="main-width">
|
|
<section>
|
|
{% if cfg.UseAuth %}
|
|
<form class="modal" method="post" action="/login" id="login-form" enctype="multipart/form-data" autocomplete="on">
|
|
<fieldset class="modal__fieldset">
|
|
<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>
|
|
<br>
|
|
<input type="text" required autofocus id="login-form__username" name="username" autocomplete="username">
|
|
<br>
|
|
<label for="login-form__password">{%s lc.Get("auth.password") %}</label>
|
|
<br>
|
|
<input type="password" required name="password" autocomplete="current-password">
|
|
<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>
|
|
</fieldset>
|
|
</form>
|
|
{%= telegramWidgetHTML(lc) %}
|
|
{% else %}
|
|
<p>{%s lc.Get("auth.noauth") %}</p>
|
|
<p><a class="btn btn_weak" href="/">← {%s lc.Get("auth.go_home") %}</a></p>
|
|
{% endif %}
|
|
</section>
|
|
</main>
|
|
</div>
|
|
{% 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 telegramWidgetHTML(lc *l18n.Localizer) %}
|
|
{% if cfg.TelegramEnabled %}
|
|
<p class="telegram-notice">{%s lc.Get("auth.telegram_tip") %}</p>
|
|
<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 %}
|
|
|
|
{% func LoginErrorHTML(err string, lc *l18n.Localizer) %}
|
|
<div class="layout">
|
|
<main class="main-width">
|
|
<section>
|
|
{% switch err %}
|
|
{% case "unknown username" %}
|
|
<p class="error">{%s lc.Get("auth.error_username") %}</p>
|
|
{% case "wrong password" %}
|
|
<p class="error">{%s lc.Get("auth.error_password") %}</p>
|
|
{% default %}
|
|
<p class="error">{%s err %}</p>
|
|
{% endswitch %}
|
|
<p><a href="/login">← {%s lc.Get("auth.try_again") %}</a></p>
|
|
</section>
|
|
</main>
|
|
</div>
|
|
{% endfunc %}
|
|
|
|
{% func LogoutHTML(can bool, lc *l18n.Localizer) %}
|
|
<div class="layout">
|
|
<main class="main-width">
|
|
<section>
|
|
{% if can %}
|
|
<h1>{%s lc.Get("auth.logout_header") %}</h1>
|
|
<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>
|
|
{% else %}
|
|
<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>
|
|
{% endif %}
|
|
</section>
|
|
</main>
|
|
</div>
|
|
{% endfunc %}
|
|
|
|
{% func LockHTML(lc *l18n.Localizer) %}
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>🔒 {%s lc.Get("auth.lock_title") %}</title>
|
|
<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>
|
|
<h1 class="locked-notice__title">{%s lc.Get("auth.lock_title") %}</h1>
|
|
<form class="locked-notice__login-form" method="post" action="/login" id="login-form" enctype="multipart/form-data" autocomplete="on">
|
|
<label for="login-form__username">{%s lc.Get("auth.username") %}</label>
|
|
<br>
|
|
<input type="text" required autofocus id="login-form__username" name="username" autocomplete="username">
|
|
<br>
|
|
<label for="login-form__password">{%s lc.Get("auth.password") %}</label>
|
|
<br>
|
|
<input type="password" required name="password" autocomplete="current-password">
|
|
<br>
|
|
<button class="btn" type="submit" value="Log in">{%s lc.Get("auth.login_button") %}</button>
|
|
</form>
|
|
{%= telegramWidgetHTML(lc) %}
|
|
</section>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
{% endfunc %}
|