我在“Accounts.onCreateUser”函数中执行服务器端验证,以便我也可以传递选项对象。我无法弄清楚如何使用验证用户功能来做到这一点。流星 - 如何在密码上使用服务器端验证
首先,如果我要走错方向,我完全开放,请告知。 我无法弄清楚如何验证服务器端的密码长度。是因为它在创建之前已经转换了吗?测试时,如果我输入一个字符作为密码,它不会引发错误。
Accounts.onCreateUser(function (options, user) {
if (options.profile) {
user.profile = options.profile;
user.profile.user_status = "new user";
}
// Error checking
var errors = "";
if (user.username.length === 0) {
errors = errors + '<li>Email is required</li>';
}
if (user.username.length !== 0 && user.username.length < 4) {
errors = errors + '<li>Email too short</li>';
}
if (user.profile.firstname.length === 0) {
errors = errors + '<li>First name is required</li>';
}
if (user.profile.firstname.length !== 0 && user.profile.firstname.length < 2) {
errors = errors + '<li>First name is too short</li>';
}
if (user.profile.lastname.length === 0) {
errors = errors + '<li>Last name is required</li>';
}
if (user.profile.lastname.length !== 0 && user.profile.lastname.length < 2) {
errors = errors + '<li>Last name is too short</li>';
}
if (user.services.password.length === 0) {
errors = errors + '<li>Please enter a password</li>';
}
if (user.services.password.length < 7) {
errors = errors + '<li>Password requires 7 or more characters</li>';
}
if (errors) {
throw new Meteor.Error(403, errors);
} else {
return user;
}
});
我没有使用Accounts-ui。试图推出我自己的...对流星来说全新的,它试图了解账户创建和验证是一场战斗。如果有一种方法可以用ValidateNewUser函数来做到这一点,我应该使用它吗?
谢谢你的一切帮助。
你没有使用任何预建的东西?不是账户密码包? –
我正在使用帐户库和帐户密码。嗨派佩!你不太会睡吗?我不应该说预先构建的东西,因为它是误导性的。编辑我的问题。 :) – user1447679