Created
January 19, 2012 18:52
-
-
Save shiawuen/1641813 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
var userSchema = new Schema({ | |
email: String | |
, passwordHash: String | |
}); | |
userSchema.pre('validate', function(next) { | |
if (this.password === this.passwordConfirm) { | |
this.set('passwordHash', hash(this.password); | |
// How do I prevent this.password and this.passwordConfirm | |
// to be save into DB? | |
} | |
next() | |
}); | |
var User = db.model('User', userSchema); | |
var user = new User() | |
user.init({ | |
email: '[email protected]' | |
, password: 'password' | |
, confirmPassword: 'password' | |
}); | |
user.save(function(err) { | |
console.log(!!err ? 'error' : 'saved'); | |
}); | |
function hash(str) { return str+'hashed' } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment