1
votes

I am working on the enrollment piece of my application. After creating a new user on the server-side, I call the Accounts.sendEnrollmentEmail(). I get the email with a link like:

http://localhost:3000/enroll-account/XqMb6mqZQ3cGfyOgQgtWvLPqzVJ-qJeBYJ_I46mNE9c

And have created a route in Iron Router to handle it and display a "Choose Password" form like so:

route:

...
this.route('enrollAccount', {
    path: '/enroll-account/:token',
    data: function() { return this.params.token; }
});
...

Enrollment Template:

<template name="enrollAccount">
    <div class="panel panel-default">
        <div class="panel-body">
            <p>Please enter a password and click 'Enroll Account'</p>
            <div class="form-control">
                <label for="password">Enter Password</label>
                <input type="password" id="password" name="password" />
            </div>
            <div class="form-control">
                <label for="reenterPassword">Re-enter Password</label>
                <input type="password" id="reenterPassword" name="reenterPassword" />
            </div>
            <button class="btn btn-primary" id="btnEnroll">Enroll Account</button>
        </div>
    </div>
</template>

And the JS:

Template.enrollAccount.events({
    'click #btnEnroll': function(event, tmpl) {
        event.preventDefault();
        console.log('Enrolling with token ', this);
        Accounts.resetPassword(this, tmpl.$('#password').val(), function(err) {
            if (err) {
                // TODO Toss some error
                console.log('Error: ', err);
            } else {
                console.log('Enrollment successful, going home...');
                Router.go('home');
            }
        });
    }
});

When I enter the enrollment URL I get the form just fine, fill it out, click the button and get the console.log saying it's sending. I have also verified that the token matches what is in the DB. However, the call to Accounts.resetPassword() never performs the callback function. There is neither an error nor the else log in the browser console. Selecting the user in MongoDB shows there is still no password set and it still has a services->password->reset with the same token. I am sure I am missing a step, but I don't know what.

1

1 Answers

2
votes

It appears that the object passed into the Template by Iron Router is not really a String. When I printed it out, it looked like a String, but if I call the reset like this:

Accounts.resetPassword(this.toString(), tmpl.$('#password').val(), function(err)...

It then works as expected.