From b67a6d82dfd5f3bf9cacf4d5c8ccafda79a802e1 Mon Sep 17 00:00:00 2001 From: Eileen Date: Thu, 17 Oct 2013 11:41:24 +1300 Subject: [PATCH] CRM-13598 d6 user validation, This commit leaves the PEAR method on authenticate 'untouched' as there 'may' be cases where the bootstrapping is not taking place - although I am not convinced any remain, this remains a gotcha for people with prefixed tables in d6 & d7 ---------------------------------------- * CRM-13598: User drupal {users} rather than storing name of drupal user table http://issues.civicrm.org/jira/browse/CRM-13598 --- CRM/Utils/System/Drupal6.php | 42 +++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index ad81d42f84..b544245b1d 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -170,29 +170,41 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } $sql = " -SELECT name, mail - FROM {users} - WHERE (LOWER(name) = LOWER('$name')) OR (LOWER(mail) = LOWER('$email'))"; + SELECT name, mail + FROM {users} + WHERE (LOWER(name) = LOWER('$name')) OR (LOWER(mail) = LOWER('$email')) + "; + $result = db_query($sql); + $rows = array(); - $db_cms = DB::connect($config->userFrameworkDSN); - if (DB::isError($db_cms)) { - die("Cannot connect to UF db via $dsn, " . $db_cms->getMessage()); + if (count($result) > 0) { + $rows[] = db_fetch_array($result); } - $query = $db_cms->query($sql); - $row = $query->fetchRow(); + if(empty($rows)) { + return; + } + $row = $rows[0]; + $user = NULL; + if (!empty($row)) { - $dbName = CRM_Utils_Array::value(0, $row); - $dbEmail = CRM_Utils_Array::value(1, $row); + $dbName = CRM_Utils_Array::value('name', $row); + $dbEmail = CRM_Utils_Array::value('mail', $row); if (strtolower($dbName) == strtolower($name)) { $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', array(1 => $name) ); } if (strtolower($dbEmail) == strtolower($email)) { - $resetUrl = $config->userFrameworkBaseURL . 'user/password'; - $errors[$emailName] = ts('The email address %1 is already registered. Have you forgotten your password?', - array(1 => $email, 2 => $resetUrl) - ); + if(empty($email)) { + $errors[$emailName] = ts('You cannot create an email account for a contact with no email', + array(1 => $email) + ); + } + else{ + $errors[$emailName] = ts('This email %1 is already registered. Please select another email.', + array(1 => $email) + ); + } } } } @@ -528,7 +540,7 @@ SELECT name, mail $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $dbpassword = md5($password); $name = $dbDrupal->escapeSimple($strtolower($name)); - $sql = "SELECT u.* FROM {users} u WHERE LOWER(u.name) = '$name' AND u.pass = '$dbpassword' AND u.status = 1"; + $sql = 'SELECT u.* FROM ' . $config->userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '$name' AND u.pass = '$dbpassword' AND u.status = 1"; $query = $dbDrupal->query($sql); $user = NULL; -- 2.25.1