-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added logs page and checkDomain function
- Loading branch information
1 parent
c1cfc70
commit 883fe10
Showing
14 changed files
with
205 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// middleware/checkDomain.js | ||
|
||
function checkDomain(req, res, next) { | ||
const allowedDomain = 'gne1.gndec.ac.in'; | ||
const origin = req.get('Origin') || req.get('Referer'); | ||
|
||
if (origin) { | ||
const url = new URL(origin); | ||
if (url.hostname === allowedDomain) { | ||
return next(); | ||
} | ||
} | ||
|
||
res.status(403).json({ message: 'Forbidden' }); | ||
} | ||
|
||
module.exports = checkDomain; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const jwt = require('jsonwebtoken') | ||
const JWT_Token = process.env.JWT_TOKEN; | ||
|
||
function isAdmin(req, res, next) { | ||
// Get the authentication token from the request headers | ||
const token = req.header('auth-token') | ||
if (!token) { | ||
return res.status(401).json({ message: 'Authentication token not provided' }); | ||
} | ||
try { | ||
// Verify the token and decode its payload | ||
const decodedToken = jwt.verify(token, JWT_Token); | ||
|
||
// Check if the user role is "admin" | ||
if (decodedToken.user.role !== 'superadmin') { | ||
return res.status(403).json({ message: 'You are not authorized to access this resource' }); | ||
} | ||
// User is authorized, proceed to the next middleware or route handler | ||
next(); | ||
} catch (error) { | ||
return res.status(401).json({ message: 'Invalid authentication token' }); | ||
} | ||
} | ||
module.exports = isAdmin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const Logs = require('../../models/logs') | ||
const fetchuser = require("../../middleware/fetchUser"); | ||
const isSuperAdmin = require("../../middleware/isSuperAdmin"); | ||
|
||
router.get('/getalllogs', fetchuser, isSuperAdmin, async (req, res) => { | ||
try { | ||
|
||
const allLogs = await Logs.find({}) | ||
if (!allLogs) { | ||
return res.status(404).json({ success: false, message: 'Logs not found' }); | ||
} | ||
return res.status(200).json({ success: true, data: allLogs }); | ||
|
||
} | ||
catch (error) { | ||
console.error('Error:', error); | ||
res.status(500).json({ success: false, message: 'Internal server error occurred' }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.