diff --git a/server/Dockerfile.ci b/server/Dockerfile.ci index b988330b0..99b2428d9 100644 --- a/server/Dockerfile.ci +++ b/server/Dockerfile.ci @@ -1,3 +1,4 @@ +#not configured properly FROM node:18 AS build WORKDIR /usr/src/app diff --git a/server/index.js b/server/index.js index 6b64efb6e..20679ae03 100644 --- a/server/index.js +++ b/server/index.js @@ -20,12 +20,13 @@ import testRoute from "./src/api/routes/test.js"; import userStudent from "./src/api/routes/userStudent.js"; import userAdmin from "./src/api/routes/userAdmin.js"; -app.use("/", indexRoute); -app.use("/test", testRoute); +app.use("/", indexRoute) +app.use("/test", testRoute) app.use("/userStudent", userStudent) app.use("/userAdmin", userAdmin) + mongoose .connect(CONNECTION_URI, { useNewUrlParser: true, useUnifiedTopology: true }) .then(() => { diff --git a/server/src/api/controllers/index.js b/server/src/api/controllers/index.js index b57733c37..603172206 100644 --- a/server/src/api/controllers/index.js +++ b/server/src/api/controllers/index.js @@ -7,24 +7,33 @@ import jwt from 'jsonwebtoken' * if yes get the session data and login * else redirect to landing page */ - if(req.session.user){ - - let isTokenValid = jwt.decode(req.session.user.token) - if(isTokenValid){ - res.status(200).json({ - success: true, - user: req.session.user, - msg: req.session.user.user.name +" is logged in successfully" - }); - } - - } - else{ - //show landing page - res.status(200).json({message:"Arrow Server is running..."}) - } + + + // if(req.session.user){ + // let isTokenValid = jwt.decode(req.session.user.token) + // if(isTokenValid){ + // res.status(200).json({ + // success: true, + // user: req.session.user, + // msg: req.session.user.user.name +" is logged in successfully" + // }); + // } + // } + // else{ + // //show landing page + // res.status(200).json({message:"Arrow Server is running..."}) + // } + /** + * If we find the way in frontend to route the user + * to homepage if there is any one already logged in else route to home page + * then we won't need above part and can be deleted + */ + + // Incase we find a way remove below response as well + res.status(200).json({message:"Arrow Server is running..."}) + } diff --git a/server/src/api/controllers/userAdmin.js b/server/src/api/controllers/userAdmin.js index 042383076..bdf331033 100644 --- a/server/src/api/controllers/userAdmin.js +++ b/server/src/api/controllers/userAdmin.js @@ -145,3 +145,9 @@ export const signin = async (req, res) => { res.json({ msg:"User Admin does not exist" }) } } + + + + + + diff --git a/server/src/api/middlewares/logout.js b/server/src/api/middlewares/logout.js new file mode 100644 index 000000000..2aee6a44b --- /dev/null +++ b/server/src/api/middlewares/logout.js @@ -0,0 +1,21 @@ +/** + * Route: /logout + * Desc: logout + */ + +export const logout = (req, res)=> { + if(req.session.user){ + req.session.destroy(err => { + if (err) { + console.error("Error destroying session:", err); + res.status(500).send("Internal Server Error"); + } else { + res.send("Logged out successfully"); + } + }); + } + else{ + res.send("No Active sessions") + } + + }; \ No newline at end of file diff --git a/server/src/api/models/userFacultyModel.js b/server/src/api/models/userFacultyModel.js index 93ece0a9a..7135cc4bd 100644 --- a/server/src/api/models/userFacultyModel.js +++ b/server/src/api/models/userFacultyModel.js @@ -1,7 +1,7 @@ import mongoose from "mongoose"; -//estimated user schema +//estimated student schema const userFacultyModel = mongoose.Schema({ id: { type: String }, name: { type: String, required: true }, diff --git a/server/src/api/models/userStaffModel.js b/server/src/api/models/userStaffModel.js index 324e6515f..7963a9b31 100644 --- a/server/src/api/models/userStaffModel.js +++ b/server/src/api/models/userStaffModel.js @@ -1,7 +1,7 @@ import mongoose from "mongoose"; -//estimated user schema +//estimated staff schema const userStaffModel = mongoose.Schema({ id: { type: String }, name: { type: String, required: true }, diff --git a/server/src/api/models/userStudentModel.js b/server/src/api/models/userStudentModel.js index 2712e77ad..3685a4a18 100644 --- a/server/src/api/models/userStudentModel.js +++ b/server/src/api/models/userStudentModel.js @@ -1,7 +1,7 @@ import mongoose from "mongoose"; -//estimated user schema +//estimated student schema const userStudentModel = mongoose.Schema({ id: { type: String }, name: { type: String, required: true }, diff --git a/server/src/api/models/userGuestModel.js b/server/src/api/models/userVisitorModel.js similarity index 65% rename from server/src/api/models/userGuestModel.js rename to server/src/api/models/userVisitorModel.js index 051ddd168..2a6d2a89e 100644 --- a/server/src/api/models/userGuestModel.js +++ b/server/src/api/models/userVisitorModel.js @@ -1,8 +1,8 @@ import mongoose from "mongoose"; -//estimated user schema -const userGuestModel = mongoose.Schema({ +//estimated visitor schema +const userVisitorModel = mongoose.Schema({ id: { type: String }, name: { type: String, required: true }, email: { type: String, required: true }, @@ -11,4 +11,4 @@ const userGuestModel = mongoose.Schema({ }) -export default mongoose.model("userGuests", userGuestModel); \ No newline at end of file +export default mongoose.model("userVisitors", userVisitorModel); \ No newline at end of file diff --git a/server/src/api/routes/index.js b/server/src/api/routes/index.js index 26f9739d1..f26b66992 100644 --- a/server/src/api/routes/index.js +++ b/server/src/api/routes/index.js @@ -3,8 +3,10 @@ import session from '../middlewares/session.js'; const router = express.Router(); import indexController from "../controllers/index.js"; +import { logout } from '../middlewares/logout.js'; router.get("/", session, indexController) +router.get("/logout",session , logout, indexController) export default router; \ No newline at end of file