]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use a case insensitive search for email 13180/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Thu, 20 Dec 2018 10:09:10 +0000 (11:09 +0100)
committerBackportbot <backportbot-noreply@rullzer.com>
Thu, 20 Dec 2018 15:19:28 +0000 (15:19 +0000)
Fixes #7084
Now entering wrongly cased email (roeland@ instead of Roeland@) for
password reset etc. Will also work.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/private/AllConfig.php
lib/private/User/Manager.php
tests/lib/User/ManagerTest.php

index 58706e290fb9ba8be8e5c63f96d56c330818fe88..09520aae2a9dc66f738b7626e8269ab4f38f14bb 100644 (file)
@@ -459,6 +459,38 @@ class AllConfig implements \OCP\IConfig {
                return $userIDs;
        }
 
+       /**
+        * Determines the users that have the given value set for a specific app-key-pair
+        *
+        * @param string $appName the app to get the user for
+        * @param string $key the key to get the user for
+        * @param string $value the value to get the user for
+        * @return array of user IDs
+        */
+       public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
+               // TODO - FIXME
+               $this->fixDIInit();
+
+               $sql  = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
+                       'WHERE `appid` = ? AND `configkey` = ? ';
+
+               if($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
+                       //oracle hack: need to explicitly cast CLOB to CHAR for comparison
+                       $sql .= 'AND LOWER(to_char(`configvalue`)) = LOWER(?)';
+               } else {
+                       $sql .= 'AND LOWER(`configvalue`) = LOWER(?)';
+               }
+
+               $result = $this->connection->executeQuery($sql, array($appName, $key, $value));
+
+               $userIDs = array();
+               while ($row = $result->fetch()) {
+                       $userIDs[] = $row['userid'];
+               }
+
+               return $userIDs;
+       }
+
        public function getSystemConfig() {
                return $this->systemConfig;
        }
index 80f504d8888a978353ead7873e4a9d80e420acdd..3d8cc34b859471edb08bea788293143f4a00d32b 100644 (file)
@@ -589,7 +589,7 @@ class Manager extends PublicEmitter implements IUserManager {
         * @since 9.1.0
         */
        public function getByEmail($email) {
-               $userIds = $this->config->getUsersForUserValue('settings', 'email', $email);
+               $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email);
 
                $users = array_map(function($uid) {
                        return $this->get($uid);
index e0b6aadf2ac17015b7bcc74fab9f21156513662f..284f7b173bc29dc696d4f6ee4186183dbf6b00af 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 namespace Test\User;
+use OC\AllConfig;
 use OC\User\Database;
 use OC\User\Manager;
 use OCP\IConfig;
@@ -670,12 +671,12 @@ class ManagerTest extends TestCase {
        }
 
        public function testGetByEmail() {
-               $config = $this->getMockBuilder(IConfig::class)
+               $config = $this->getMockBuilder(AllConfig::class)
                        ->disableOriginalConstructor()
                        ->getMock();
                $config
                        ->expects($this->at(0))
-                       ->method('getUsersForUserValue')
+                       ->method('getUsersForUserValueCaseInsensitive')
                        ->with('settings', 'email', 'test@example.com')
                        ->will($this->returnValue(['uid1', 'uid99', 'uid2']));