-
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
1 parent
1166e35
commit 43145cd
Showing
18 changed files
with
1,623 additions
and
59 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,4 @@ | ||
body { | ||
margin: 0; | ||
background-color: #FFF; | ||
width: 40%; } |
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 @@ | ||
body { | ||
margin: 0; | ||
background-color: #FFF; | ||
width: 40%; } |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
body { | ||
margin: 0; | ||
background-color:#FFF; | ||
width:40%; | ||
} | ||
|
||
margin: 0; | ||
background-color: #FFF; | ||
width: 40%; } |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
body { | ||
margin: 0; | ||
background-color:#CCC; | ||
width:40%; | ||
} | ||
|
||
margin: 0; | ||
background-color: #CCC; | ||
width: 40%; } |
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 @@ | ||
body { | ||
margin: 0; | ||
background-color:#FFF; | ||
width:40%; | ||
} | ||
|
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 @@ | ||
body { | ||
margin: 0; | ||
background-color:#FFF; | ||
width:40%; | ||
} | ||
|
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 @@ | ||
body { | ||
margin: 0; | ||
background-color:#FFF; | ||
width:40%; | ||
} | ||
|
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 @@ | ||
body { | ||
margin: 0; | ||
background-color:#CCC; | ||
width:40%; | ||
} | ||
|
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 |
---|---|---|
|
@@ -15,4 +15,6 @@ db.once('open', function() { | |
|
||
console.log("Successfully connected to the database"); | ||
|
||
}); | ||
}); | ||
|
||
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,82 @@ | ||
const passport = require('passport'); | ||
const LocalStrategy = require('passport-local').Strategy; | ||
const User = require('../models/user'); | ||
|
||
passport.use(new LocalStrategy({ | ||
|
||
usernameField:'email' | ||
}, | ||
function(email,password,done){ | ||
|
||
User.findOne({email:email},function(err,user){ | ||
|
||
if (err){console.log('Error in finding user ---> Passport'); return done(err);} | ||
|
||
if (!user || user.password != password){ | ||
|
||
console.log('Invalid Username/Password'); | ||
|
||
return done(null,false); | ||
|
||
} | ||
|
||
return done(null,user); | ||
|
||
}); | ||
|
||
} | ||
|
||
)); | ||
|
||
|
||
|
||
// serialing | ||
|
||
passport.serializeUser(function(user,done){ | ||
|
||
done(null,user.id); | ||
|
||
}); | ||
|
||
|
||
// deserialing | ||
|
||
passport.deserializeUser(function(id,done){ | ||
|
||
|
||
User.findById(id,function(err,user){ | ||
|
||
if (err){console.log('Error in finding user ---> Passport'); return done(err);} | ||
|
||
return done(null,user); | ||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
// check if the user is authenticated | ||
passport.checkAuthentication = function(req, res, next){ | ||
// if the user is signed in, then pass on the request to the next function(controller's action) | ||
if (req.isAuthenticated()){ | ||
return next(); | ||
} | ||
|
||
// if the user is not signed in | ||
return res.redirect('/user/sign-in'); | ||
} | ||
|
||
passport.setAuthenticatedUser = function(req, res, next){ | ||
if (req.isAuthenticated()){ | ||
// req.user contains the current signed in user from the session cookie and we are just sending this to the locals for the views | ||
res.locals.user = req.user; | ||
|
||
} | ||
|
||
return next(); | ||
} | ||
|
||
|
||
|
||
|
||
module.exports = passport; |
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.