meteor:显示已创建用户的警报
我想向用户显示一条消息,如:“我已发送电子邮件以激活您的帐户” 我不能,因为当用户被创建时,我还没有找到这个钩子 你知道怎么做吗meteor:显示已创建用户的警报,meteor,user-accounts,Meteor,User Accounts,我想向用户显示一条消息,如:“我已发送电子邮件以激活您的帐户” 我不能,因为当用户被创建时,我还没有找到这个钩子 你知道怎么做吗 我当前永久显示一条消息,但我不希望这样。我只想在用户烧录时显示一次。这里有两个选项,如果您在客户端创建用户,只需使用 Accounts.createUser({email: email, password: password}, function(err) { if(!err){ alert(""I have sent a email to activate
我当前永久显示一条消息,但我不希望这样。我只想在用户烧录时显示一次。这里有两个选项,如果您在客户端创建用户,只需使用
Accounts.createUser({email: email, password: password}, function(err) {
if(!err){
alert(""I have sent a email to activate your account")
}
});
或者,如果您是从一个方法创建用户,它应该是这样的
//Server.js
Meter.method({
createUser:function(username,email,password){
//create user logic.
}
})
Meteor.call('createUser',username,email,password,function(err,result){
if(!err){
alert(""I have sent a email to activate your account")
}
});
在客户机上应该是这样的
//Server.js
Meter.method({
createUser:function(username,email,password){
//create user logic.
}
})
Meteor.call('createUser',username,email,password,function(err,result){
if(!err){
alert(""I have sent a email to activate your account")
}
});
在这两种情况下,我们都使用一个名为
callback
的额外参数。此函数接受另外两个参数,它们是err,result
,因此,如果创建帐户时没有错误,则应触发警报您应该能够在客户端的createUser()回调中添加警报。假设您有一个表单之类的东西,您提交该表单来创建用户,那么您将执行以下操作
Template.myTemplate.events({
'submit #new-user-form': function(event) {
// These next few lines will depend on what your template looks like and what data you require on login
// Here I've assumed just username and pw in appropriately-named inputs on your page
var email = $('#email-input').val();
var password = $('#password-input').val();
event.preventDefault();
Accounts.createUser({email: email, password: password}, function(error) {
if (error) { alert("There was an error!"); }
else { alert("I have sent you an email to verify your account"); }
});
}
});
如果您希望在安装了帐户ui的情况下完成此行为,则不会显示任何可以挂接的内容。但是,您可以这样手动执行:
Template.myTemplate.events({
'click .login-form-create-account #login-buttons-password': function() {
alert("I sent you an email to verify your account");
}
});
不幸的是,即使没有成功创建用户,也会触发该命令。从客户端或服务器在哪里创建用户?