Skip to content

Commit

Permalink
Merge branch 'main' into Updating_Password_Requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
smog-root authored Oct 14, 2024
2 parents bd8aeff + 0361282 commit 6647615
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 87 deletions.
60 changes: 41 additions & 19 deletions login-system/token.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
require("dotenv").config()
// generating the token for user
const jwt = require("jsonwebtoken")
const crypto=require('crypto')
function generateAccessToken (user) {
return jwt.sign(user, process.env.ACCESS_TOKEN_SECRET, {expiresIn: "20m"})
const crypto=require('crypto');
const ACCESS_TOKEN = process.env.ACCESS_TOKEN_SECRET

// check for valid access token
if(!ACCESS_TOKEN){
throw new Error("Missing ACCESS_TOKEN_SECRET in environment variables.");
}
// function for generating access token
function generateAccessToken(user,expireTime = "20m") {
try{
const token = jwt.sign(user,ACCESS_TOKEN,{expiresIn : expireTime});
return token;
}catch(err){
console.log({
Message : "Error While Generating The Token",
Error : err.message
})
return null;
}
}

// function for decoding the token
function decodeAccessToken(authorizationHeader) {
if (!authorizationHeader) {
console.log('authorization header is missing')
return null;
}
function decodeAccessToken(AuthHeader){
if(!AuthHeader){
console.log("Authorization header is missing");
return null;
}

const token = authorizationHeader.split(' ')[1];

try {
const decoded = jwt.verify(token, process.env.ACCESS_TOKEN_SECRET);
// console.log('decoded info: ',decoded)
return decoded;
} catch (error) {
console.error('Error decoding access token:', error);
return null;
const token = AuthHeader.split(" ")[1];
if(!token){
console.log("Token is missing");
return null;
}
try{

const decodedToken = jwt.verify(token,ACCESS_TOKEN)
return decodedToken;

}catch(err){
console.log({
Message : "Error decoding access token:",
Error : err.message
})
return null
}
}

Expand All @@ -30,4 +52,4 @@ function registrationToken(email) {
return crypto.createHash('sha256').update(email).digest('hex');
}

module.exports={ generateAccessToken, decodeAccessToken ,registrationToken}
module.exports={ generateAccessToken, decodeAccessToken ,registrationToken}
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
Binary file added public/images/badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/boost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/career.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/connectpeers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/explorepapers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/follow.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/plagiarism.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 21 additions & 38 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,55 +209,38 @@ <h3>Explore Top Papers</h3>
<h3>Top Services</h3>
<div class="all-boxes">
<div class="box show hidden">
<h3>Plagiarism checker</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores mollitia dolor eveniet quos enim!
Labore recusandae nihil, blanditiis officia cumque ullam odit, quo autem quos facilis, aspernatur
minima
mollitia possimus.</p>
<h3>Plagiarism Checker</h3>
<img src="images/plagiarism.png" alt="Plagiarism Checker Icon" style="width:150; height: 150px; border-radius: 15px; border: 2px solid #ccc;">
<p>
Ensure your content is original with our advanced plagiarism detection tool, and receive detailed reports to uphold integrity in your writing.
</p>
</div>
<div class="box show hidden">
<h3>Explore Project</h3>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Illum animi nulla dolorum, non quibusdam
tenetur saepe cumque cum vero ipsa explicabo tempore voluptatum voluptatibus rerum ad quas
asperiores
exercitationem debitis.</p>
</div>
<div class="box show hidden">
<h3>Connect with peers</h3>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Illum animi nulla dolorum, non quibusdam
tenetur saepe cumque cum vero ipsa explicabo tempore voluptatum voluptatibus rerum ad quas
asperiores
exercitationem debitis.</p>
<h3>Explore Papers</h3>
<img src="images/explorepapers.png" alt="project" style="width:150; height: 150px; border-radius: 15px; border: 2px solid #ccc;">
<p>Experience seamless research collaboration as students, stakeholders, and faculty connect easily.
Turn submissions into impactful evaluations with a few clicks!
</p>
</div>

<div class="box show hidden">
<h3>Follow Groups</h3>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Illum animi nulla dolorum, non quibusdam
tenetur saepe cumque cum vero ipsa explicabo tempore voluptatum voluptatibus rerum ad quas
asperiores
exercitationem debitis.</p>
<img src="images/follow.jpeg" alt="follow group" style="width:200; height: 150px; border-radius: 15px; border: 2px solid #ccc;">
<p>Stay in the loop with your favorite research groups follow, engage, and collaborate on the topics that matter most.</p>
</div>
<div class="box show hidden">
<h3>Boost Level</h3>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Illum animi nulla dolorum, non quibusdam
tenetur saepe cumque cum vero ipsa explicabo tempore voluptatum voluptatibus rerum ad quas
asperiores
exercitationem debitis.</p>
</div>
<div class="box show hidden">
<h3>Redeem Badges</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dicta laborum, sequi culpa, harum delectus
nobis
distinctio quae ratione nesciunt tempore suscipit qui repellendus, sit itaque molestiae nostrum?
Esse,
vel in!</p>
<img src="images/boost.png" alt="boost" style="width:150; height: 150px; border-radius: 15px; border: 2px solid #ccc;">
<p>Amplify your academic reach boost your growth with a network that supports and inspires
with powerful partnerships, transforming ideas into impactful research outcomes.
</p>
</div>

<div class="box show hidden">
<h3>Career Opportunities</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dicta laborum, sequi culpa, harum delectus
nobis
distinctio quae ratione nesciunt tempore suscipit qui repellendus, sit itaque molestiae nostrum?
Esse,
vel in!</p>
<img src="images/career.png" alt="career" style="width:150; height: 150px; border-radius: 15px; border: 2px solid #ccc;">
<p>Turn your academic achievements into career opportunities, opening doors to roles that match your expertise and aspirations.
</p>
</div>
</div>
</section>
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
55 changes: 54 additions & 1 deletion public/stk_signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ <h2 style="text-align: center;">Sign Up</h2>
requirementsDiv.style.display = 'block'; // Show requirements
return false; // Prevent form submission
}
else {
icon.src = "images/moon.png";
}
requirementsDiv.style.display = 'none'; // Hide requirements if valid
return true; // Allow form submission
}
Expand Down Expand Up @@ -110,6 +113,17 @@ <h2 style="text-align: center;">Sign Up</h2>
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';
Expand All @@ -123,9 +137,48 @@ <h2 style="text-align: center;">Sign Up</h2>
setTimeout(() => {
result3.style.display = 'none';
}, 2000);
return; // Stop form submission
}

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 6647615

Please sign in to comment.