使用accounts.ui包验证电子邮件

时间:2013-01-31 00:35:35

标签: email meteor verification

我想在创建某个用户时发送验证邮件。我使用accounts-password包,因此在我的代码中调用任何Accounts方法。

我在文档中读到了我需要调用的内容:

Accounts.sendVerificationEmail(userId, [email])

但问题是我不知道何时调用它。

我试图调用Accounts.onCreateUser(func)的回调函数,但尚未在数据库中创建用户。

有什么想法吗?

3 个答案:

答案 0 :(得分:14)

服务器端上的

Accounts.config({sendVerificationEmail: true, forbidClientAccountCreation: false}); 

得到了上述评论的答案。

答案 1 :(得分:3)

sendVerificationEmail is only available server-side。我通常做的是在setInterval内使用onCreateUser等待Meteor在发送电子邮件之前创建用户。

阅读更多Verify an Email with Meteor Accounts

// (server-side)
Accounts.onCreateUser(function(options, user) {  
  user.profile = {};

  // we wait for Meteor to create the user before sending an email
  Meteor.setTimeout(function() {
    Accounts.sendVerificationEmail(user._id);
  }, 2 * 1000);

  return user;
});

答案 2 :(得分:2)

您需要在环境变量中指定邮件。 然后在Accounts.sendVerificationEmail(userId, [email])的回调中使用Account.onCreateUser抱歉错误和延迟。

像这样(下面是完整的示例js文件):

Template.register.events({
'submit #register-form' : function(e, t) {
  e.preventDefault();
  var email = t.find('#account-email').value
    , password = t.find('#account-password').value;

    // Trim and validate the input

  Accounts.onCreateUser({email: email, password : password}, function(err){
      if (err) {
        // Inform the user that account creation failed
      } else {
        // Success. Account has been created and the user
        // has logged in successfully.
       Accounts.sendVerificationEmail(this.userId, email);
      }
    });

  return false;
}  });

if(Meteor.isServer){
   Meteor.startup(function(){
      process.env.MAIL_URL='smtp://your_mail:your_password@host:port'
   }
}

我参考了这个页面: http://blog.benmcmahen.com/post/41741539120/building-a-customized-accounts-ui-for-meteor

http://sendgrid.com/blog/send-email-meteor-sendgrid/

How come my Meteor app with accounts package is not sending a verification email?