mrcni
mrcni

Reputation: 509

password confirmation with sails.js

I am trying to set up password confirmation in sails 0.10.0-rc9. this is for a new user sign-up. when i use the same password in both fields, console confirms it's grabbing the same passwords, then spits out the error that they don't match. I want to know what I'm missing...

the model - user.js - looks like https://github.com/mrcn/C_Express/blob/master/api/models/User.error.js

module.exports = {
  schema: true,
  attributes: {
    name: {
      type: "string",
      required: true
    },
    email: {
      type: "string",
      email: true,
      required: true,
      unique: true
    },
    encryptedPassword: {
      type: "string"
    },
    toJSON: function() {
      var obj = this.toObject();
      delete obj.password;
      delete obj.confirmation;
      delete obj.encryptedPassword;
      delete obj._csrf;
      return obj;
    }
  },
  beforeCreate: function (values, next) {
      console.log("Called beforeCreate User ");
      console.log(values);
    if(!values.password || values.password != values.confirmation) {
      console.log("\n if statement call \n");
      return next({
        err : ["password dont match."]
      });
    }
  }
};

the form looks like this: https://github.com/mrcn/C_Express/blob/master/views/user/new.ejs

  <input type="text" class="form-control" placeholder="your name" name="name" required />

  <input type="email" class="form-control" placeholder="email address" name="email" data-parsley-trigger="change" required />

  <input type="password" class="form-control" placeholder="password" name="password" required />

  <input type="password" class="form-control" placeholder="confirmation" name="confirmation" required />
  <br />

  <input type="submit" class="btn btn-lg btn-primary btn-block" value="Create Account" />
  <input type="hidden" name="_csrf" value="<% _csrf %>" />

when i use random "wer" for everything, Console logs"

Called beforeCreate User
{ name: 'wer',
  email: '[email protected]',
  password: 'wer',
  confirmation: 'wer',
  _csrf: '',
  id: null }

 if statement call

{ err: [ 'password dont match.' ] }

Upvotes: 0

Views: 1141

Answers (2)

marcelo medina
marcelo medina

Reputation: 1

beforeCreate changes to beforeValidate Ç

Upvotes: 0

sgress454
sgress454

Reputation: 24948

Maybe spell password the same in both places? :P

if(!values.password || values.pasword != values.confirmation) {
                                ^oops

Upvotes: 5

Related Questions