Javascript Meteor:Accounts.sendVerificationEmail自定义行为
有人能提供正确的方法在用户创建时发送电子邮件验证吗?这是最重要的部分 a)我希望用户在注册后能够立即访问。但是如果用户在48小时内还没有点击验证链接,我想拒绝他们登录,直到他们点击了链接 到目前为止,我的代码发送了一封电子邮件验证,但是用户可以通过或不通过单击验证链接继续访问应用程序(因此我的代码当然是不完整的) client.jsJavascript Meteor:Accounts.sendVerificationEmail自定义行为,javascript,meteor,email-verification,meteor-accounts,Javascript,Meteor,Email Verification,Meteor Accounts,有人能提供正确的方法在用户创建时发送电子邮件验证吗?这是最重要的部分 a)我希望用户在注册后能够立即访问。但是如果用户在48小时内还没有点击验证链接,我想拒绝他们登录,直到他们点击了链接 到目前为止,我的代码发送了一封电子邮件验证,但是用户可以通过或不通过单击验证链接继续访问应用程序(因此我的代码当然是不完整的) client.js Template.join.events({ 'submit #join-form': function(e,t){ e.preventDefault();
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 = "no-reply@mydomain.com";
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
});
我的尝试是通过自己阅读meteor文档并查看其他代码来完成的。我被困住了。谢谢你的支持 我认为最基本的想法是在
帐户中设置一些验证代码。validateLogInAttract
每次用户登录前都要检查这些代码。您可以做的是存储用户在user.profile.joinDate
中注册的日期和时间。如果用户尝试登录
- 检查电子邮件地址是否已被验证或删除
- 检查用户是否在48小时的宽限期内登录
<body>
{{ > start }}
</body>
<template name="start">
{{#if currentUser}}{{>showUserProfile}}{{else}}{{> login}}{{/if}}
</template>
<template name="login">
## Grab username/password here
</template>
验证链接在“hook”中发送到帐户。createUser
:
Accounts.onCreateUser(function(options, user) {
user.profile = {};
Meteor.setTimeout(function() {
Accounts.sendVerificationEmail(user._id);
}, 2 * 3000);
return user;
});
公平地说,48小时宽限期不必如此严格。只要在某个时刻对用户的电子邮件地址进行验证。我看到Accounts.validateLogInTest有一个“允许的”回调函数,它返回true或false。首先,你能告诉我如何使用电子邮件设置登录吗。我不明白当用户点击链接时它现在做什么+1对于问题的系统方法,感谢SteffoRe编辑了答案。当用户单击验证链接(如下所示)时,将创建
登录
模板并帐户。verifyEmail
抓取有趣的字符并验证它们(Meteor对此负责)。感谢您的输入。我将应用此代码,并让您知道我的进展情况,并进行相应的投票。这很有帮助。我仍在试图解构正在发生的事情。我想做的是回到过去简化一下。你能告诉我一个干净的方式发送电子邮件验证链接给用户。就这些了,好吗?
<body>
{{ > start }}
</body>
<template name="start">
{{#if currentUser}}{{>showUserProfile}}{{else}}{{> login}}{{/if}}
</template>
<template name="login">
## Grab username/password here
</template>
Template.login.created = function() {
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message = 'Verify email link expired [403]') {
var message ='Sorry this verification link has expired.';
console.log(message);
alertBox = Blaze.renderWithData(Template.Alert, {message: message}, $("body").get(0));
}
} else {
var message = "Thank you! Your email address has been confirmed.";
console.log(message);
alertBox = Blaze.renderWithData(Template.Alert, {message: message}, $("body").get(0));
}
});
}
};
Accounts.onCreateUser(function(options, user) {
user.profile = {};
Meteor.setTimeout(function() {
Accounts.sendVerificationEmail(user._id);
}, 2 * 3000);
return user;
});