简体   繁体   English

在Meteor.method中使用时,Accounts.createUser不发送验证电子邮件

[英]Accounts.createUser not sending verification email when used in Meteor.methods

I have a basic meteor method that does the following 我有一个基本的流星方法,可以执行以下操作

server/methods.js 服务器/methods.js

Meteor.methods({
  createUserAccount: function(user) {
    return Accounts.createUser(user);
    }
});

server/init.js 服务器/init.js

Meteor.startup(function() {
    process.env.MAIL_URL = ""//removed for SO;

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

from the client the registration is called like this. 从客户那里注册就是这样。

client/register.js 客户端/register.js

'submit #app-register-user': function(e,t){
        e.preventDefault();
        var user = {
            username: t.find('#app-username').value,
            email: t.find('#app-email').value,
            password: t.find('#app-password').value,
            profile:{
                name: t.find('#app-username').value
            }
        };
        Meteor.call('createUserAccount', user, function(error) {
            if(error){
                alert(error);
            }
            else{
                $("#joinModal").modal("hide");
            }
        });
}

This creates the user, however no verification email is being sent. 这将创建用户,但是不会发送验证电子邮件。 However if I was to create the user from the client side like so 但是,如果我要像这样从客户端创建用户

client/register.js 客户端/register.js

Accounts.createUser({
        username: t.find('#app-username').value,
        email: t.find('#app-email').value,
        password: t.find('#app-password').value,
        profile:{
            name: t.find('#app-username').value
        }
    },function(err){
        if(err){
            alert("something went wrong "+ err);
        }
        else{
            $("#joinModal").modal("hide");
        }
})

the email gets sent. 电子邮件被发送。

The reason why I'm trying to create the user from the server side is because I want to disable auto-login and allow users who are verified to login. 我尝试从服务器端创建用户的原因是因为我想禁用自动登录并允许经过验证的用户登录。

Any help on how to solve this would be greatly appreciated! 任何有关如何解决此问题的帮助将不胜感激!

Thank you. 谢谢。

If you create a user client side, the Accounts package takes care of creating the user in the Meteor.users collection and afterwards sending the verification email. 如果创建用户客户端,则“帐户”包将负责在Meteor.users集合中创建用户,然后发送验证电子邮件。 It does so by calling the server method createUser . 通过调用服务器方法createUser

If you create a new user server side by using your own method like you do, Accounts package only creates the user. 如果像您一样使用自己的方法创建新的用户服务器端,则“帐户”包将仅创建该用户。 You have to send the verification email yourself as richsilv suggested. 您必须按照richsilv建议自己发送验证电子邮件。 Or use some other routine that will get your verification email sent to the user. 或者使用其他一些例程,这些例程会将您的验证电子邮件发送给用户。

If you want to have some insight on how the Accounts package handles this, have a look at: Accounts packages createUser/verification 如果您想对Accounts程序包如何处理有一些了解,请看一下: Accounts程序包createUser / verification

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM