2021-06-22 20:38:08 +00:00
|
|
|
<!DOCTYPE html>
|
2016-12-18 13:12:14 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
{% import "header.html" as header %}
|
|
|
|
<title>Login/Register</title>
|
|
|
|
<meta charset="UTF-8">
|
2017-07-21 06:10:48 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
2018-02-24 20:51:36 +00:00
|
|
|
<link rel="stylesheet" href="/static/css/common.css">
|
2020-09-03 18:50:16 +00:00
|
|
|
<link rel="stylesheet" href="/static/css/etiquette.css">
|
2019-08-14 20:43:35 +00:00
|
|
|
{% if theme %}<link rel="stylesheet" href="/static/css/theme_{{theme}}.css">{% endif %}
|
2018-02-24 20:51:36 +00:00
|
|
|
<script src="/static/js/common.js"></script>
|
2018-09-23 23:50:27 +00:00
|
|
|
<script src="/static/js/api.js"></script>
|
2016-12-18 13:12:14 +00:00
|
|
|
|
|
|
|
<style>
|
2016-12-21 09:11:50 +00:00
|
|
|
input
|
|
|
|
{
|
|
|
|
width: 300px;
|
|
|
|
}
|
|
|
|
button
|
|
|
|
{
|
|
|
|
width: 80px;
|
|
|
|
}
|
|
|
|
|
2016-12-18 13:12:14 +00:00
|
|
|
#content_body
|
|
|
|
{
|
2018-10-22 01:46:27 +00:00
|
|
|
margin: auto;
|
2016-12-18 13:12:14 +00:00
|
|
|
}
|
2016-12-21 09:11:50 +00:00
|
|
|
|
2019-08-26 21:54:29 +00:00
|
|
|
form
|
2016-12-18 13:12:14 +00:00
|
|
|
{
|
2019-08-26 21:54:29 +00:00
|
|
|
display: grid;
|
|
|
|
grid-auto-rows: max-content;
|
|
|
|
grid-row-gap: 8px;
|
|
|
|
margin: 0;
|
2016-12-18 13:12:14 +00:00
|
|
|
}
|
2019-08-26 21:54:29 +00:00
|
|
|
form h2
|
2016-12-18 13:12:14 +00:00
|
|
|
{
|
2019-08-26 21:54:29 +00:00
|
|
|
margin: 0;
|
2016-12-18 13:12:14 +00:00
|
|
|
}
|
2019-08-26 21:54:29 +00:00
|
|
|
#login_form { grid-area: login_form; }
|
|
|
|
#register_form { grid-area: register_form; }
|
2018-02-24 08:34:46 +00:00
|
|
|
#message_area
|
|
|
|
{
|
2019-08-26 21:54:29 +00:00
|
|
|
grid-area: message_area;
|
2018-02-24 08:34:46 +00:00
|
|
|
}
|
2019-08-26 21:54:29 +00:00
|
|
|
|
2020-09-19 04:12:28 +00:00
|
|
|
@media screen and (min-width: 800px)
|
|
|
|
{
|
|
|
|
#content_body
|
|
|
|
{
|
|
|
|
grid-template:
|
|
|
|
"login_form register_form" auto
|
|
|
|
"message_area message_area" 150px
|
|
|
|
/ 1fr 1fr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 06:02:09 +00:00
|
|
|
@media screen and (max-width: 800px)
|
|
|
|
{
|
2019-08-26 21:54:29 +00:00
|
|
|
#content_body
|
2017-07-21 06:02:09 +00:00
|
|
|
{
|
2019-08-26 21:54:29 +00:00
|
|
|
grid-template:
|
|
|
|
"login_form" auto
|
|
|
|
"register_form" auto
|
2019-09-11 08:13:10 +00:00
|
|
|
"message_area" 150px
|
2019-08-26 21:54:29 +00:00
|
|
|
/ 1fr;
|
2017-07-21 06:02:09 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-18 13:12:14 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
{{header.make_header(session=session)}}
|
|
|
|
<div id="content_body">
|
2019-08-26 21:54:29 +00:00
|
|
|
<form id="login_form" class="panel" action="/login" method="post">
|
|
|
|
<h2>Log in</h2>
|
|
|
|
<input type="text" id="login_input_username" name="username" placeholder="username" autofocus>
|
|
|
|
<input type="password" id="login_input_password" name="password" placeholder="password">
|
2020-09-04 17:37:04 +00:00
|
|
|
<button type="submit" id="login_submit_button" class="green_button" onclick="return login_form(event);">Log in</button>
|
2019-08-26 21:54:29 +00:00
|
|
|
</form>
|
|
|
|
<form id="register_form" class="panel" action="/register" method="post">
|
|
|
|
<h2>Register</h2>
|
2021-10-25 05:17:50 +00:00
|
|
|
{% if registration_enabled %}
|
2019-08-26 21:54:29 +00:00
|
|
|
<input type="text" id="register_input_username" name="username" placeholder="username (at least {{min_username_length}})">
|
|
|
|
<input type="text" id="register_input_display_name" name="display_name" placeholder="display name (optional)">
|
|
|
|
<input type="password" id="register_input_password_1" name="password_1" placeholder="password (at least {{min_password_length}})">
|
|
|
|
<input type="password" id="register_input_password_2" name="password_2" placeholder="password again">
|
2020-09-04 17:37:04 +00:00
|
|
|
<button type="submit" id="register_input_button" class="green_button" onclick="return register_form(event);">Register</button>
|
2021-10-25 05:17:50 +00:00
|
|
|
{% else %}
|
|
|
|
<span>Registrations are disabled.</span>
|
|
|
|
{% endif %}
|
2019-08-26 21:54:29 +00:00
|
|
|
</form>
|
2020-11-05 01:20:59 +00:00
|
|
|
<div id="message_area" class="panel">
|
2016-12-18 13:12:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2020-09-15 01:33:53 +00:00
|
|
|
const message_area = document.getElementById("message_area");
|
2016-12-21 09:11:50 +00:00
|
|
|
|
2019-08-26 21:34:50 +00:00
|
|
|
function login_form(event)
|
2016-12-21 09:11:50 +00:00
|
|
|
{
|
2019-08-26 21:34:50 +00:00
|
|
|
event.preventDefault();
|
2020-09-15 01:33:53 +00:00
|
|
|
const username = document.getElementById("login_input_username").value;
|
|
|
|
const password = document.getElementById("login_input_password").value;
|
2016-12-21 09:11:50 +00:00
|
|
|
if (username == "" || password == "")
|
|
|
|
{
|
2018-07-29 08:25:53 +00:00
|
|
|
common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo.");
|
2016-12-21 09:11:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-12 22:37:04 +00:00
|
|
|
api.users.login(username, password, login_register_callback)
|
2018-07-29 08:25:53 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 21:34:50 +00:00
|
|
|
function register_form(event)
|
2016-12-21 09:11:50 +00:00
|
|
|
{
|
2019-08-26 21:34:50 +00:00
|
|
|
event.preventDefault();
|
2020-09-15 01:33:53 +00:00
|
|
|
const username = document.getElementById("register_input_username").value;
|
|
|
|
const display_name = document.getElementById("register_input_display_name").value;
|
|
|
|
const password_1 = document.getElementById("register_input_password_1").value;
|
|
|
|
const password_2 = document.getElementById("register_input_password_2").value;
|
2016-12-21 09:11:50 +00:00
|
|
|
if (username == "" || password_1 == "" || password_2 == "")
|
|
|
|
{
|
2018-07-29 08:25:53 +00:00
|
|
|
common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo.");
|
2016-12-21 09:11:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-12 22:37:04 +00:00
|
|
|
api.users.register(username, display_name, password_1, password_2, login_register_callback);
|
2016-12-21 09:11:50 +00:00
|
|
|
}
|
2018-07-29 08:25:53 +00:00
|
|
|
|
2020-01-12 22:37:04 +00:00
|
|
|
function login_register_callback(response)
|
2016-12-21 09:11:50 +00:00
|
|
|
{
|
2020-12-26 21:22:19 +00:00
|
|
|
if (! response.meta.json_ok)
|
2020-11-07 06:50:05 +00:00
|
|
|
{
|
|
|
|
alert(JSON.stringify(response));
|
|
|
|
return;
|
|
|
|
}
|
2020-06-29 00:54:16 +00:00
|
|
|
if ("error_type" in response.data)
|
2016-12-21 09:11:50 +00:00
|
|
|
{
|
2020-06-29 00:54:16 +00:00
|
|
|
common.create_message_bubble(message_area, "message_negative", response.data.error_message);
|
2018-07-29 08:25:53 +00:00
|
|
|
return;
|
2016-12-21 09:11:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.href = "/";
|
|
|
|
}
|
|
|
|
}
|
2016-12-18 13:12:14 +00:00
|
|
|
</script>
|
|
|
|
</html>
|