Hello,

The below code is to trigger some code when LoginToboggan's validation event occurs.
It looks to update the user account but Rules does not pick up the validation process where a role is updated in the user account.
Can anyone assist in figuring out why Rules "User details have been updated" does not get triggered?

#628334: Assign role on account confirmation

<?php
function my_module_name_user($op, $edit, &$account, $category = NULL) {
  switch($op){
    case 'update':
      if($account->logintoboggan_email_validated)
        //What happens when LT's _logintoboggan_process_validation() is finished
        break;
  }
}
?>

I am trying to create a rule that will be triggered by the event of the validation to set action to Send a privatemsg to the user.
I would really appreciate your help!

Comments

robby.smith’s picture

Component: Rules Core » Rules Engine

The maintainer of LoginToboggan says:

this section of code is called any time LT processes a login. it should give you the flag you're looking to leverage:

<?php
  // Allow other modules to react to email validation by invoking the user update hook.
  // This should only be triggered if LT's custom validation is active.
  if (!variable_get('user_email_verification', TRUE)) {
    $edit = array();
    $account->logintoboggan_email_validated = TRUE;
    user_module_invoke('update', $edit, $account);
  }
?>

The maintainer says it's a standard invocation of the user update hook. rules should support that.
Can anyone help me understand how to make rules trigger an event for this?

robby.smith’s picture

Below is the complete function:

function _logintoboggan_process_validation($account) {
  // Test here for a valid pre-auth -- if the pre-auth is set to the auth user, we
  // handle things a bit differently.
  $validating_id = logintoboggan_validating_id();
  $pre_auth = !variable_get('user_email_verification', TRUE) && $validating_id != DRUPAL_AUTHENTICATED_RID;

  // Remove the pre-auth role from the user, unless they haven't been approved yet.
  if ($account->status) {
    if ($pre_auth) {
      db_query("DELETE FROM {users_roles} WHERE uid = %d AND rid = %d", $account->uid, $validating_id);
      // Since we're passing $account around to the update hook, remove
      // the pre-auth role from the roles array, and add in the auth user
      // role.
      $account->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
      unset($account->roles[$validating_id]);
    }
  }
  // Allow other modules to react to email validation by invoking the user update hook.
  // This should only be triggered if LT's custom validation is active.
  if (!variable_get('user_email_verification', TRUE)) {
    $edit = array();
    $account->logintoboggan_email_validated = TRUE;
    user_module_invoke('update', $edit, $account);
  }
}
robby.smith’s picture

Status: Active » Closed (fixed)

my mistake, this rule only looked at AFTER the account details of updated
custom module with rules event at #678684: Rules Integration