You are here

function simple_ldap_sso_validate_user in Simple LDAP 7

Same name and namespace in other branches
  1. 7.2 simple_ldap_sso/simple_ldap_sso.inc \simple_ldap_sso_validate_user()

Validate the user exists, and the data is valid.

1 call to simple_ldap_sso_validate_user()
simple_ldap_sso_get_cookie_data in simple_ldap_sso/simple_ldap_sso.inc
Read the SSO data from the cookie.

File

simple_ldap_sso/simple_ldap_sso.inc, line 199
Simple LDAP SSO API functions.

Code

function simple_ldap_sso_validate_user(array $data) {

  // Check to see if the user exists.
  $result = db_query("SELECT uid FROM {users} WHERE name = :name", array(
    ':name' => $data['name'],
  ));
  $uid = $result
    ->fetchField();

  // If we don't have a $uid, create the user.
  if (!$uid) {

    // We can't call user_save() in here, because it's too early in the
    // bootstrap. Instead, we'll just write the record to the user table
    // directly.
    require_once DRUPAL_ROOT . '/includes/common.inc';
    $account = new stdClass();
    $account->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')
      ->fetchField());
    $account->created = REQUEST_TIME;
    $account->name = $data['name'];
    $account->status = 1;
    drupal_write_record('users', $account);
    $uid = isset($account->uid) ? $account->uid : FALSE;

    // Always queue a sync from LDAP to Drupal if the user was just created.
    simple_ldap_sso_queue_user_sync();
  }
  return $uid ? $uid : FALSE;
}