有人可以提供用戶創建時發送電子郵件驗證的正確方法嗎?這是重要的部分...流星:Accounts.sendVerificationEmail自定義行爲
a)我希望用戶在註冊後立即訪問。但是如果用戶在48小時內沒有點擊點擊驗證鏈接,我想拒絕他們登錄,直到他們點擊鏈接。
我的代碼到目前爲止都會發送一個電子郵件驗證,但用戶可以連續訪問應用程序,無論是否點擊驗證鏈接(所以我的代碼當然是不完整的)。
client.js
Template.join.events({
'submit #join-form': function(e,t){
e.preventDefault();
var firstName= t.find('#join-firstName').value,
lastName= t.find('#join-lastName').value,
email = t.find('#join-email').value,
password = t.find('#join-password').value,
username = firstName.substring(0) + '.' + lastName.substring(0),
profile = {
fullname: firstName + ' ' + lastName
};
Accounts.createUser({
email: email,
username: username,
password: password,
userType: // 'reader' or 'publisher'
createdAt: new Date(),
profile: profile
}, function(error) {
if (error) {
alert(error);
} else {
Router.go('home');
}
});
}
});
server.js
Meteor.startup(function() {
process.env.MAIL_URL = 'smtp://postmaster.....';
Accounts.emailTemplates.from = "[email protected]";
Accounts.emailTemplates.sitename = "My SIte Name";
Accounts.emailTemplates.verifyEmail.subject = function(user) {
return 'Please confirm tour Email address' ;
},
Accounts.emailTemplates.verifyEmail.text = function(user, url) {
return 'Click on the link below to verify your address: ' + url;
}
Accounts.config({
sendVerificationEmail: true
});
我嘗試已通過對流星文檔自己的讀數做出和SO尋找其他的代碼。我被卡住了。感謝您的支持。
要公平48小時的寬限期不需要那麼嚴格。只要在某個時候用戶的電子郵件地址有驗證。我在Accounts.validateLoginAttempt中看到,有一個'allowed'回調函數返回true或false。首先,你能告訴我如何設置LoginWithEmail。我不明白當用戶點擊鏈接時目前的功能。 +1爲有問題的系統方法,謝謝Steffo – meteorBuzz 2014-12-02 17:12:10
重新編輯答案。當用戶點擊驗證鏈接(看起來這個http:// localhost:3000 /#/ verify-email/lots-of-funny-chars)時,會創建'login'模板並且'Accounts.verifyEmail'抓住有趣的-chars並驗證它們(流星注意到這一點)。 – Steffo 2014-12-02 18:54:42
感謝您的意見。我會應用這段代碼,並讓你知道我很快會如何投票並相應投票。 – meteorBuzz 2014-12-03 09:54:01