4
votes

In my application I want to seed the database with users and send them an enrollment link to activate their account (and choose a password). I also want them to verify/change some profile data.

On the server I seed the database like this:

Meteor.startup(function () {
  if(Meteor.users.find().count() === 0) {
    var user_id = Accounts.createUser({ email: '[email protected]', profile: { some: 'profile' } });
    Accounts.sendEnrollmentEmail(user_id);
  }
})

The enrollment link is sent as expected, but I want to create a custom template for when the url in the email is clicked. Preferably handled by iron-router. (Not using the accounts-ui package).

I tried things like redirecting the user to a custom route like this:

var doneCallback, token;

Accounts.onEnrollmentLink(function (token, done) {
  doneCallback = done;
  token = token;
  Router.go('MemberEnroll')
});

which is not working (it changes the url but not rendering my template)

I also tried to change the enroll URL on the server like this:

Accounts.urls.enrollAccount = function (token) {
  return Meteor.absoluteUrl('members/enroll/' + token);
};

But when I do this, the Accounts.onEnrollmentLink callback does not fire. Also, changing the URL is not documented so I'm not sure its a good practice at all.

Any help is appreciated.

2

2 Answers

13
votes

In my application I'm doing like this

        this.route('enroll', {
            path: '/enroll-account/:token',
            template: 'enroll_page',
            onBeforeAction: function() {
                Meteor.logout();
                Session.set('_resetPasswordToken', this.params.token);
                this.subscribe('enrolledUser', this.params.token).wait();
            },
            data: function() {
                if(this.ready()){
                    return {
                        enrolledUser: Meteor.users.findOne()
                    }
                }
            }
       })

As enrollment url is like this

http://www.yoursite.com/enroll-account/hkhk32434kh42hjkhk43

when users click on the link they will redirect to this template and you can render your template

In my publication

Meteor.publish('enrolledUser', function(token) {
    return Meteor.users.find({"services.password.reset.token": token});
});

After taking the password from the user

Accounts.resetPassword(token, creds.password,function(e,r){
  if(e){
    alert("Sorry we could not reset your password. Please try again.");
  }else{
    alert("Logged In");
    Router.go('/');
   }
 })

enroll link

Accounts.urls.enrollAccount = function (token) {
  return Meteor.absoluteUrl('enroll-account/' + token);
};
0
votes

Im afraid now isnt possible, what i did is changing the html and css using "rendered" function but it has some probs with delay

Meteor.startup(function(){
    Template["_enrollAccountDialog"].rendered = function(){
        document.getElementById('enroll-account-password-label').innerHTML = 'Escolha sua senha';
        $('.accounts-dialog').css('background-color','#f4f5f5');
        $('.accounts-dialog').css('text-align','center');
        $('.accounts-dialog').removeAttr('width');
        document.getElementById('login-buttons-enroll-account-button').className = ' create-account-button'; 
        document.getElementById('login-buttons-enroll-account-button').innerHTML = 'Criar conta';
    }
});