Skip to content

Commit

Permalink
Merge pull request #127 from ygowthamr/LogoutFunctionalityAdded
Browse files Browse the repository at this point in the history
Logout functionality for stakeholder and student
  • Loading branch information
Harshdev098 authored Oct 15, 2024
2 parents 35ed3aa + f48449c commit 6b8e994
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 152 deletions.
230 changes: 124 additions & 106 deletions login-system/dbServer.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,144 @@
const express = require('express')
const path = require('path')
const { upload, save, disp } = require(path.resolve(__dirname, '../file_upload/upload.js'));
const {stk_signup,stk_signin}=require('../stakeholder/login')
const {info,check} = require('../file_upload/form_db')
const { signup, signin } = require('./login');
const rateLimiter=require('express-rate-limit')
const { approve,uploadedpapers,displaydetail }= require('../stakeholder/stk_approval')
const {display}=require('../backend/profile');
const {stk_display}=require('../backend/stk_profile')
const { setcriteria, evaluate } = require('../stakeholder/evaluation');
const {allot,DisplayPapers} = require('../stakeholder/allotment');
const {Dis_fac_papers, fac_signup, fac_login, dis_mail, giverating}=require('../stakeholder/faculty')
const app = express()

const globalLimit=rateLimiter({
windowMs:30*60*1000,
max:100,
message:"Too amny request from same IP"
})

app.use(globalLimit)

// serving pages
app.use(express.static(path.join(__dirname, '../public')));

app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '../public/index.html'));
const express = require("express");
const path = require("path");
const { upload, save, disp } = require(path.resolve(
__dirname,
"../file_upload/upload.js"
));
const { stk_signup, stk_signin } = require("../stakeholder/login");
const { info, check } = require("../file_upload/form_db");
const { signup, signin } = require("./login");
const rateLimiter = require("express-rate-limit");
const {
approve,
uploadedpapers,
displaydetail,
} = require("../stakeholder/stk_approval");
const { display } = require("../backend/profile");
const { stk_display } = require("../backend/stk_profile");
const { logout } = require("./logout");
const { setcriteria, evaluate } = require("../stakeholder/evaluation");
const { allot, DisplayPapers } = require("../stakeholder/allotment");
const {
Dis_fac_papers,
fac_signup,
fac_login,
dis_mail,
giverating,
} = require("../stakeholder/faculty");
const app = express();

const globalLimit = rateLimiter({
windowMs: 30 * 60 * 1000,
max: 100,
message: "Too amny request from same IP",
});
app.get('/login.html', (req, res) => {
res.sendFile(path.join(__dirname, '../public/login.html'));
})
app.get('/signup.html', (req, res) => {
res.sendFile(path.join(__dirname, '../public/signup.html'));
})
app.get('/main_page.html', (req, res) => {
res.sendFile(path.join(__dirname, '../public/main_page.html'));
})
app.get('/upload_file.html', (req, res) => {
res.sendFile(path.join(__dirname, '../public/upload_file.html'));
})
app.get('/stk_signup.html',(req,res)=>{
res.sendFile(path.join(__dirname, '../public/stk_signup.html'));
})
app.get('/form_filling',async (req,res)=>{
await check(req,res)
})
app.get('/dashboard',async(req,res)=>{
await display(req,res);
})


app.use(express.json())
app.use(express.static('../file_upload/uploads'))

app.use(globalLimit);

app.post("/logout", logout);

// serving pages
app.use(express.static(path.join(__dirname, "../public")));

app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "../public/index.html"));
});
app.get("/login.html", (req, res) => {
res.sendFile(path.join(__dirname, "../public/login.html"));
});
app.get("/signup.html", (req, res) => {
res.sendFile(path.join(__dirname, "../public/signup.html"));
});
app.get("/main_page.html", (req, res) => {
res.sendFile(path.join(__dirname, "../public/main_page.html"));
});
app.get("/upload_file.html", (req, res) => {
res.sendFile(path.join(__dirname, "../public/upload_file.html"));
});
app.get("/stk_signup.html", (req, res) => {
res.sendFile(path.join(__dirname, "../public/stk_signup.html"));
});
app.get("/form_filling", async (req, res) => {
await check(req, res);
});
app.get("/dashboard", async (req, res) => {
await display(req, res);
});

app.use(express.json());
app.use(express.static("../file_upload/uploads"));

// serving ejs files
app.set('views', path.join(__dirname, '../views'));
app.set('view engine','ejs')
app.get('/stk_papers',async(req,res)=>{
res.render('stk_papers')
})
app.get('/api/stk_papers',uploadedpapers) //displaying uploaded papers to the stakeholder during approval
app.get('/api/papers_detail',displaydetail) //displaying uploaded papers details to the stakeholder during approval
app.get('/allotment',DisplayPapers) //displaying papers
app.get('/fac_signup',(req,res)=>{
dis_mail(req,res) //displaying the email of the faculty on signup page
})

