2021-06-07 12:46:46 +00:00
|
|
|
import { Modal } from "./modules/modal.js";
|
2023-06-22 17:31:16 +00:00
|
|
|
import { Validator, ValidatorConf } from "./modules/validator.js";
|
2021-06-07 12:46:46 +00:00
|
|
|
import { _post, addLoader, removeLoader } from "./modules/common.js";
|
2022-01-01 02:58:26 +00:00
|
|
|
import { loadLangSelector } from "./modules/lang.js";
|
2021-03-30 21:41:28 +00:00
|
|
|
|
2021-06-07 12:46:46 +00:00
|
|
|
interface formWindow extends Window {
|
|
|
|
invalidPassword: string;
|
|
|
|
successModal: Modal;
|
|
|
|
telegramModal: Modal;
|
|
|
|
discordModal: Modal;
|
|
|
|
matrixModal: Modal;
|
|
|
|
confirmationModal: Modal
|
|
|
|
code: string;
|
|
|
|
messages: { [key: string]: string };
|
|
|
|
confirmation: boolean;
|
|
|
|
telegramRequired: boolean;
|
|
|
|
telegramPIN: string;
|
|
|
|
discordRequired: boolean;
|
|
|
|
discordPIN: string;
|
|
|
|
discordStartCommand: string;
|
|
|
|
discordInviteLink: boolean;
|
|
|
|
discordServerName: string;
|
|
|
|
matrixRequired: boolean;
|
|
|
|
matrixUserID: string;
|
|
|
|
userExpiryEnabled: boolean;
|
|
|
|
userExpiryMonths: number;
|
|
|
|
userExpiryDays: number;
|
|
|
|
userExpiryHours: number;
|
|
|
|
userExpiryMinutes: number;
|
|
|
|
userExpiryMessage: string;
|
|
|
|
}
|
2021-03-30 21:41:28 +00:00
|
|
|
|
2022-01-01 02:58:26 +00:00
|
|
|
loadLangSelector("pwr");
|
|
|
|
|
2021-06-07 12:46:46 +00:00
|
|
|
declare var window: formWindow;
|
2021-03-30 21:41:28 +00:00
|
|
|
|
2021-06-07 12:46:46 +00:00
|
|
|
const form = document.getElementById("form-create") as HTMLFormElement;
|
2023-06-22 17:31:16 +00:00
|
|
|
const submitInput = form.querySelector("input[type=submit]") as HTMLInputElement;
|
2021-06-07 12:46:46 +00:00
|
|
|
const submitSpan = form.querySelector("span.submit") as HTMLSpanElement;
|
|
|
|
const passwordField = document.getElementById("create-password") as HTMLInputElement;
|
|
|
|
const rePasswordField = document.getElementById("create-reenter-password") as HTMLInputElement;
|
2021-03-30 21:41:28 +00:00
|
|
|
|
2021-06-07 12:46:46 +00:00
|
|
|
window.successModal = new Modal(document.getElementById("modal-success"), true);
|
2021-03-30 21:41:28 +00:00
|
|
|
|
2023-06-22 17:31:16 +00:00
|
|
|
let validatorConf: ValidatorConf = {
|
|
|
|
passwordField: passwordField,
|
|
|
|
rePasswordField: rePasswordField,
|
|
|
|
submitInput: submitInput,
|
|
|
|
submitButton: submitSpan
|
|
|
|
};
|
|
|
|
|
|
|
|
var validator = new Validator(validatorConf);
|
|
|
|
var requirements = validator.requirements;
|
2021-06-07 12:46:46 +00:00
|
|
|
|
|
|
|
interface sendDTO {
|
|
|
|
pin: string;
|
|
|
|
password: string;
|
2021-03-30 21:41:28 +00:00
|
|
|
}
|
2021-06-07 12:46:46 +00:00
|
|
|
|
|
|
|
form.onsubmit = (event: Event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
addLoader(submitSpan);
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
let send: sendDTO = {
|
|
|
|
pin: params.get("pin"),
|
|
|
|
password: passwordField.value
|
|
|
|
};
|
|
|
|
_post("/reset", send, (req: XMLHttpRequest) => {
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
removeLoader(submitSpan);
|
|
|
|
if (req.status == 400) {
|
|
|
|
for (let type in req.response) {
|
|
|
|
if (requirements[type]) { requirements[type].valid = req.response[type] as boolean; }
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (req.status != 200) {
|
|
|
|
const old = submitSpan.textContent;
|
|
|
|
submitSpan.textContent = window.messages["errorUnknown"];
|
|
|
|
submitSpan.classList.add("~critical");
|
|
|
|
submitSpan.classList.remove("~urge");
|
|
|
|
setTimeout(() => {
|
|
|
|
submitSpan.classList.add("~urge");
|
|
|
|
submitSpan.classList.remove("~critical");
|
|
|
|
submitSpan.textContent = old;
|
|
|
|
}, 2000);
|
|
|
|
} else {
|
|
|
|
window.successModal.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
};
|
2023-06-22 17:31:16 +00:00
|
|
|
|
|
|
|
validator.validate();
|