Skip to content

Instantly share code, notes, and snippets.

@deedubs
Forked from shiawuen/index.js
Created January 19, 2012 19:04
Show Gist options
  • Save deedubs/1641857 to your computer and use it in GitHub Desktop.
Save deedubs/1641857 to your computer and use it in GitHub Desktop.

Revisions

  1. Dan Williams revised this gist Jan 19, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    var userSchema = new Schema({
    email: String
    , passwordHash: String
    @@ -8,6 +7,9 @@ userSchema.pre('validate', function(next) {
    if (this.password === this.passwordConfirm) {
    this.set('passwordHash', hash(this.password);

    this.set('passwordHash',undefined);
    this.set('passwordConfirm',undefined);

    // How do I prevent this.password and this.passwordConfirm
    // to be save into DB?
    }
  2. @shiawuen shiawuen revised this gist Jan 19, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,8 @@ userSchema.pre('validate', function(next) {
    // How do I prevent this.password and this.passwordConfirm
    // to be save into DB?
    }

    next()
    });

    var User = db.model('User', userSchema);
  3. @shiawuen shiawuen revised this gist Jan 19, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -26,5 +26,5 @@ user.save(function(err) {
    console.log(!!err ? 'error' : 'saved');
    });

    function hash(str) { return str+'hashed }
    function hash(str) { return str+'hashed' }

  4. @shiawuen shiawuen created this gist Jan 19, 2012.
    30 changes: 30 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@

    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?
    }
    });

    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 }