2014-03-02 46 views
0

我有以下幾點:發送驗證電子郵件和流星造成的錯誤

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) 

我所有賬戶基地,賬戶的用戶界面,安裝密碼賬戶。

不知道我做錯了什麼:(

回答

2

正如你在讀the documentationAccounts.sendVerificationEmail只在服務器上可用,並且你想使用它的客戶端上。

我我不確定你是否可以使用Accounts.onCreateUser函數發送驗證郵件:在這個函數中,用戶還沒有被添加到Meteor.users集合中,我猜Accounts.sendVerificationEmail要求用戶在那個集合中。我不知道解決這個問題的最好方法,但你可以隨時使用光標選擇所有用戶,然後觀察添加到集合中的用戶(儘管這不是一個好的解決方案)。

僅使用Accounts.config函數中的sendVerificationEmail字段是不夠的?

+0

謝謝佩佩。我錯過了明顯的。你介意解釋我如何將新創建的userId傳遞給sendVerificationEmail?例如,如果我在上面的例子中將「Meteor.call('VerifyEmail',_Id?< - 在我的成功函數中?我現在也使用OnCreateUser,但不理解如何獲取發送給電子郵件功能。再次感謝:) – user1447679

+0

@ user1447679看到我更新的答案。 –