You are here

function _bakery_check_account in Bakery Single Sign-On System 7.3

Check for a different account with same name, email or Bakery init field.

Parameters

int $uid UID of current account.:

array $data Array of properties to find account on.:

Return value

bool TRUE if another account with same name, email, or init field.

1 call to _bakery_check_account()
_bakery_handle_sso in ./bakery.module
Authenticate from valid SSO cookie.

File

./bakery.module, line 796

Code

function _bakery_check_account($uid, $data) {
  $checks = TRUE;
  $mail_count = db_select('users', 'u')
    ->fields('u', array(
    'uid',
  ))
    ->condition('uid', $uid, '!=')
    ->condition('mail', '', '!=')
    ->where('LOWER(mail) = LOWER(:mail)', array(
    ':mail' => $data['mail'],
  ))
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($mail_count > 0) {
    $checks = FALSE;
  }
  $name_count = db_select('users', 'u')
    ->fields('u', array(
    'uid',
  ))
    ->condition('uid', $uid, '!=')
    ->where('LOWER(name) = LOWER(:name)', array(
    ':name' => $data['name'],
  ))
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($name_count > 0) {
    $checks = FALSE;
  }
  $init_count = db_select('users', 'u')
    ->fields('u', array(
    'uid',
  ))
    ->condition('uid', $uid, '!=')
    ->condition('init', $data['init'], '=')
    ->where('LOWER(name) = LOWER(:name)', array(
    ':name' => $data['name'],
  ))
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($init_count > 0) {
    $checks = FALSE;
  }
  return $checks;
}