Meteor : Accounts onCreateUser

微笑、不失礼 提交于 2020-01-03 04:54:11

问题


Accounts.onCreateUser(function(options,user){
  if (options.password.length < 6 && options.password.length != 0) {
    throw new Meteor.Error();
  } else if (options.password.length == 0) {
    throw new Meteor.Error();
  } else {
    user.password = options.password;
  }
});

Simple server-side validation.

Here's my create user call:

Accounts.createUser({email:email,username:username,password:password,profile:{firstname:firstname,lastname:lastname}},function(error){});

Without the server-side validation, it works smoothly.

and the problem is... it says length of undefined when I use the onCreateUser.

I guess the .length is the problem. But I need it. any workarounds?


回答1:


You can't do that. The password is explicitly deleted in the code.

// Attempt to log in as a new user.
Accounts.createUser = function (options, callback) {
  options = _.clone(options); // we'll be modifying options

  if (!options.password)
    throw new Error("Must set options.password");
  var verifier = SRP.generateVerifier(options.password);
  // strip old password, replacing with the verifier object
  delete options.password;
  options.srp = verifier;



回答2:


The options object has the following structure:

{
    username: 'dummy',
    email: 'dumm@example.com',
    password: {
        digest: '7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4da9a',
        algorithm: 'sha-256'
    }
}

As you can see, the password field is an object with a digest (a hash) so you can't retrieve the password on the server (nor can you test for its length).


It seems like you subsequently asked another question on how to check password length in the server. The answer to which backs up the fact that you can't.



来源:https://stackoverflow.com/questions/20787620/meteor-accounts-oncreateuser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!