<div class="modal-dialog modal-sm modal-dialog-centered">
<div class="modal-content shadow">
<div class="modal-header text-secondary py-2">
- <i class="fas fa-key my-auto"></i><h6 class="modal-title fw-bolder">Login to Rspamd</h6>
+ <i class="fas fa-key my-auto"></i>
+ <div id="authInvalidCharFeedback" class="invalid-tooltip">Invalid characters</div>
+ <div id="authUnauthorizedFeedback" class="invalid-tooltip">Wrong password</div>
+ <h6 class="modal-title fw-bolder">Login to Rspamd</h6>
</div>
<div class="modal-body" id="connectBody">
<form id="connectForm">
displayUI();
},
error: function () {
+ function clearFeedback() {
+ $("#connectPassword").off("input").removeClass("is-invalid");
+ $("#authInvalidCharFeedback,#authUnauthorizedFeedback").hide();
+ }
+
$("#connectDialog")
- .on("shown.bs.modal", function () {
+ .on("show.bs.modal", () => {
+ $("#connectDialog").off("show.bs.modal");
+ clearFeedback();
+ })
+ .on("shown.bs.modal", () => {
$("#connectDialog").off("shown.bs.modal");
$("#connectPassword").focus();
})
.modal("show");
- $("#connectForm").on("submit", function (e) {
+ $("#connectForm").off("submit").on("submit", function (e) {
e.preventDefault();
var password = $("#connectPassword").val();
+
+ function invalidFeedback(tooltip) {
+ $("#connectPassword")
+ .addClass("is-invalid")
+ .off("input").on("input", () => clearFeedback());
+ $(tooltip).show();
+ }
+
if (!(/^[\u0020-\u007e]*$/).test(password)) {
- alertMessage("alert-modal alert-error", "Invalid characters in the password");
+ invalidFeedback("#authInvalidCharFeedback");
$("#connectPassword").focus();
return;
}
displayUI();
}
},
- error: function (jqXHR) {
- ui.alertMessage("alert-modal alert-error", jqXHR.statusText);
+ error: function (jqXHR, textStatus) {
+ if (textStatus.statusText === "Unauthorized") {
+ invalidFeedback("#authUnauthorizedFeedback");
+ } else {
+ ui.alertMessage("alert-modal alert-error", textStatus.statusText);
+ }
$("#connectPassword").val("");
$("#connectPassword").focus();
},