Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shakti1590 committed May 30, 2023
0 parents commit ff09d31
Show file tree
Hide file tree
Showing 31 changed files with 3,464 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/

6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"emmet.includeLanguages": {
"ejs": "html"
},
"html.format.unformatted": "wbr,%"
}
4 changes: 4 additions & 0 deletions README.md
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.

21 changes: 21 additions & 0 deletions configs/db_connection.js
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;
67 changes: 67 additions & 0 deletions configs/passport_local_strategy.js
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;
Loading

0 comments on commit ff09d31

Please sign in to comment.