Projet

Général

Profil

Révision dd54aff9

Ajouté par Assos Assos il y a plus de 10 ans

Weekly update of contrib modules

Voir les différences:

htmltest/sites/all/modules/ldap/ldap_authentication/ldap_authentication.inc
60 60
    if (isset($auth_conf->loginUIPasswordTxt)) {
61 61
      $form['pass']['#description'] = t($auth_conf->loginUIPasswordTxt);
62 62
    }
63
    if ($auth_conf->templateUsageRedirectOnLogin) {
64
      $form['#submit'][] = 'ldap_authentication_check_for_email_template';
65
    }
63 66
  }
64 67
}
65 68

  
......
115 118
  }
116 119
}
117 120

  
121
/**
122
 * Replaces the email address in $ldap_user with one from the template in
123
 * $auth_conf.
124
 * 
125
 * @param array $ldap_user
126
 *   LDAP user entry
127
 * @param LdapAuthenticationConf $auth_conf
128
 *   LDAP authentication configuration class.
129
 */
130
function _ldap_authentication_replace_user_email(&$ldap_user, $auth_conf, $tokens) {
131
  // fallback template in case one was not specified.
132
  $template = '@username@localhost';
133
  if (!empty($auth_conf->emailTemplate)) {
134
    $template = $auth_conf->emailTemplate;
135
  }
136
  $ldap_user['mail'] = format_string($template, $tokens);
137
}
118 138

  
119 139
/**
120 140
  * user form validation will take care of username, pwd fields
......
242 262
  }
243 263
  $watchdog_tokens['%drupal_accountname'] = $drupal_accountname;
244 264

  
265
  // @todo maybe we can add more tokens?
266
  $email_template_tokens = array(
267
    '@username' => $drupal_accountname,
268
  );
269
  
270
  $email_template_used = FALSE;
271
  
272
  /**
273
   * Ensures that we respect the email template handling settings.
274
   */
275
  if (!empty($auth_conf->emailTemplate)) {
276
    switch ($auth_conf->emailTemplateHandling) {
277
      case LDAP_AUTHENTICATION_EMAIL_TEMPLATE_IF_EMPTY:
278
        if (!empty($ldap_user['mail'])) {
279
          break;
280
        }
281
        // deliberate fallthrough
282
      case LDAP_AUTHENTICATION_EMAIL_TEMPLATE_ALWAYS:
283
        _ldap_authentication_replace_user_email($ldap_user, $auth_conf, $email_template_tokens);
284
        if ($detailed_watchdog_log) {
285
          watchdog('ldap_authentication', 'Using template generated email for %username', $watchdog_tokens, WATCHDOG_DEBUG);
286
        }
287
        $email_template_used = TRUE;
288
        break;
289
    }
290
  }
291
  
245 292
  /**
246 293
   * VI. Find or create corresponding drupal account and set authmaps
247 294
   *
......
307 354
   * VI.C: existing Drupal account with incorrect email.  fix email if appropriate
308 355
   *
309 356
   */
310
  if ($drupal_account_exists && $drupal_account->mail != $ldap_user['mail'] && (
311
          $auth_conf->emailUpdate == LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE_NOTIFY ||
312
          $auth_conf->emailUpdate == LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE
313
          ))  {
357
  if ((!($auth_conf->templateUsageNeverUpdate && $email_template_used)) && 
358
      $drupal_account_exists && 
359
      $drupal_account->mail != $ldap_user['mail'] && 
360
      (
361
        $auth_conf->emailUpdate == LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE_NOTIFY ||
362
        $auth_conf->emailUpdate == LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE
363
      )) {
314 364
    $user_edit = array('mail' => $ldap_user['mail']);
315 365

  
316 366
    $watchdog_tokens['%username'] = $drupal_account->name;
......
337 387

  
338 388
    // VI.C.1 Do not provision Drupal account if another account has same email.
339 389
    if ($account_with_same_email = user_load_by_mail($ldap_user['mail'])) {
390
      $error = TRUE;
340 391
      /**
341 392
       * username does not exist but email does.  Since user_external_login_register does not deal with
342 393
       * mail attribute and the email conflict error needs to be caught beforehand, need to throw error here
343 394
       */
344
      $watchdog_tokens['%duplicate_name'] = $account_with_same_email->name;
345
      watchdog('ldap_authentication', 'LDAP user with DN %dn has email address
346
        (%mail) conflict with a drupal user %duplicate_name', $watchdog_tokens, WATCHDOG_ERROR);
347
      drupal_set_message(t('Another user already exists in the system with the same email address. You should contact the system administrator in order to solve this conflict.'), 'error');
348
      return;
395
      if ($auth_conf->templateUsageResolveConflict && (!$email_template_used)) {
396
        if ($detailed_watchdog_log) {
397
          watchdog('ldap_authentication', 'Conflict detected, using template generated email for %username', $watchdog_tokens, WATCHDOG_DEBUG);
398
        }
399
        _ldap_authentication_replace_user_email($ldap_user, $auth_conf, $email_template_tokens);
400
        $email_template_used = TRUE;
401
        // recheck with the template email to make sure it doesn't also exist.
402
        if ($account_with_same_email = user_load_by_mail($ldap_user['mail'])) {
403
          $error = TRUE;
404
        }
405
      }
406
      if ($error) {
407
        $watchdog_tokens['%duplicate_name'] = $account_with_same_email->name;
408
        watchdog('ldap_authentication', 'LDAP user with DN %dn has email address
409
          (%mail) conflict with a drupal user %duplicate_name', $watchdog_tokens, WATCHDOG_ERROR);
410
        drupal_set_message(t('Another user already exists in the system with the same email address. You should contact the system administrator in order to solve this conflict.'), 'error');
411
        return;
412
      }
349 413
    }
350 414

  
351 415
    // VI.C.2 Do not provision Drupal account if provisioning disabled
......
384 448
    else {
385 449
      $user_edit = array('name' => $drupal_accountname, 'status' => 1);
386 450
    }
451
    
452
    // If the email template was used, we want to pass in the email that was
453
    // generated so that its not overridden by the provisioner.
454
    if ($email_template_used) {
455
      $user_edit['mail'] = $ldap_user['mail'];
456
    }
387 457

  
388 458
    // don't pass in ldap user to provisionDrupalAccount, because want to requery with correct attributes needed
389 459
    // this may be a case where efficiency dictates querying for all attributes
......
396 466
    }
397 467
    else {
398 468
      user_set_authmaps($drupal_account, array('authname_ldap_user' => $authname));
469
      // Using Rules allows emails to be fired and many other possible reactions
470
      // to the creation of a user.
471
      if (module_exists('rules')) {
472
        rules_invoke_event('ldap_user_created', $drupal_account, $email_template_used);
473
      }
399 474
    }
400 475
  }
401 476

  

Formats disponibles : Unified diff