1

With Drupal and Civi latest, is it possible to send an email with a one-time login url?

We have a scenario in which an admin grants a membership to a new contact. We want this new contact to automatically be given a new user account, and the correct role for their membership, and then send them an email giving them details about their new membership, as well as how to access their membership materials. (Their membership materials are on Drupal pages that are only visible to that membership's role).

So far we've succeeded in all of the above, using Drupal Rules.

However, to make their life easier I'd like to send them a one-time login so they can quickly make a password and get on with their life!

I'd prefer not to use the Drupal 'New Account' email for this purpose, since that has to be the same for all possible new users of the site. Also, we looked into not creating a user for them, and just sending them to the Drupal new user registration page. But that's clunky and these users are not internet savvy; they get lost.

In Drupal rules' 'Send HTML Email' action there is a token for the one-time user login: civicrm-user:one-time-login-url. However, it's not populated. And inspecting $civicrm_user via php print_r in the email shows no sign of this variable.

I did wonder if CiviRules could do all of the above, but I can't see any way to make a user from it, nor any token for a one-time user login - quite naturally since this would be a Drupal thing.

So... any ideas about how to progress this? I'm grateful for your thoughts.

1 Answer 1

2

The good news is that it is possible to send an email with a one-time login URL using rules.

There is an issue on the rules module for exactly this ability: problem with mail and one-time-login-url. A patch has been created for this issue that generates a new action in rules to generate a one-time login URL variable which you can then use to insert into an email. I updated the latest version of the patch to work with the most recent dev version of rules.

You will need to access the Drupal user account details in the rule in order to generate the login.

1
  • Thanks @Ben, this is super helpful! I hadn't found that patch, and this will help us greatly now. As it turned out, we sidestepped the problem just this once by auto-generating a password for the user in Rules and then emailing it to them along with their username. No where near as secure as the one-time-login but for this purpose quite suitable. To generate the password we used: drupal.stackexchange.com/a/120661/30379
    – Andyg8
    Jun 5, 2019 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.