Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use a case insensitive search for email
Fixes #7084
Now entering wrongly cased email (roeland@ instead of Roeland@) for
password reset etc. Will also work.

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Dec 20, 2018
commit 03fe2b3b812e68765b5df6cb27e7f352ebbc2f87
32 changes: 32 additions & 0 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,38 @@ public function getUsersForUserValue($appName, $key, $value) {
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_map to the rescue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I just copy pasted

while ($row = $result->fetch()) {
$userIDs[] = $row['userid'];
}

return $userIDs;
}

public function getSystemConfig() {
return $this->systemConfig;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ private function getSeenUserIds($limit = null, $offset = null) {
* @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);
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

namespace Test\User;
use OC\AllConfig;
use OC\User\Database;
use OC\User\Manager;
use OCP\IConfig;
Expand Down Expand Up @@ -670,12 +671,12 @@ public function testDeleteUser() {
}

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', '[email protected]')
->will($this->returnValue(['uid1', 'uid99', 'uid2']));

Expand Down