-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ff09d31
Showing
31 changed files
with
3,464 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ERS_DB_URI= 'mongodb+srv://shaktibtcs38:[email protected]/?retryWrites=true&w=majority' | ||
ERS_SESSION_SECRETE='secrete' | ||
ERS_PORT=5000 |
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,2 @@ | ||
node_modules/ | ||
|
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,6 @@ | ||
{ | ||
"emmet.includeLanguages": { | ||
"ejs": "html" | ||
}, | ||
"html.format.unformatted": "wbr,%" | ||
} |
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,4 @@ | ||
# Employee Review System | ||
|
||
Employee review system webapp is an online platform designed to assist companies in managing their employee performance evaluations. The system allows managers to conduct employee performance reviews, track progress, and provide feedback in a centralized location. | ||
|
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,21 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const url = process.env.ERS_DB_URI; // mongoodb url | ||
mongoose.connect(url); // connecting to db | ||
|
||
const db = mongoose.connection; // getting connection of db | ||
|
||
db.on('error', console.error.bind(console, 'Error: connecting to db :: MongoDB')); // if error while conecting to db | ||
|
||
|
||
// once connection is open (started) | ||
db.once('open', (err) => { | ||
if (err) { | ||
console.log('Error: while opening db connection', err); | ||
} else { | ||
console.log('DB connection successfull :: MongoDB'); | ||
} | ||
}) | ||
|
||
|
||
module.exports = db; |
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,67 @@ | ||
const passport = require('passport'); | ||
const localStrategy = require('passport-local').Strategy; | ||
|
||
const User = require('../models/user'); | ||
|
||
/** | ||
* using local strategy of passport js to validate user | ||
* serialize user -- takes user and put its id into session cookie | ||
* deserialize user -- decrypt user id and get user from its id | ||
* checkAuthentication -- custom middleware to check if user if logged or not | ||
* setAuthenticatedUser -- if user is logged it takes user from request and put it into locals to use in ejs | ||
*/ | ||
|
||
passport.use(new localStrategy({ | ||
usernameField: 'email', | ||
passwordField: 'password', | ||
}, | ||
async (email, password, done) => { | ||
|
||
|
||
try { | ||
// find user by its email ID | ||
const user = await User.findOne({ email: email }); | ||
//if we don't find email return from here saying authentication false | ||
if (!user || user.password != password) { return done(null, false); } | ||
return done(null, user); | ||
|
||
} catch (error) { | ||
console.error('Error: ', error); | ||
return done(null, false); | ||
} | ||
|
||
})); | ||
|
||
|
||
passport.serializeUser((user, done) => { | ||
done(null, user.id); | ||
}); | ||
|
||
|
||
passport.deserializeUser(async (id, done) => { | ||
|
||
|
||
try { | ||
const user = await User.findById(id); | ||
if (!user) { return done(new Error('unable to find user '), false); } | ||
user.password = undefined; | ||
done(null, user); | ||
} catch (error) { | ||
done(error, false); | ||
} | ||
}); | ||
|
||
|
||
passport.checkAuthentication = function (req, res, next) { | ||
if (req.isAuthenticated()) { return next(); } | ||
return res.redirect('/signin'); | ||
} | ||
|
||
|
||
passport.setAuthenticatedUser = function (req, res, next) { | ||
if (req.isAuthenticated()) { res.locals.user = req.user; } | ||
next(); | ||
} | ||
|
||
|
||
module.exports = passport; |
Oops, something went wrong.