diff --git a/login-system/token.js b/login-system/token.js index 0818c76..de5466a 100644 --- a/login-system/token.js +++ b/login-system/token.js @@ -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 } } @@ -30,4 +52,4 @@ function registrationToken(email) { return crypto.createHash('sha256').update(email).digest('hex'); } -module.exports={ generateAccessToken, decodeAccessToken ,registrationToken} \ No newline at end of file +module.exports={ generateAccessToken, decodeAccessToken ,registrationToken} 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/images/badge.png b/public/images/badge.png new file mode 100644 index 0000000..983f32e Binary files /dev/null and b/public/images/badge.png differ diff --git a/public/images/boost.png b/public/images/boost.png new file mode 100644 index 0000000..687ba1d Binary files /dev/null and b/public/images/boost.png differ diff --git a/public/images/career.png b/public/images/career.png new file mode 100644 index 0000000..b26e9e8 Binary files /dev/null and b/public/images/career.png differ diff --git a/public/images/connectpeers.png b/public/images/connectpeers.png new file mode 100644 index 0000000..86df63d Binary files /dev/null and b/public/images/connectpeers.png differ diff --git a/public/images/explorepapers.png b/public/images/explorepapers.png new file mode 100644 index 0000000..cabb475 Binary files /dev/null and b/public/images/explorepapers.png differ diff --git a/public/images/follow.jpeg b/public/images/follow.jpeg new file mode 100644 index 0000000..58889ee Binary files /dev/null and b/public/images/follow.jpeg differ diff --git a/public/images/plagiarism.png b/public/images/plagiarism.png new file mode 100644 index 0000000..3f4d2c8 Binary files /dev/null and b/public/images/plagiarism.png differ diff --git a/public/index.html b/public/index.html index add1019..cd64e05 100644 --- a/public/index.html +++ b/public/index.html @@ -209,55 +209,38 @@

Explore Top Papers

Top Services

- + - +
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 30184ce..a37ad9b 100644 --- a/public/stk_signup.html +++ b/public/stk_signup.html @@ -77,6 +77,9 @@

Sign Up

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 } @@ -110,6 +113,17 @@

Sign Up

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'; @@ -123,9 +137,48 @@

Sign Up

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 } } - + \ 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); } }