diff --git a/pages/public/users.html b/pages/public/users.html
index e35bf7c..8f32ea6 100644
--- a/pages/public/users.html
+++ b/pages/public/users.html
@@ -1,4 +1,5 @@
+
Invitation
diff --git a/static/js/users.js b/static/js/users.js
index 90286ec..37116fd 100644
--- a/static/js/users.js
+++ b/static/js/users.js
@@ -1,4 +1,30 @@
+function flushResponse() {
+ document.getElementById("alert-response" ).style.display = 'none';
+ document.getElementById("alert-response" ).classList.remove('alert-success' );
+ document.getElementById("alert-response" ).classList.remove('alert-danger' );
+ document.getElementById("alert-response" ).classList.remove('alert-primary' );
+}
+
+function loadingResponse() {
+ flushResponse();
+ document.getElementById("alert-status" ).innerHTML = "Loading...";
+ document.getElementById("alert-desc" ).innerHTML = "Please wait...";
+ document.getElementById("alert-response").classList.add('alert-primary');
+ document.getElementById("alert-response").style.display = 'block';
+}
+
+function responseAlert(response) {
+ flushResponse();
+ const obj = JSON.parse(response);
+ if (obj.status == "success" ) document.getElementById("alert-response").classList.add('alert-success' );
+ if (obj.status == "failed" ) document.getElementById("alert-response").classList.add('alert-danger' );
+ document.getElementById("alert-status" ).innerHTML = obj.status;
+ document.getElementById("alert-desc" ).innerHTML = obj.desc;
+ document.getElementById("alert-response").style.display = 'block';
+}
+
var token = document.getElementById("form-token" ).value;
+var allow = document.getElementById("form-allow" ).value;
const listerUser = document.getElementById("lister-user" );
const listerRoles = document.getElementById("lister-roles" );
@@ -43,28 +69,39 @@ sendHttpRequest("/api/auth/roles/list", "POST", null,
ls.data.forEach(row => {
const itemElement = document.createElement("div");
- itemElement.innerHTML = ``;
- listerRoles.appendChild(itemElement);
+ if (allow.includes(row.id)) {
+ itemElement.innerHTML = ``;
+ listerRoles.appendChild(itemElement);
+ } else {}
});
}
}, "application/json", `Bearer ${token}`
);
function invite() {
- const checkedRoles = Array
+ const roles = Array
.from(document.querySelectorAll('input[name="roles"]:checked'))
- .map(cb => Number(cb.value)); // Convert into number
- const email = document.getElementById('form-email').value;
- const username = document.getElementById('form-username').value;
- const password = document.getElementById('form-password').value;
-
- console.log({
- email,
- username,
- password,
- roles: checkedRoles // Example: [2, 3]
- });
-
- // Next command here
+ .map(row => Number(row.value)); // Convert into number. Output example: [2, 3]
+ const email = document.getElementById('form-email').value;
+ const username = document.getElementById('form-username').value;
+ const password = document.getElementById('form-password').value;
+ var url = "/api/auth/invite";
+ var payload = {
+ "roles" : roles,
+ "email" : email,
+ "username" : username,
+ "password" : password
+ };
+ // console.log(payload);
+ sendHttpRequest(url, "POST", payload, function (error, response) {
+ if (error) {
+ // console.error("Error:", error);
+ responseAlert({"status" : "failed", "desc" : error});
+ }
+ else {
+ // console.log("JSON Response:", response);
+ responseAlert(response);
+ }
+ }, "application/json", `Bearer ${token}`);
}