chore: javascript formatting
This commit is contained in:
parent
574d2661a1
commit
4d20b49002
|
|
@ -8,7 +8,6 @@
|
|||
document
|
||||
.getElementById("usersBtn")
|
||||
.addEventListener("click", function () {
|
||||
// Redirect to the users page.
|
||||
window.location.href = "/web/admin/users";
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
|
||||
<div id="content">
|
||||
<h1>User Management</h1>
|
||||
<p>Welcome, {{ email }}</p>
|
||||
<h1>User Management</h1>
|
||||
<p>Welcome, {{ email }}</p>
|
||||
</div>
|
||||
|
||||
<div id="menu">
|
||||
<button id="adminBtn">Admin</button>
|
||||
<button id="logoutBtn">Logout</button>
|
||||
<button id="adminBtn">Admin</button>
|
||||
<button id="logoutBtn">Logout</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
|
@ -18,27 +17,27 @@
|
|||
.addEventListener("click", function () {
|
||||
// Remove the cookie by setting its value to an empty string and its expiry date to the past.
|
||||
fetch("/web-api/logout", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
})
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok' + response.statusText);
|
||||
throw new Error(
|
||||
`Network response was not ok: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
window.location.href = "/web/login";
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
`There was a problem with the fetch operation: ${error}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
document
|
||||
.getElementById("adminBtn")
|
||||
.addEventListener("click", function () {
|
||||
// Redirect to the admin page.
|
||||
window.location.href = "/web/admin";
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -39,20 +39,21 @@
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
credentials: 'same-origin',
|
||||
credentials: "same-origin",
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
// If HTTP status code is not OK, throw an error with the status text
|
||||
throw Error(response.statusText);
|
||||
}
|
||||
window.location.href = "/web/home";
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
document.getElementById("response").innerText =
|
||||
"Login failed: " + error.message;
|
||||
});
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
// If HTTP status code is not OK, throw an error with the status text
|
||||
throw Error(response.statusText);
|
||||
}
|
||||
window.location.href = "/web/home";
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Error:, ${error}`);
|
||||
document.getElementById(
|
||||
"response",
|
||||
).innerText = `Login failed: ${error.message}`;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@
|
|||
<button id="setPasswordBtn">Set Password</button>
|
||||
</h2>
|
||||
|
||||
<div id="passwordModal" style="display: none;">
|
||||
<div id="passwordModal" style="display: none">
|
||||
<label for="newPassword">New Password:</label>
|
||||
<input type="password" id="newPassword" name="newPassword">
|
||||
<input type="password" id="newPassword" name="newPassword" />
|
||||
<button id="submitPasswordBtn">Submit</button>
|
||||
<button id="closePasswordModalBtn">Close</button>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<br />
|
||||
|
||||
<p>Phone: {{ user.phone|escape }}</p>
|
||||
<p>Email Confirmed At: {{ user.email_confirmed_at|default("-") }}</p>
|
||||
|
|
@ -27,44 +27,50 @@
|
|||
<a href="/web/admin/users">Back to User List</a>
|
||||
|
||||
<script>
|
||||
document.getElementById('setPasswordBtn').addEventListener('click', function() {
|
||||
document.getElementById('passwordModal').style.display = 'block';
|
||||
});
|
||||
document
|
||||
.getElementById("setPasswordBtn")
|
||||
.addEventListener("click", function () {
|
||||
document.getElementById("passwordModal").style.display = "block";
|
||||
});
|
||||
|
||||
document.getElementById('closePasswordModalBtn').addEventListener('click', function() {
|
||||
document.getElementById('passwordModal').style.display = 'none';
|
||||
});
|
||||
document
|
||||
.getElementById("closePasswordModalBtn")
|
||||
.addEventListener("click", function () {
|
||||
document.getElementById("passwordModal").style.display = "none";
|
||||
});
|
||||
|
||||
document.getElementById('submitPasswordBtn').addEventListener('click', function() {
|
||||
const newPassword = document.getElementById('newPassword').value;
|
||||
let confirmed = confirm("Set new password?");
|
||||
if(confirmed && newPassword) {
|
||||
fetch('/web-api/set_user_password', {
|
||||
method: 'POST',
|
||||
document
|
||||
.getElementById("submitPasswordBtn")
|
||||
.addEventListener("click", function () {
|
||||
const newPassword = document.getElementById("newPassword").value;
|
||||
let confirmed = confirm("Set new password?");
|
||||
if (confirmed && newPassword) {
|
||||
fetch("/web-api/set_user_password", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
userId: "{{ user.id }}",
|
||||
newPassword: newPassword,
|
||||
userId: "{{ user.id }}",
|
||||
newPassword: newPassword,
|
||||
}),
|
||||
})
|
||||
.then((response) => {
|
||||
if(!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
alert('Password set successfully!');
|
||||
document.getElementById('passwordModal').style.display = 'none';
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error setting password:', error);
|
||||
alert('Failed to set password. Please try again later.');
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
alert("Password set successfully!");
|
||||
document.getElementById("passwordModal").style.display = "none";
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error setting password:", error);
|
||||
alert("Failed to set password. Please try again later.");
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -25,31 +25,35 @@
|
|||
</table>
|
||||
|
||||
<script>
|
||||
document.getElementById('createUserBtn').addEventListener('click', function() {
|
||||
// Get the email from the user
|
||||
const email = prompt('Please enter the new user email:');
|
||||
if (email) {
|
||||
fetch(`/web-api/user/${email}`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok' + response.statusText);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
if (data.code === 0) {
|
||||
window.location.href = "/web/admin/users/" + data.data.id;
|
||||
} else {
|
||||
throw new Error('Error creating user: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
});
|
||||
}
|
||||
});
|
||||
document
|
||||
.getElementById("createUserBtn")
|
||||
.addEventListener("click", function () {
|
||||
// Get the email from the user
|
||||
const email = prompt("Please enter the new user email:");
|
||||
if (email) {
|
||||
fetch(`/web-api/user/${email}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Network response was not ok: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
if (data.code === 0) {
|
||||
window.location.href = `/web/admin/users/${data.data.id}`;
|
||||
} else {
|
||||
throw new Error(`Error creating user: ${data.message}`);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Error: ${error}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue