diff --git a/core/scripts/webpanel/templates/users.html b/core/scripts/webpanel/templates/users.html
index 579c08b..839c9f9 100644
--- a/core/scripts/webpanel/templates/users.html
+++ b/core/scripts/webpanel/templates/users.html
@@ -76,6 +76,7 @@
|
-
+
|
{{ loop.index }} |
@@ -96,35 +97,42 @@
{{ user['status'] }}
{% endif %}
|
- {{ user.username }} |
- {{ user.traffic_used }} |
- {{ user.expiry_date }} |
- {{ user.expiry_days }} |
+ {{ user['username'] }} |
+ {{ user['traffic_used'] }} |
+ {{ user['expiry_date'] }} |
+ {{ user['expiry_days'] }} |
- {% if user.enable %}
+ {% if user['enable'] %}
{% else %}
{% endif %}
|
+
+ {% if user['unlimited_ip'] %}
+
+ {% else %}
+
+ {% endif %}
+ |
+ data-username="{{ user['username'] }}">
|
|
@@ -173,6 +181,10 @@
+
+
+
+
@@ -206,9 +218,13 @@
-
+
+
+
+
+
@@ -259,7 +275,6 @@
}
$("#addSubmitButton").prop("disabled", true);
- // $("#editSubmitButton").prop("disabled", true);
$("#addUsername").on("input", function () {
const username = $(this).val();
@@ -387,11 +402,12 @@
}
$("#addSubmitButton").prop("disabled", true);
- const formData = $(this).serializeArray();
- const jsonData = {};
- formData.forEach(field => {
- jsonData[field.name] = field.value;
- });
+ const jsonData = {
+ username: $("#addUsername").val(),
+ traffic_limit: $("#addTrafficLimit").val(),
+ expiration_days: $("#addExpirationDays").val(),
+ unlimited: $("#addUnlimited").is(":checked")
+ };
$.ajax({
url: " {{ url_for('add_user_api') }} ",
@@ -435,6 +451,7 @@
const trafficUsageText = row.find("td:eq(4)").text().trim();
const expiryDaysText = row.find("td:eq(6)").text().trim();
const blocked = row.find("td:eq(7) i").hasClass("text-danger");
+ const unlimited_ip = row.find("td:eq(8) i").hasClass("text-primary");
const expiryDaysValue = (expiryDaysText.toLowerCase() === 'unlimited') ? 0 : parseInt(expiryDaysText, 10);
@@ -455,6 +472,7 @@
$("#editTrafficLimit").val(trafficLimitValue);
$("#editExpirationDays").val(expiryDaysValue);
$("#editBlocked").prop("checked", blocked);
+ $("#editUnlimitedIp").prop("checked", unlimited_ip);
const isValid = validateUsername(username, "editUsernameError");
$("#editUserForm button[type='submit']").prop("disabled", !isValid);
@@ -465,12 +483,19 @@
if (!validateUsername($("#editUsername").val(), "editUsernameError")) {
return;
}
+ $("#editSubmitButton").prop("disabled", true);
+
+ const jsonData = {
+ new_username: $("#editUsername").val(),
+ new_traffic_limit: $("#editTrafficLimit").val() || null,
+ new_expiration_days: $("#editExpirationDays").val() || null,
+ blocked: $("#editBlocked").is(":checked"),
+ unlimited_ip: $("#editUnlimitedIp").is(":checked")
+ };
- const formData = $(this).serializeArray();
- const jsonData = {};
- formData.forEach(field => {
- jsonData[field.name] = field.value;
- });
+ if (jsonData.new_username === $("#originalUsername").val()) {
+ delete jsonData.new_username;
+ }
const editUserUrl = "{{ url_for('edit_user_api', username='USERNAME_PLACEHOLDER') }}";
const url = editUserUrl.replace("USERNAME_PLACEHOLDER", encodeURIComponent($("#originalUsername").val()));
@@ -481,22 +506,8 @@
contentType: "application/json",
data: JSON.stringify(jsonData),
success: function (response) {
- if (typeof response === 'string' && response.includes("User updated successfully")) {
+ if (response && response.detail) {
$("#editUserModal").modal("hide");
- Swal.fire({
- title: "Success!",
- text: "User updated successfully!",
- icon: "success",
- confirmButtonText: "OK",
- }).then(() => {
- location.reload();
- });
- }
- else if (response && response.detail) {
- // Hide the modal
- $("#editUserModal").modal("hide");
-
- // Show a success message
Swal.fire({
title: "Success!",
text: response.detail,
@@ -509,29 +520,29 @@
$("#editUserModal").modal("hide");
Swal.fire({
title: "Error!",
- text: response.error || "An error occurred.",
+ text: (response && response.error) || "An unknown error occurred.",
icon: "error",
confirmButtonText: "OK",
});
+ $("#editSubmitButton").prop("disabled", false);
}
},
- error: function (error) {
- console.error(error);
+ error: function (jqXHR) {
+ let errorMessage = "An error occurred while updating user.";
+ if (jqXHR.responseJSON && jqXHR.responseJSON.detail) {
+ errorMessage = jqXHR.responseJSON.detail;
+ }
Swal.fire({
title: "Error!",
- text: "An error occurred while updating user",
+ text: errorMessage,
icon: "error",
confirmButtonText: "OK",
});
+ $("#editSubmitButton").prop("disabled", false);
}
});
});
- $("#editUserForm button[type='submit']").on("click", function (e) {
- e.preventDefault();
- $(this).closest("form").submit();
- });
-
// Reset User Button Click
$("#userTable").on("click", ".reset-user", function () {
const username = $(this).data("user");
@@ -653,15 +664,12 @@
method: "GET",
dataType: 'json',
success: function (response) {
- // console.log("API Response:", response);
-
const configs = [
{ type: "IPv4", link: response.ipv4 },
{ type: "IPv6", link: response.ipv6 },
{ type: "Normal-SUB", link: response.normal_sub }
];
-
configs.forEach(config => {
if (config.link) {
const displayType = config.type;
@@ -765,10 +773,10 @@
}
$('#addUserModal').on('show.bs.modal', function (event) {
- $('#addUsername').val('');
+ $('#addUserForm')[0].reset();
+ $('#addUsernameError').text('');
$('#addTrafficLimit').val('30');
$('#addExpirationDays').val('30');
- $('#addUsernameError').text('');
$('#addSubmitButton').prop('disabled', true);
});