流星:重置密码电子邮件 link 行为

Meteor: resetPassword email link behavior

我正在尝试在我的 Meteor 应用程序中实现 "reset password" 功能。我有一个基于本教程的非常简单的实现:Julien's tutorial on gentlenode

周围有几个使用相同基本方法的示例。我做的几乎和 Julien 的一模一样,但我只使用了一个模板;如果我的会话变量 sResetPassword 不是假的,我在显示 'reset password' 表单的模板中使用 {{#if}}。 (我不知道正确的模板应该如何显示在 Julien 的示例中,而且它对我来说不起作用——模板没有改变。)

这是关键代码段。两种不同的方法都适用于我的本地应用程序,但都不适用于我的托管(模数)应用程序。

/* method one
if (Accounts._resetPasswordToken) {
  Session.set('sResetPassword', Accounts._resetPasswordToken);
}

/* method two
Accounts.onResetPasswordLink( function(token) { 
    Session.set('sResetPassword', token);  
});

在我部署的版本 (Modulus) 上,link 打开我的应用程序并直接进入开始屏幕。当我检查我的 sResetPassword 会话变量的值时,它是未定义的,因此令牌的值永远不会以某种方式放入变量中。

当我们讨论这个主题时,有谁知道当您为重置密码表单使用单独的模板时应该如何加载正确的模板?

以下是我们的运作方式。代码:

var token, done;

Accounts.onResetPasswordLink(function (t, d)
{
    token = t;
    done = d;
    setTimeout(()=>Router.go("reset_password"), 0);
});

Template["reset_password"].events({
    "click #resetBtn": function (event:Event, instance:Blaze.TemplateInstance)
    {
        var password1: string = instance.$("#input_password1").val();
        var password2: string = instance.$("#input_password2").val();
        console.log(password1, password2);
        if (password1 != password2)
        {
            return;
        }

        Accounts.resetPassword(token, password1, ()=>
        {
            done();
            Router.go("somewhere");
        });


    }
});

模板:

<template name="reset_password">
<form data-parsley-validate>
    <div class="input-field">
        <input id="input_password1" type="password" class="validate" data-parsley-trigger="keyup" data-parsley-minlength="6" data-parsley-minlength-message = "Please provide a password that is at least a 6 characters long." required>
        <label for="input_password1">New Password</label>
    </div>
    <div class="input-field">
        <input id="input_password2" type="password" class="validate" data-parsley-trigger="keyup" data-parsley-minlength="6" data-parsley-minlength-message = "Please provide a password that is at least a 6 characters long." required>
        <label for="input_password2">Again</label>
    </div>
    <button id="resetBtn" class="waves-effect btn">Reset Password</button>
</form>

好的,无论出于何种原因,用 flow-router 替换 iron-router 为我解决了这个问题。我创建了一个只有登录和重置密码功能的新应用程序,它运行良好。我添加了 iron-router 并且它再次工作,但只有开发模式。当我 运行 它处于生产模式时,问题又来了。将 iron-router 替换为 flow-router(在测试应用程序和我的完整应用程序中),现在问题消失了。电子邮件 link 在两种模式下都按预期工作。