// uploading files
app.post('/upload', upload.single('file'), async (req, res) => {
if (!req.file) {
console.error('File upload failed');
return res.status(500).send('File upload failed');
}
try {
console.log('File uploaded successfully:', req.file.filename);
await save(req, res);
res.sendStatus(200);
} catch (error) {
console.error('Error during upload:', error);
return res.status(500).send('Internal Server Error');
}
app.set("views", path.join(__dirname, "../views"));
app.set("view engine", "ejs");
app.get("/stk_papers", async (req, res) => {
res.render("stk_papers");
});
app.get("/api/stk_papers", uploadedpapers); //displaying uploaded papers to the stakeholder during approval
app.get("/api/papers_detail", displaydetail); //displaying uploaded papers details to the stakeholder during approval
app.get("/allotment", DisplayPapers); //displaying papers
app.get("/fac_signup", (req, res) => {
dis_mail(req, res); //displaying the email of the faculty on signup page
});

// uploading files
app.post("/upload", upload.single("file"), async (req, res) => {
if (!req.file) {
console.error("File upload failed");
return res.status(500).send("File upload failed");
}
try {
console.log("File uploaded successfully:", req.file.filename);
await save(req, res);
res.sendStatus(200);
} catch (error) {
console.error("Error during upload:", error);
return res.status(500).send("Internal Server Error");
}
});

// uploading user information to database
app.post('/info', info);
app.post("/info", info);

// serving uploaded research papers to the student
app.get('/uploaded_files', disp)
app.get("/uploaded_files", disp);

// creating users
app.post("/create_user",signup)
app.post("/stk_holder_signup",stk_signup)
app.post('/fac_signup',fac_signup) // registration of faculty

app.post("/create_user", signup);
app.post("/stk_holder_signup", stk_signup);
app.post("/fac_signup", fac_signup); // registration of faculty

// login backend
app.post("/login",signin)
app.post("/stk_holder_signin",stk_signin)
app.post('/fac_login',fac_login) //login for faculty
// login backend
app.post("/login", signin);
app.post("/stk_holder_signin", stk_signin);
app.post("/fac_login", fac_login); //login for faculty

// approval by stakeholder
app.get('/approval',approve)
app.get("/approval", approve);

// setting evaluation criteria
app.post('/evaluation',setcriteria)
// setting evaluation criteria
app.post("/evaluation", setcriteria);

// alloting papers to the faculty
app.post('/paper_allot',allot)
app.post("/paper_allot", allot);

// sending papers to the alloted faculty
app.use('/uploads', express.static(path.join(__dirname, '../file_upload/uploads')));
app.get('/fac_papers',Dis_fac_papers)

// saving rating given by faculty
app.post('/rating',giverating)
app.get('/result',evaluate)

// displaying stk profile details
app.get('/stk_profile_detail',stk_display)
app.use(
"/uploads",
express.static(path.join(__dirname, "../file_upload/uploads"))
);
app.get("/fac_papers", Dis_fac_papers);

// saving rating given by faculty
app.post("/rating", giverating);
app.get("/result", evaluate);

// displaying stk profile details
app.get("/stk_profile_detail", stk_display);
// app.get('/dis_criteria',dis_evaluation_criteria)

// starting the app on port
const port = process.env.PORT || 3000
app.listen(port,
() => console.log(`Server Started on port http://localhost:${port}`))
// starting the app on port
const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Server Started on port http://localhost:${port}`)
);
6 changes: 6 additions & 0 deletions login-system/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const logout = async (req, res) => {
localStorage.removeItem("accessToken");
res.sendStatus(200);
};

module.exports = { logout };
28 changes: 24 additions & 4 deletions public/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<li><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>Home</li>
<li><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>About Us</li>
<li onclick="view_result()"><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>View Result</li>
<li><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>Log Out</li>
<li id="logoutBtn"><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>Log Out</li>
</ul>
</div>
<div class="largesection">
Expand Down Expand Up @@ -99,7 +99,27 @@
}
}
fetchdata()
const handleLogout = async () => {
try {
const token = localStorage.getItem('token'); // Retrieve the token from storage
const response = await fetch('/logout', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`, // Send the token if needed
},
});

if (response.ok) {
localStorage.removeItem('token'); // Remove the token from storage
window.location.href = '/';
} else {
console.error("Logout failed:", response.statusText);
}
} catch (error) {
console.error("Logout error:", error);
}
};
document.getElementById('logoutBtn').addEventListener('click', handleLogout);
function hide() {
document.body.classList.toggle("dark-theme");
const regularicon = document.getElementById('regular')
Expand Down Expand Up @@ -152,8 +172,8 @@
const result = document.getElementById('result')
result.innerHTML = "Result not declared yet!"
result.style.color = "red"
result.style.padding="16px"
result.style.fontSize="18px"
result.style.padding = "16px"
result.style.fontSize = "18px"
}
else {
console.log("an error occured")
Expand All @@ -162,4 +182,4 @@
</script>
</body>

</html>
</html>
Loading

0 comments on commit 6b8e994

Please sign in to comment.