Hello,
I have created a rule: when an anonymous user leaves a comment, it:
- creates a new user with name and email address from poster of the comment
- unblock this user account (dunno why it is blocked by default)
- sends an email with the login one time link for the user to activate the account.

Eveything works fine (user created, unblocked, email sent with link), but the page opened by the link is always "access denied".
I have tried deleting the cookies, cache, etc. + tried changing the combination on "/admin/config/people/accounts" for users registration rights.
=> but I still have an "access denied" page all the time.

However, when I send the login one time link simply by clicking on the button from the user page, the link works ok.

What am I missing here ? Is it something related to the user role ?

Comments

danielb’s picture

Can you compare the links being sent (good link and bad link) in the emails and/or show me what they are?
Are you configuring a custom path to send them to, etc.. ?

Louis Bob’s picture

Thanks for your prompt reply.

Link sent via Rules:
http://www.mydomain.com/login_one_time//1334048890/Yeec0-Y5Vcpq_7II-pJRX...

Link sent via the Login One Time button:
http://www.mydomain.com/login_one_time/97/1334049016/ZQNxQ7RKBuvYV4VfTdS...

vA?destination=user/97

So it seems that the user ID (97 here) is missing in the Rules link, that should instead read:
http://www.mydomain.com/login_one_time/97/1334048890/Yeec0-Y5Vcpq_7II-pJRXSjprWkbZrlbrlvbtVUWv6Y?destination=comment/reply/2

Also I have these error messages when the rule is applied, which would explain why the user ID is missing. However, the user is correctly created before the email is sent, so I don't understand the problem.

Notice : Undefined property: stdClass::$uid dans login_one_time_get_link() (ligne 529 dans /var/www/clients/client0/web3/web/sites/all/modules/login_one_time/login_one_time.module).
Notice : Undefined property: stdClass::$pass dans login_one_time_get_link() (ligne 530 dans /var/www/clients/client0/web3/web/sites/all/modules/login_one_time/login_one_time.module).
Notice : Undefined property: stdClass::$login dans login_one_time_get_link() (ligne 530 dans /var/www/clients/client0/web3/web/sites/all/modules/login_one_time/login_one_time.module).

Anyway I have manually added the user ID to the Rules link, and no more "access denied", but this message instead:

You have tried to use a one-time login link which has been used. Please use the log in form to supply your username and password.

I am a bit confused here...

danielb’s picture

At this point I'm confused because I don't remember such functionality (sending the email link through Rules) being provided by this module, and I don't see how that is allowed for in the code.
I am not a user of the Rules module so there might be some information I don't have about where it gets it's data/integration from.

Louis Bob’s picture

Status: Active » Closed (works as designed)

Well a variable from your module is available in Rules, therefore it can be sent via email.

Thanks for your responses, I have opened a support request in the Rules issues, since it seems more directly related:
http://drupal.org/node/1528492

rachelf’s picture

Hi there

I have had a similar problem, and it is rules related. The user id is missing because the new user entity that rules has created is not saved until the end of the rules evaluation.

I have successfully used this by first saving the user that I have just created (until this point the user id is unassigned).

My sequence of actions goes:
Create a new entity (the new user)
Save entity (force saving immediately)
Add user role
Unblock user
Execute custom PHP code:

<?php $account = user_load($entity_created->uid);
$path = 'user/'.$entity_created->uid.'edit'
login_one_time_send_mail($account, $path)
?>

Hope this helps!

Louis Bob’s picture

Hello Rachelf,

You're a life savior: it works perfectly :)
Thanks a lot!

Rosamunda’s picture

Thanks rachelf! Your insight solved my problem too!
BIG THANKS!