Skip to content

Commit

Permalink
Merge pull request #44 from Naresh-chandanbatve/main
Browse files Browse the repository at this point in the history
Added logout & deployment Bugs fixed
  • Loading branch information
Siddhant-Patil0203 authored Aug 31, 2023
2 parents 901c443 + ff8c6a3 commit 541fc85
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions server/Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#not configured properly
FROM node:18 AS build

WORKDIR /usr/src/app
Expand Down
5 changes: 3 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
41 changes: 25 additions & 16 deletions server/src/api/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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..."})


}

Expand Down
6 changes: 6 additions & 0 deletions server/src/api/controllers/userAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ export const signin = async (req, res) => {
res.json({ msg:"User Admin does not exist" })
}
}






21 changes: 21 additions & 0 deletions server/src/api/middlewares/logout.js
Original file line number Diff line number Diff line change
@@ -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")
}

};
2 changes: 1 addition & 1 deletion server/src/api/models/userFacultyModel.js
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion server/src/api/models/userStaffModel.js
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion server/src/api/models/userStudentModel.js
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -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 },
Expand All @@ -11,4 +11,4 @@ const userGuestModel = mongoose.Schema({

})

export default mongoose.model("userGuests", userGuestModel);
export default mongoose.model("userVisitors", userVisitorModel);
2 changes: 2 additions & 0 deletions server/src/api/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 541fc85

Please sign in to comment.