chpasswd/index.html

136 lines
5.1 KiB
HTML
Raw Normal View History

2025-01-08 12:11:26 +00:00
<!DOCTYPE html>
<!--
Copyright (c) 2025 Nikita Osokin.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided
with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-->
<html>
<head>
<meta charset="utf-8" />
<style>
#container {
display: grid;
grid-template-rows: 2fr 1fr 1fr 1fr 1fr 1fr 2fr;
place-items: center;
}
</style>
</head>
<body>
<div id="container">
<h2>Смена пароля на почтовый ящик @sch9.ru</h2>
<input id="username" type="email" placeholder="Адрес эл. почты" />
<input id="old_password" type="password" placeholder="Старый пароль" />
<input id="password" type="password" placeholder="Новый пароль" />
<input id="password_repeat" type="password" placeholder="Повторите новый пароль" />
<input id="send" type="button" onclick="send_input()" value="Поменять пароль" />
</div>
<script>
function response_body_to_status(response_body) {
if(response_body == "255") {
return "Внутренняя ошибка сервера.";
}
if(response_body == "254") {
return "Адрес эл. почты содержит недопустимые символы.";
}
if(response_body == "253") {
return "Адрес эл. почты не найден.";
}
if(response_body == "252") {
return "Старый пароль неправилен.";
}
if(response_body == "251") {
return "Новые пароли не совпадают.";
}
if(response_body == "250") {
return "Пустые, неправильно заполненные или слишком длинные поля (макс. 2048 байтов на поле).";
2025-01-08 12:11:26 +00:00
}
return response_body;
}
async function display_status(response) {
let send_button = document.getElementById("send");
let paragraph = document.createElement("p");
paragraph.id = "status_display";
let status_text;
if(response.status == 200) {
status_text = document.createTextNode("Пароль изменён.");
} else {
let response_body = await response.text();
status_text = document.createTextNode(response_body_to_status(response_body));
}
paragraph.append(status_text);
send_button.after(paragraph);
}
function display_net_error(e) {
let send_button = document.getElementById("send");
let paragraph = document.createElement("p");
paragraph.id = "status_display";
let status_text = document.createTextNode("Сетевая ошибка. Возможно, вам стоит проверить своё интернет-соединение или подождать, а затем попробовать поменять пароль снова.");
paragraph.append(status_text);
send_button.after(paragraph);
}
function append_to_input(input, offset, text) {
input.set(text, offset);
input[offset + text.length] = 10; // '\n'
return offset + text.length + 1;
}
function send_input() {
let old_paragraph = document.getElementById("status_display");
if(old_paragraph != null) {
old_paragraph.remove();
}
let text_encoder = new TextEncoder();
let username = text_encoder.encode(document.getElementById("username").value);
let old_password = text_encoder.encode(document.getElementById("old_password").value);
let password = text_encoder.encode(document.getElementById("password").value);
let password_repeat = text_encoder.encode(document.getElementById("password_repeat").value);
let input = new Uint8Array(username.length + old_password.length + password.length + password_repeat.length + 4);
let offset = append_to_input(input, 0, username);
offset = append_to_input(input, offset, old_password);
offset = append_to_input(input, offset, password);
append_to_input(input, offset, password_repeat);
fetch(
"",
{
method: "POST",
body: input
}
).then(
display_status,
display_net_error
);
}
</script>
</body>
</html>