我想向用户显示这样的信息:“我已经发送了一封电子邮件来激活您的帐户”。
我不能这样做,因为当用户被创建时,我还没有找到一个钩子。
你知道怎么做吗?
我目前永久地显示一条信息,但我不想这样做。我只想在用户被烧掉的时候显示一次。
发布于 2015-03-31 17:11:18
这里有两个选项,如果要在客户端创建用户,只需使用
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")
}
});在这两种情况下,我们都使用一个额外的参数,名为callback这个函数,接受另外两个参数,即err,result,因此,如果在创建帐户时没有错误,则应该触发警报。
发布于 2015-03-31 17:26:35
您应该能够在客户机上的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"); }
});
}
}); 如果您希望在安装了accounts ui时完成此行为,文献资料将不会显示您可以连接到的任何内容。但是,您可以手动这样做:
Template.myTemplate.events({
'click .login-form-create-account #login-buttons-password': function() {
alert("I sent you an email to verify your account");
}
}); 不幸的是,即使用户没有成功创建,这仍然会触发。
https://stackoverflow.com/questions/29373997
复制相似问题