Created
January 4, 2016 02:26
-
-
Save miyamotodev123/ee315d5b3075bd934925 to your computer and use it in GitHub Desktop.
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
// app/models/user.js | |
// load the things we need | |
var mongoose = require('mongoose'); | |
var bcrypt = require('bcrypt-nodejs'); | |
// define the schema for our user model | |
var userSchema = mongoose.Schema({ | |
local : { | |
email : String, | |
password : String, | |
} | |
}); | |
// methods ====================== | |
// generating a hash | |
userSchema.methods.generateHash = function(password) { | |
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); | |
}; | |
// 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 | |
module.exports = mongoose.model('User', userSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment