【问题标题】:Sending verification email with Meteor causing error使用 Meteor 发送验证电子邮件导致错误
【发布时间】:2014-04-03 04:46:59
【问题描述】:

我有以下:

Template.joinTemplate.events({
"submit #Signup-Form": function(event, template) {
    event.preventDefault();
    var email = template.find('#Email').value;
    Accounts.createUser({
        username: template.find('#Email').value,
        emails: {
            address: template.find('#Email').value
        },
        password: template.find('#Password').value,
        profile: {
            firstname: template.find("#Firstname").value,
            lastname: template.find("#Lastname").value

        }
    }, function(error) {
        if (error) {
            // Deal with errors
        } else {
            Accounts.sendVerificationEmail(this.userId, email);
            Router.go('/');

        }
    });
}
});

但是得到以下错误:

 Error logging in with token: Error: You've been logged out by the server. Please login again. [403] debug.js:41
Exception in delivering result of invoking 'createUser': TypeError: Object #<Object> has no method 'sendVerificationEmail'
    at http://localhost:3000/client/views/application/authentication/join_template.js?0ca175e5dc0f3b4596ed33e260d5636f8f9cc69b:28:26
    at http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:801:19
    at loggedInAndDataReadyCallback (http://localhost:3000/packages/accounts-base.js?efdcc57c69f7e2ccbb61f1e963da216b1729ac72:455:5)
    at null._callback (http://localhost:3000/packages/meteor.js?2b578107b8239ff9bc64200e6af2a24001461b30:801:22)
    at _.extend._maybeInvokeCallback (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3502:12)
    at _.extend.receiveResult (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3522:10)
    at _.extend._livedata_result (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:4452:9)
    at onMessage (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3376:12)
    at http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:2705:11
    at Array.forEach (native) 

我已经安装了所有的accounts-base、accounts-ui、accounts-password。

不知道我做错了什么:(

【问题讨论】:

    标签: meteor meteorite


    【解决方案1】:

    正如您在the documentation 中看到的,Accounts.sendVerificationEmail 仅在服务器上可用,而您正尝试在客户端上使用它。

    我不确定你是否可以使用Accounts.onCreateUser函数发送验证邮件:在这个函数中,用户还没有被添加到Meteor.users集合中,我猜Accounts.sendVerificationEmail需要用户在那个集合中。我不知道解决这个问题的最佳方法,但您始终可以使用光标选择所有用户,然后观察添加到集合中的用户(尽管这不是一个好的解决方案)。

    Accounts.config函数中使用sendVerificationEmail字段还不够?

    【讨论】:

    • 谢谢佩佩。我错过了明显的。您介意解释一下我如何将新创建的 userId 传递给 sendVerificationEmail 吗?例如,如果我将“Meteor.call('VerifyEmail', _Id?电子邮件功能。再次感谢 :)
    猜你喜欢
    • 2016-02-16
    • 2015-11-23
    • 1970-01-01
    • 2015-02-15
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    相关资源
    最近更新 更多