javascript - Meteor 账户 邮箱验证

标签 javascript meteor reactjs

如何使用自定义消息和自定义 from 参数而不是默认参数向用户发送电子邮件验证。

Meteor.methods({
    sendveryficationmail: function (theuserId, themail) {
        this.unblock();
        Accounts.sendVerificationEmail(theuserId);
    }
});

当我使用该方法时,我会收到默认的 meteor 验证电子邮件。如何更改参数以及应该从哪里更改它们?

最佳答案

您可以创建自己的函数来使用模板发送自定义 HTML,您可以将事件传递给简单的 HTML 而不是模板文件。这是代码:

'sendVerificationEmail':function (emailId) {
        Meteor.users.update({'emails.address': emailId}, {$unset: {'services.email.verificationTokens': 1}});
        var user = Meteor.users.findOne({"emails.address": emailId});
        if (user) {
                if( user.emails.find(email=> email.address === emailId ).verified ){
                    throw new Meteor.Error("Email already verified");
                } else {
                    var userInfo = user.profile;
                    var emailId = user.email[0].address;
                    Accounts.emailTemplates.siteName = "NJAL";
                    Accounts.emailTemplates.from = "myTest <community@myTest.com>";
                    Accounts.emailTemplates.verifyEmail.subject = function(user) {
                        return "Account Verification Required";
                    };
                    Accounts.emailTemplates.verifyEmail.html = function (user, url) {
                         SSR.compileTemplate( 'registartionEmail', Assets.getText( 'email_templates/registration_confirm.html' ) );
                        var res=url.split("/");
                      var emailData = {
                            "designer_name": userInfo.fname + " "+ userInfo.lname,
                            "url": "http://domain.com/pages/verify/?token="+res[res.length-2]+"/"+res[res.length-1],
                            "emailId": emailId,
                        };
                        return SSR.render( 'registartionEmail', emailData );
                    };
                    Accounts.sendVerificationEmail(user._id, emailId);
                }
        } else {        
            throw new Meteor.Error("Email does not exist");
        }
  },

关于javascript - Meteor 账户 邮箱验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38746917/

相关文章:

javascript - 如何在 Reactjs 中使用 Javascript 代码?

javascript - pulltorefresh.js - 暂时禁用

javascript - 应用滚动条时如何对齐列内容

javascript - react : Render canvas at certain framerate

http - 从其 url 下载图像并直接上传到 AWS

javascript - meteor .js : lib folder not loaded first

reactjs - 通过放大存储 reactjs 在 S3 上上传时出错

javascript - 在 html5 视频中添加参数 (jQuery)

javascript - 多个父子作用域事件触发问题

javascript - 解构分配在 node_modules meteor 中不起作用