From 1fa0658afe5147e2a2665060f0cb76ee3a14e6e3 Mon Sep 17 00:00:00 2001 From: Mitul Sonagara Date: Sun, 13 Oct 2024 21:57:30 +0530 Subject: [PATCH] fix: trusted email service --- public/fac_login.html | 15 +++++++ public/stk_login.html | 14 +++++++ public/stk_signup.html | 95 +++++++++++++++++++++++++----------------- views/fac_signup.ejs | 77 +++++++++++++++++++++------------- 4 files changed, 134 insertions(+), 67 deletions(-) diff --git a/public/fac_login.html b/public/fac_login.html index 3b7d28b..ef0be76 100644 --- a/public/fac_login.html +++ b/public/fac_login.html @@ -54,6 +54,14 @@

(for F icon.src="images/moon.png"; } } + + function isValidEmail(email) { + // List of allowed domains + const allowedDomains = ["gmail.com", "outlook.com", "yahoo.com", "protonmail.com", "icloud.com", "tutanota.com"]; + const domain = email.split('@')[1]; + return allowedDomains.includes(domain); + } + const register = async () => { const email = document.getElementById('email').value; const password = document.getElementById('password').value; @@ -61,6 +69,13 @@

(for F const result2 = document.getElementById('box2') const result3 = document.getElementById('box3') const result4 = document.getElementById('box4') + + // Validate email domain + if (!isValidEmail(email)) { + alert('Please use a valid email from Gmail, Outlook, or other reputable providers.'); + return; + } + const response = await fetch('http://localhost:3000/fac_login', { method: "POST", headers: { diff --git a/public/stk_login.html b/public/stk_login.html index bbe0842..6d45799 100644 --- a/public/stk_login.html +++ b/public/stk_login.html @@ -56,6 +56,14 @@

(for S icon.src="images/moon.png"; } } + + function isValidEmail(email) { + // List of allowed domains + const allowedDomains = ["gmail.com", "outlook.com", "yahoo.com", "protonmail.com", "icloud.com", "tutanota.com"]; + const domain = email.split('@')[1]; + return allowedDomains.includes(domain); + } + const register = async () => { const email = document.getElementById('email').value; const password = document.getElementById('password').value; @@ -70,6 +78,12 @@

(for S const result2 = document.getElementById('box2'); const result3 = document.getElementById('box3'); const result4 = document.getElementById('box4'); + + // Validate email domain + if (!isValidEmail(email)) { + alert('Please use a valid email from Gmail, Outlook, or other reputable providers.'); + return; + } try { const response = await fetch('http://localhost:3000/stk_holder_signin', { diff --git a/public/stk_signup.html b/public/stk_signup.html index c934fdf..2116b69 100644 --- a/public/stk_signup.html +++ b/public/stk_signup.html @@ -40,58 +40,77 @@

Sign Up

- + \ No newline at end of file diff --git a/views/fac_signup.ejs b/views/fac_signup.ejs index 9849793..b843f56 100644 --- a/views/fac_signup.ejs +++ b/views/fac_signup.ejs @@ -46,45 +46,64 @@ const register = async () => { const emailText = document.getElementById('email').textContent; - const email=emailText.trim() + const email = emailText.trim() const name = document.getElementById('name').value; const password = document.getElementById('password').value; console.log(email, name, password) const result1 = document.getElementById('box1') const result2 = document.getElementById('box2') const result3 = document.getElementById('box3') - const response = await fetch('http://localhost:3000/fac_signup', { - method: "POST", - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ name, email, password }), - }); - if (response.status == 201) { - result1.style.opacity = '1'; - result1.style.display = 'block'; - setTimeout(() => { - result1.style.display = 'none'; - window.location.href = 'fac_login.html'; - }, 2000); - } - else if (response.status == 409) { - document.getElementById('email').value = '' - document.getElementById('password').value = '' - document.getElementById('colname').value = '' + + // Allowed email domains + const allowedDomains = ["gmail.com", "outlook.com", "yahoo.com", "protonmail.com", "icloud.com", "tutanota.com"]; + const emailDomain = email.split("@").pop(); + + // Check if the email domain is allowed + if (!allowedDomains.includes(emailDomain)) { + result2.innerHTML = "Invalid email domain. Please use Gmail, Outlook, Yahoo, Protonmail, Icloud, or Tutanota. "; result2.style.display = 'block'; setTimeout(() => { result2.style.display = 'none'; - }, 2000) + }, 2000); + return; // Stop form submission } - else { - result3.style.display = 'block' - document.getElementById('email').value = '' - document.getElementById('password').value = '' - document.getElementById('colname').value = '' - setTimeout(() => { - result3.style.display = 'none' - }, 2000) + + try { + const response = await fetch('http://localhost:3000/fac_signup', { + method: "POST", + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ name, email, password }), + }); + if (response.status == 201) { + result1.style.opacity = '1'; + result1.style.display = 'block'; + setTimeout(() => { + result1.style.display = 'none'; + window.location.href = 'fac_login.html'; + }, 2000); + } + else if (response.status == 409) { + document.getElementById('email').value = '' + document.getElementById('password').value = '' + document.getElementById('colname').value = '' + result2.style.display = 'block'; + setTimeout(() => { + result2.style.display = 'none'; + }, 2000) + } + else { + result3.style.display = 'block' + document.getElementById('email').value = '' + document.getElementById('password').value = '' + document.getElementById('colname').value = '' + setTimeout(() => { + result3.style.display = 'none' + }, 2000) + } + } catch (error) { + console.error('Error:', error); } }