0

We have an existing application with users and we would like to get our user base to accept the terms and conditions. In this regard I did some research and see that legal module comes the closest to desired functionality however there is one concern:

By default the legal module only shows up on login when a user has accepted terms and conditions on registration and only if the terms have changed. What we want to do is to get every user to see that upon login until they accept them.

I looked at the module code and see there is a hook_login function. No matter what I do, this function does not get called. I have tried to backtrace the login system and find out that certain modules do get their hook user login called but some do not. Legal module would be one of them. Any thoughts on how to trouble shoot this further?

The hook is as follows:

function legal_user_login(&$edit, $account) {
  echo "Legal module hook login called"; <--- never see this
  exit; <-- does not get called


  global $user;
  global $language;

  if ($user->uid == 1) {
    return;
  }

  // Get last accepted version for this account
  $legal_account = legal_get_accept($user->uid);

  // If no version has been accepted yet, get version with current language revision.
  if (empty($legal_account['version'])) {
    $conditions = legal_get_conditions($language->language);
    // No conditions set yet.
    if (empty($conditions['conditions'])) {
      return;
    }
  }
  // Get version / revision of last accepted language.
  else {
    $conditions = legal_get_conditions($legal_account['language']);
    // No conditions set yet.
    if (empty($conditions['conditions'])) {
      return;
    }

    // Check latest version of T&C has been accepted.
    $accepted = legal_version_check($user->uid, $conditions['version'], $conditions['revision'], $legal_account);

    if ($accepted) {
      return;
    }
  }

  $uid = $user->uid;

  // Log the user out and regenerate the Drupal session.
  module_invoke_all('user_logout', $user);
  drupal_session_regenerate();

  // We have to use $GLOBALS to unset a global variable.
  $user = drupal_anonymous_user();

  $query = NULL;

  // Deal with destination from password reset one time login link,
  // by creating a new one time login link and setting it as the destination
  // after the T&Cs have been accepted.
  if (arg(0) == 'user' && arg(1) == 'reset') {
    $token = drupal_hash_base64(drupal_random_bytes(55));
    // This is a new, anonymous-user session.
    $_SESSION['pass_reset_' . $uid] = $token;
    $query = array('destination' => "user/$uid/edit?pass-reset-token=$token");
  }

  if (!empty($_REQUEST['destination'])) {
    $query = array('destination' => $_REQUEST['destination']);
  }

  unset($_GET['destination']);

  $result    = db_select('users', 'u')
    ->fields('u')
    ->condition('uid', $uid)
    ->range(0, 1)
    ->execute()
    ->fetchAllAssoc('uid');
  $signatory = array_pop($result);

  drupal_goto('legal_accept/' . $signatory->uid . '/' . md5($signatory->name . $signatory->pass . $signatory->login), array('query' => $query));
}
  • Your module should be called legal and that hook implementation (the legal_user_login function) must be on the legal.module file, in the root directory of your module. Is this ok? – sanzante Feb 12 '16 at 21:04
  • yes I copied and pasted that function from legal module in the legal.module file. Also the module is enabled and I have cleared cache. – kratos Feb 12 '16 at 21:50
  • You copied and pasted from the legal module, but is your module also "legal"? So the file you put that into is legal.module? (Sorry, it's not clear by your response to @tunic – Chris Rockwell Feb 12 '16 at 22:58
2

Just add a (boolean) field to the user.

For new Drupal 7 site you can use:

Admin > Configuration > People > Account settings > Manage fields Another method is using Profile2 module, a successor of Content Profile Drupal 6 module If you have started with a minimal install profile you will need to enable the Field UI module to access Manage fields via the Account settings.

Then, in a custom module, invoke hook_user_load and there, check if it's set. If not redirect to a page where the user needs to accept the terms and this field get updated.

Or, have a look at EU cookie compliance, it does more or less what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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