Skip to content

Commit

Permalink
Merge pull request #110 from MitulSonagara/trusted-email-all
Browse files Browse the repository at this point in the history
fix: trusted email service
  • Loading branch information
Harshdev098 authored Oct 14, 2024
2 parents 2cae88f + 1fa0658 commit 8abfebf
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 67 deletions.
15 changes: 15 additions & 0 deletions public/fac_login.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,28 @@ <h4 style="text-align: center; margin: 0px 0px 10px 0px;font-size: 22px;">(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;
const result1 = document.getElementById('box1')
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: {
Expand Down
14 changes: 14 additions & 0 deletions public/stk_login.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ <h4 style="text-align: center; margin: 0px 0px 10px 0px;font-size: 22px;">(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;
Expand All @@ -70,6 +78,12 @@ <h4 style="text-align: center; margin: 0px 0px 10px 0px;font-size: 22px;">(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', {
Expand Down
95 changes: 57 additions & 38 deletions public/stk_signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,58 +40,77 @@ <h2 style="text-align: center;">Sign Up</h2>
</div>
</div>
<script>
var icon =document.getElementById("icon");
icon.onclick = function(){
var icon = document.getElementById("icon");
icon.onclick = function () {
document.body.classList.toggle("dark-theme");
if(document.body.classList.contains("dark-theme")){
icon.src="images/sun.png";
if (document.body.classList.contains("dark-theme")) {
icon.src = "images/sun.png";
}
else{
icon.src="images/moon.png";
else {
icon.src = "images/moon.png";
}
}
const register = async () => {
const email = document.getElementById('email').value;
const colname = document.getElementById('colname').value;
const password = document.getElementById('password').value;
const result1=document.getElementById('box1')
const result2=document.getElementById('box2')
const result3=document.getElementById('box3')
const response = await fetch('http://localhost:3000/stk_holder_signup', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ colname, email, password }),
});
if (response.status == 201) {
result1.style.opacity = '1';
result1.style.display = 'block';
setTimeout(() => {
result1.style.display = 'none';
window.location.href = 'stk_login.html';
}, 2000);
}
else if (response.status == 409) {
document.getElementById('email').value = ''
document.getElementById('password').value = ''
document.getElementById('colname').value = ''
const result1 = document.getElementById('box1')
const result2 = document.getElementById('box2')
const result3 = document.getElementById('box3')

// 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/stk_holder_signup', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ colname, email, password }),
});
if (response.status == 201) {
result1.style.opacity = '1';
result1.style.display = 'block';
setTimeout(() => {
result1.style.display = 'none';
window.location.href = 'stk_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);
}
}
</script>
</body>

</html>
</html>
77 changes: 48 additions & 29 deletions views/fac_signup.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
</script>
Expand Down

0 comments on commit 8abfebf

Please sign in to comment.