Compare commits

...

2 commits

Author SHA1 Message Date
f025794a27 V1.7 2025-02-20 00:22:01 +01:00
d91df9dad3 V1.6 2025-02-20 00:19:45 +01:00
2 changed files with 55 additions and 20 deletions

View file

@ -1,17 +1,31 @@
async function login(username, password) {
console.log("Login function called!"); // Debugging
const authHeader = "Basic " + btoa(username + ":" + password);
const response = await fetch("https://mail.pandem.fr/SOGo/so/session", {
method: "POST",
headers: {
"Authorization": authHeader,
"Content-Type": "application/json"
}
});
try {
console.log("Sending request to SOGo API...");
const response = await fetch("https://mail.pandem.fr/SOGo/so/session", {
method: "POST",
headers: {
"Authorization": authHeader,
"Content-Type": "application/json"
}
});
if (response.ok) {
return true; // Successfully logged in
} else {
return false; // Login failed
console.log("Response received:", response);
if (response.ok) {
console.log("Login successful");
return true;
} else {
console.log("Login failed with status:", response.status, response.statusText);
const errorText = await response.text();
console.log("Response body:", errorText);
return false;
}
} catch (error) {
console.error("Fetch error:", error);
return false;
}
}

View file

@ -1,12 +1,33 @@
document.getElementById("login-btn").addEventListener("click", async () => {
const username = document.getElementById("email").value;
const password = document.getElementById("password").value;
document.addEventListener("DOMContentLoaded", function () {
console.log("Popup loaded!"); // Debugging
const success = await login(username, password);
document.getElementById("login-btn").addEventListener("click", async () => {
console.log("Login button clicked!"); // Debugging
if (success) {
document.getElementById("status").innerText = "Login Successful!";
} else {
document.getElementById("status").innerText = "Login Failed!";
}
const username = document.getElementById("email").value;
const password = document.getElementById("password").value;
if (!username || !password) {
console.log("Missing username or password");
document.getElementById("status").innerText = "Please enter both email and password.";
return;
}
console.log("Attempting login..."); // Debugging
try {
const success = await login(username, password);
if (success) {
document.getElementById("status").innerText = "Login Successful!";
console.log("Login successful!");
} else {
document.getElementById("status").innerText = "Login Failed!";
console.log("Login failed!");
}
} catch (error) {
console.error("Login error:", error);
document.getElementById("status").innerText = "An error occurred.";
}
});
});