Hello,

I am using LoginToboggan and would like to trigger a Rule based on account validation. Would someone in the community be able to help make this Rules Event "User has validated their account (LoginToboggan)"?

I found a post where the maintainer said "you can look for the object property $account->logintoboggan_email_validated = TRUE in the the $account object during the 'update' op of hook_user() to determine if the account has just been validated by LT"

Flow I want to achieve:
1) User clicks validation link in the email (LoginToboggan)
2) Event triggers a Rule (this project)
3) Rule has Action: Send privatemsg To: "User who validated" From: "Admin"

Please let me know if more information is needed.
Thank you!

Comments

1sp’s picture

Hi trupal218,

I recently did a similar task with rules module(drupal6 version). Here is how I created the rule:
1. Use event "User account details have been updated".
2. create a condition "custom php code" to check whether current url is in the form of "user/validate".
3. create a condition "custom php code" to check that acting user is the one who's account is being validated.
4. create a condition "custom php code" to check if there was an transition from false to true in "logintoboggan_email_validated" property of user account object.

Now I attached a suitable action to the rule.

The exported rule (without action) is:

array (
  'rules' => 
  array (
    'rules_9' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_update',
      '#label' => 'when going through logintoboggan validation',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
        0 => 'logintoboggan',
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'label' => 'check whether url is "user/validate"',
            'label callback' => false,
            'module' => 'PHP',
            'eval input' => 
            array (
              0 => 'code',
            ),
          ),
          '#name' => 'rules_condition_custom_php',
          '#settings' => 
          array (
            'code' => 'if(arg(0) == \'user\' && arg(1) == \'validate\'){
return true;
}else{
return false;
}',
            'vars' => 
            array (
            ),
          ),
          '#type' => 'condition',
        ),
        1 => 
        array (
          '#info' => 
          array (
            'label' => 'check that acting user is the one who\'s account is being validated',
            'label callback' => false,
            'arguments' => 
            array (
              'number1' => 
              array (
                'label' => 'Number 1',
                'type' => 'number',
              ),
              'number2' => 
              array (
                'label' => 'Number 2',
                'type' => 'number',
              ),
            ),
            'module' => 'Rules',
          ),
          '#name' => 'rules_condition_number_compare',
          '#settings' => 
          array (
            'number1' => '<?php arg(2); ?>',
            'number2' => '<?php echo $account->uid; ?>',
            'operation' => 'equal',
            '#eval input' => 
            array (
              'rules_input_evaluator_php' => 
              array (
                'number1' => 
                array (
                ),
                'number2' => 
                array (
                  0 => 'account',
                ),
              ),
            ),
          ),
          '#type' => 'condition',
          '#weight' => 0,
        ),
        2 => 
        array (
          '#weight' => 0,
          '#type' => 'condition',
          '#settings' => 
          array (
            'code' => 'if(!$account_unchanged->logintoboggan_email_validated && $account->logintoboggan_email_validated){
return true;
}else{
return false;
}',
            'vars' => 
            array (
              0 => 'account',
              1 => 'account_unchanged',
            ),
          ),
          '#name' => 'rules_condition_custom_php',
          '#info' => 
          array (
            'label' => 'check if there was an transition from false to true in "logintoboggan_email_validated" property in account abject',
            'label callback' => false,
            'module' => 'PHP',
            'eval input' => 
            array (
              0 => 'code',
            ),
          ),
        ),
      ),
      '#actions' => 
      array (
      ),
      '#version' => 6003,
    ),
  ),
)

Cheers!!

Bilmar’s picture

wow! thanks so much skporwal
gotta love the drupal community! =)

Bilmar’s picture

I imported the rule and tested it with rule debug on, but it seems like "User account details have been updated" is not triggered when a user clicks the validation link and is logged into their account. I am going to continue to troubleshoot and will post back if I can figure it out. Any pointers from the community will be appreciated! =)

1sp’s picture

Sorry for late reply. I just noticed the rules event "User account is updated" fires on "after_update" action and not on "update" action, so the exported rule won't work. Sincere apologies for the initial wrong solution.

For this, as rightly stated by last commenter , a small module will suffice which create an rules event and fires it on 'update' operation of hook_user.

you can download a working module which does this from here http://logintoboggan-rules.googlecode.com/files/logintoboggan_rules-6.x....
Please find full configuration instructions inside the readme.txt present in the tarball.

Cheers,
Sudhir

Bilmar’s picture

hello Sudhir,

Awesome work on the custom module! I will be testing it tonight when I get home.

In the README file it says: "3. For best results , uncheck the "Immediate login" option..."

I was wondering what this means? Does the option disrupt the custom module from working?

I currently have Immediate login enabled for my site. Users can still browse the site under the 'non-authenticated' role but a message shows at the top for them to validate for more access. When the user validates via the email link then i have a Privatemsg message sent to the user Welcoming them to the site and all the features they have access to now.

Thanks again!

Regards

1sp’s picture

No, this module just need the "Set Password" option to be set in logintoboggan settings.

You can safely ignore the "Immediate login" option because it doesn't have any effect if "Set Password" option is set.

Thanks for trying, Have a good day :)

Sudhir

Bilmar’s picture

Great! Thanks for the confirmation. I look forward to testing it and will report back if any issues.

Bilmar’s picture

Tested the module just now - works great! Thanks for the hard work Sudhir
I would suggest making a project page "LoginToboggan Rules Integration" to document this module for the benefit of the community

Regards

Bilmar’s picture

Still not able to get this working correctly.
Any help would be appreciated! =)
Thanks

robby.smith’s picture

I am looking for the same User has been validated Rule and was wondering if anyone can assist. Thanks!

GSMKer_Kevin’s picture

Did the above solution by skporwal work or is this still needed?

Bilmar’s picture

Hello,

No it did not work. Robby and I are still continuing to try to get this to work =/

GSMKer_Kevin’s picture

Hello trupal218,

I have it working. I created a module that adds a new event. This event is triggered when user uses the validation link via LoginToboggan. I just have a few loose ends to tie up.

It looks like to me the above solution doesn't work do to the fact that the event only fires when actually updating an account. The event is incorrect for what you want.

GSMKer_Kevin’s picture

Great job skporwal on the module. I guess mine wont be needed.

I do disagree on the "Immediate login" option. If this option is set then the user is automatically logged in and using the validation URL is invalid.

Update: Looks like the validation URL still works and LoginToboggan event will still fire.

Bilmar’s picture

Hello,

I came across one issue and hoping someone can help.

If a new user (who has not validated yet) receives a one-time login link in an email via Forgot Password page, this link acts as the validation link and the non-authenticated role set by LoginToboggan is successfully removed from the user. However, the issue is that the 'User has validated' event is not triggered by this action.

Is there anyway to trigger this LoginToboggan event for if the link sent by the Forgot Password page is used to not only log in the user but also used to validate the user?

I would really appreciate your help.

Thank you