diff --git a/Files/background.js b/Files/background.js
new file mode 100644
index 0000000..3783557
--- /dev/null
+++ b/Files/background.js
@@ -0,0 +1,17 @@
+async function login(username, password) {
+ 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"
+ }
+ });
+
+ if (response.ok) {
+ return true; // Successfully logged in
+ } else {
+ return false; // Login failed
+ }
+}
diff --git a/Files/popup.html b/Files/popup.html
index 5b5e3a0..92ffb68 100644
--- a/Files/popup.html
+++ b/Files/popup.html
@@ -1,32 +1,20 @@
-
-
-
-
-
- Mailcow Temp Mail
-
-
-
-
-
-
-
-
+
diff --git a/Files/popup.js b/Files/popup.js
index ed94cff..fb139bb 100644
--- a/Files/popup.js
+++ b/Files/popup.js
@@ -1,107 +1,12 @@
-const API_BASE = "https://mail.pandem.fr/api/v1";
-const LOGIN_ENDPOINT = "/login";
-const GET_ALIAS_ENDPOINT = "/get/alias";
-const ADD_ALIAS_ENDPOINT = "/add/alias";
-
-// Check if user is logged in
-document.addEventListener("DOMContentLoaded", async () => {
- const storedSession = await browser.storage.local.get("session");
- if (storedSession.session) {
- showEmailForm();
- }
-});
-
-document.getElementById("login").addEventListener("click", async () => {
- const username = document.getElementById("username").value;
+document.getElementById("login-btn").addEventListener("click", async () => {
+ const username = document.getElementById("email").value;
const password = document.getElementById("password").value;
- try {
- const response = await fetch(API_BASE + LOGIN_ENDPOINT, {
- method: "POST",
- credentials: "include",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ username, password })
- });
+ const success = await login(username, password);
- if (!response.ok) throw new Error("Login failed");
-
- await browser.storage.local.set({ session: true });
- showEmailForm();
- } catch (error) {
- console.error(error);
- alert("Login error");
+ if (success) {
+ document.getElementById("status").innerText = "Login Successful!";
+ } else {
+ document.getElementById("status").innerText = "Login Failed!";
}
});
-
-document.getElementById("logout").addEventListener("click", async () => {
- await browser.storage.local.remove("session");
- showLoginForm();
-});
-
-document.getElementById("fetch").addEventListener("click", async () => {
- try {
- const response = await fetch(API_BASE + GET_ALIAS_ENDPOINT, {
- credentials: "include"
- });
-
- if (!response.ok) throw new Error("Failed to fetch emails");
-
- const aliases = await response.json();
-
- if (aliases.length > 0) {
- const latestEmail = aliases[0].address;
- document.getElementById("email").value = latestEmail;
- } else {
- document.getElementById("email").value = "No temp email found";
- }
- } catch (error) {
- console.error(error);
- alert("Error fetching email");
- }
-});
-
-document.getElementById("generate").addEventListener("click", async () => {
- const emailPrefix = "temp" + Date.now();
- const domain = "pandem.fr";
- const newEmail = `${emailPrefix}@${domain}`;
-
- const requestData = {
- address: newEmail,
- goto: "your_main@pandem.fr",
- active: true
- };
-
- try {
- const response = await fetch(API_BASE + ADD_ALIAS_ENDPOINT, {
- method: "POST",
- credentials: "include",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(requestData)
- });
-
- if (!response.ok) throw new Error("Failed to generate email");
-
- document.getElementById("email").value = newEmail;
- alert("New email created: " + newEmail);
- } catch (error) {
- console.error(error);
- alert("Error creating email");
- }
-});
-
-document.getElementById("copy").addEventListener("click", () => {
- const emailField = document.getElementById("email");
- emailField.select();
- document.execCommand("copy");
- alert("Copied: " + emailField.value);
-});
-
-function showEmailForm() {
- document.getElementById("login-form").style.display = "none";
- document.getElementById("email-form").style.display = "block";
-}
-
-function showLoginForm() {
- document.getElementById("login-form").style.display = "block";
- document.getElementById("email-form").style.display = "none";
-}