forked from iampavangandhi/TradeByte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default Password Error Resolved, Code Prettified, Other Issues Resolved
- Loading branch information
1 parent
13c8fe1
commit 0b99ae5
Showing
19 changed files
with
1,205 additions
and
743 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 |
---|---|---|
@@ -1,40 +1,40 @@ | ||
const LocalStrategy = require('passport-local').Strategy; | ||
const bcrypt = require('bcryptjs'); | ||
const LocalStrategy = require("passport-local").Strategy; | ||
const bcrypt = require("bcryptjs"); | ||
|
||
// Load User model | ||
const User = require('../models/User'); | ||
const User = require("../models/User"); | ||
|
||
module.exports = function (passport) { | ||
passport.use( | ||
new LocalStrategy({ usernameField: 'email' }, (email, password, done) => { | ||
// Match User | ||
User.findOne({ | ||
email: email | ||
}).then(user => { | ||
if (!user) { | ||
return done(null, false, { message: 'That email is not registered' }) | ||
} | ||
passport.use( | ||
new LocalStrategy({ usernameField: "email" }, (email, password, done) => { | ||
// Match User | ||
User.findOne({ | ||
email: email, | ||
}).then((user) => { | ||
if (!user) { | ||
return done(null, false, { message: "That email is not registered" }); | ||
} | ||
|
||
// Match user Password | ||
bcrypt.compare(password, user.password, (err, isMatch) => { | ||
if (err) throw err; | ||
if (isMatch) { | ||
done(null, user); | ||
} else { | ||
return done(null, false, { message: 'That password is incorrect' }) | ||
} | ||
}) | ||
}) | ||
}) | ||
) | ||
// Match user Password | ||
bcrypt.compare(password, user.password, (err, isMatch) => { | ||
if (err) throw err; | ||
if (isMatch) { | ||
done(null, user); | ||
} else { | ||
return done(null, false, { message: "That password is incorrect" }); | ||
} | ||
}); | ||
}); | ||
}) | ||
); | ||
|
||
passport.serializeUser((user, done) => { | ||
done(null, user.id); | ||
}); | ||
passport.serializeUser((user, done) => { | ||
done(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser((id, done) => { | ||
User.findById(id, (err, user) => { | ||
done(err, user); | ||
}); | ||
passport.deserializeUser((id, done) => { | ||
User.findById(id, (err, user) => { | ||
done(err, user); | ||
}); | ||
} | ||
}); | ||
}; |
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
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.