我有一個表單,用戶在連接表單中輸入他們的電子郵件地址和密碼。這創建了帳戶,但我現在想要進一步開發它。流星:創建帳戶之前,Meteor.users收集中不存在檢查郵件
client.js
Template.joinForm.events({
'submit .form-join': function(e, t) {
e.preventDefault();
var email = t.find('#email').value,
password = t.find('#password').value,
username = Random.id(),
array = [],
profile = {
nameOfArray: array
};
Accounts.createUser({
email: email,
username: username,
password: password,
profile: profile
}, function(error) {
if (error) {
alert(error);
} else {
Router.go('/');
}
});
}
});
之前創建一個用戶帳號,你怎麼了:
1,檢查從joinForm「電子郵件」變量尚不存在的流星。用戶收集(在服務器上處理)?
- 如果'email'確實存在,那麼拒絕用戶創建?
我已經看到了新的功能,並想知道我是否使用它? http://docs.meteor.com/#/full/accounts_validatenewuser
Accounts.validateNewUser(function (user) {
//pseudo if statement code
if (email not exist) {
1. create the user account and then
Accounts.sendVerificationEmail(userId, [email])
} else {
throw new Meteor.Error(403, "email address is already registered");
}
});
感謝您閱讀此。
我不清楚是否使用Accounts.createUser或Accounts.onCreateUser和 應該是客戶上的代碼,其中服務器上。我的目標是安全地建立帳戶,因此,在此過程中從控制檯拒絕任何其他修改權限。
卡森,你是對的。驗證需要在Accounts.onCreateUser中完成。 – meteorBuzz 2015-03-26 18:36:16