Meteor: resetPassword email link behavior

谁说我不能喝 提交于 2019-12-25 05:43:16

问题


I'm trying to implement the "reset password" functionality in my Meteor app. I have a very simple implementation of it based on this tutorial: Julien's tutorial on gentlenode

There are several examples floating around that use this same basic approach. I did mine almost exactly like Julien's but I used only one template; I use an {{#if}} in my template that displays the 'reset password' form, if my session variable sResetPassword is not falsey. (I don't know how the correct template is supposed to get displayed in Julien's example and it doesn't work for me as it is written -- the template doesn't change.)

Here's the critical piece of code. Two different methods that both work on my local app, but neither one works on my hosted (modulus) app.

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

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

On my deployed version (Modulus), the link opens up my app and just goes straight to the start screen. When I check the value of my sResetPassword session var, it's undefined, so somehow the value of the token never gets put into the var.

While we're on the subject, does anyone know how you are supposed to get the correct template to load when you use a separate template for the reset password form?


回答1:


Here is how it works for us. Code:

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:

<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>




回答2:


OK, for whatever reason, replacing iron-router with flow-router fixed this issue for me. I created a new app with only the login and reset password functionality and it worked fine. I added iron-router and again it worked, but only dev mode. When I ran it in production mode, the problem returned. Replaced iron-router with flow-router (in both the test app and my full app) and now the problem is gone. The email link works as expected in both modes.



来源:https://stackoverflow.com/questions/32511241/meteor-resetpassword-email-link-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!