Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,15 @@ var userSchema = mongoose.Schema({

});

// checking if password is valid using bcrypt
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
// methods ======================
// generating a hash
userSchema.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};


// this method hashes the password and sets the users password
userSchema.methods.hashPassword = function(password) {
var user = this;

// hash the password
bcrypt.hash(user.local.password, null, null, function(err, hash) {
if (err)
return next(err);

user.local.password = hash;
});

// checking if password is valid
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
};

// create the model for users and expose it to our app
Expand Down
2 changes: 1 addition & 1 deletion config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function(passport) {

// set the user's local credentials
newUser.local.email = email;
newUser.hashPassword(password); // use the generateHash function in our user model
newUser.local.password = newUser.generateHash(password); // use the generateHash function in our user model

// save the user
newUser.save(function(err) {
Expand Down