Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trusted_Email #104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions public/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,27 @@ <h4 style="text-align: center; margin: 10px 0px 6px 0px;font-size: 22px;">(for R
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);
}

async function login() {
let email = document.getElementById("email").value;
let 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')
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;
}

try {
const response = await fetch('http://localhost:3000/login', {
Expand All @@ -71,44 +85,41 @@ <h4 style="text-align: center; margin: 10px 0px 6px 0px;font-size: 22px;">(for R
body: JSON.stringify({ email, password }),
});


if (response.status === 200) {
const result1 = document.getElementById('box1');
console.log('Login successful');
const result = await response.json();
const token = result.accessToken;
console.log(token)
localStorage.setItem('accessToken', token);
result1.style.display = 'block';
setTimeout(() => {
window.location.href = 'form_filling.html';
}, 2000);
}
else if(response.status==401){
else if (response.status == 401) {
result4.style.display = 'block';
document.getElementById('email').value = ''
document.getElementById('password').value = ''
document.getElementById('email').value = '';
document.getElementById('password').value = '';
setTimeout(() => {
result4.style.display = 'none';
}, 2000)
}, 2000);
}
else if (response.status === 404) {
result2.style.display = 'block';
console.log('User not found');
document.getElementById('email').value = ''
document.getElementById('password').value = ''
document.getElementById('email').value = '';
document.getElementById('password').value = '';
setTimeout(() => {
result2.style.display = 'none';
}, 2000)
}, 2000);
} else {
const errorMessage = await response.text();
console.log(`Login failed: ${errorMessage}`);
result3.style.display = 'block';
email = ''
password = ''
email = '';
password = '';
setTimeout(() => {
result3.style.display = 'none';
}, 2000)
}, 2000);
}
} catch (error) {
console.error('Error during login:', error);
Expand Down
69 changes: 39 additions & 30 deletions public/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p>Please Try Again!! Account Already Exists</p>
</div>
<div id="box3">
<p>Error Occuered! Please Try Again</p>
<p>Error Occurred! Please Try Again</p>
</div>
<div class="form" id="login">
<form id="registrationForm">
Expand All @@ -41,16 +41,16 @@ <h4 style="text-align: center; margin: 6px 0px 10px 0px;font-size: 22px;">(for R
</div>

<script>
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";
}
else{
icon.src="images/moon.png";
}
}
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";
} else {
icon.src = "images/moon.png";
}
}

document.getElementById('registrationForm').addEventListener('submit', async function (event) {
event.preventDefault();

Expand All @@ -62,6 +62,20 @@ <h4 style="text-align: center; margin: 6px 0px 10px 0px;font-size: 22px;">(for R
const result3 = document.getElementById('box3');
const login = document.getElementById('login');

// 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);
return; // Stop form submission
}

try {
const response = await fetch('http://localhost:3000/create_user', {
method: 'POST',
Expand All @@ -78,30 +92,25 @@ <h4 style="text-align: center; margin: 6px 0px 10px 0px;font-size: 22px;">(for R
setTimeout(() => {
window.location.href = 'login.html';
}, 2000);
}
else if (response.status === 409) {
document.getElementById('email').value = ''
document.getElementById('password').value = ''
document.getElementById('name').value = ''
} else if (response.status === 409) {
document.getElementById('email').value = '';
document.getElementById('password').value = '';
document.getElementById('name').value = '';
result2.style.display = 'block';
setTimeout(() => {
result2.style.display = 'none';
}, 2000)
// alert('User already exists!');
}
else if(response.status==400){
document.getElementById('password').value = ''
const message=await response.json()
console.log('error',message.error)
result2.innerHTML=message.error;
}, 2000);
} else if (response.status == 400) {
document.getElementById('password').value = '';
const message = await response.json();
console.log('error', message.error);
result2.innerHTML = message.error;
result2.style.display = 'block';
}
else {
result3.style.display = 'block'
} else {
result3.style.display = 'block';
setTimeout(() => {
result3.style.display = 'none'
}, 2000)
// alert('Failed to register user.');
result3.style.display = 'none';
}, 2000);
}
} catch (error) {
console.error('Error:', error);
Expand Down