From b10dcfc3b7e84c97d4dba4f7c63b4dff2fbc310b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 2 May 2016 14:19:10 +0200 Subject: [PATCH 1/2] Fixing local event delivery for calendar events based on the email address --- apps/dav/lib/connector/sabre/principal.php | 8 ++++++++ apps/dav/lib/server.php | 3 +++ apps/dav/tests/unit/connector/sabre/principal.php | 15 +++++++++++++++ lib/private/user/manager.php | 14 ++++++++++++++ lib/public/iusermanager.php | 7 +++++++ 5 files changed, 47 insertions(+) diff --git a/apps/dav/lib/connector/sabre/principal.php b/apps/dav/lib/connector/sabre/principal.php index 18f28a916f..787bcdf469 100644 --- a/apps/dav/lib/connector/sabre/principal.php +++ b/apps/dav/lib/connector/sabre/principal.php @@ -196,6 +196,14 @@ class Principal implements BackendInterface { * @return string */ function findByUri($uri, $principalPrefix) { + if (substr($uri, 0, 7) === 'mailto:') { + $email = substr($uri, 7); + $users = $this->userManager->getByEmail($email); + if (count($users) === 1) { + return $this->principalPrefix . '/' . $users[0]->getUID(); + } + } + return ''; } diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 73e24c9a29..edaa7ac855 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -84,6 +84,9 @@ class Server { // acl $acl = new DavAclPlugin(); + $acl->principalCollectionSet = [ + 'principals/users', 'principals/groups' + ]; $acl->defaultUsernamePath = 'principals/users'; $this->server->addPlugin($acl); diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php index 1747885240..75076e9618 100644 --- a/apps/dav/tests/unit/connector/sabre/principal.php +++ b/apps/dav/tests/unit/connector/sabre/principal.php @@ -255,4 +255,19 @@ class Principal extends TestCase { public function testSearchPrincipals() { $this->assertSame([], $this->connector->searchPrincipals('principals/users', [])); } + + public function testFindByUri() { + $fooUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $fooUser + ->expects($this->exactly(1)) + ->method('getUID') + ->will($this->returnValue('foo')); + + $this->userManager->expects($this->once())->method('getByEmail')->willReturn([ + $fooUser + ]); + $ret = $this->connector->findByUri('mailto:foo@bar.net', 'principals/users'); + $this->assertSame('principals/users/foo', $ret); + } } diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 4371be134a..37a3e5ba13 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -33,6 +33,7 @@ namespace OC\User; use OC\Hooks\PublicEmitter; +use OCP\IUser; use OCP\IUserBackend; use OCP\IUserManager; use OCP\IConfig; @@ -354,4 +355,17 @@ class Manager extends PublicEmitter implements IUserManager { } while (count($users) >= $limit); } } + + /** + * @param string $email + * @return IUser[] + * @since 9.1.0 + */ + public function getByEmail($email) { + $userIds = $this->config->getUsersForUserValue('settings', 'email', $email); + + return array_map(function($uid) { + return $this->get($uid); + }, $userIds); + } } diff --git a/lib/public/iusermanager.php b/lib/public/iusermanager.php index 6442938a99..00c0bbc872 100644 --- a/lib/public/iusermanager.php +++ b/lib/public/iusermanager.php @@ -142,4 +142,11 @@ interface IUserManager { * @since 9.0.0 */ public function callForAllUsers (\Closure $callback, $search = ''); + + /** + * @param string $email + * @return IUser[] + * @since 9.1.0 + */ + public function getByEmail($email); } From 7aca13f14c2974a5e3f78cff628209c3964aaf04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 2 May 2016 14:51:01 +0200 Subject: [PATCH 2/2] Allow login by email address --- core/templates/login.php | 4 ++-- lib/private/legacy/user.php | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/templates/login.php b/core/templates/login.php index 8405bac689..86c186928c 100644 --- a/core/templates/login.php +++ b/core/templates/login.php @@ -40,11 +40,11 @@ script('core', [

autocomplete="on" autocapitalize="off" autocorrect="off" required> - +

diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php index 11c35daa0d..78eb4bab12 100644 --- a/lib/private/legacy/user.php +++ b/lib/private/legacy/user.php @@ -152,14 +152,22 @@ class OC_User { /** * Try to login a user * - * @param string $loginname The login name of the user to log in + * @param string $loginName The login name of the user to log in * @param string $password The password of the user * @return boolean|null * * Log in a user and regenerate a new session - if the password is ok */ - public static function login($loginname, $password) { - $result = self::getUserSession()->login($loginname, $password); + public static function login($loginName, $password) { + + $result = self::getUserSession()->login($loginName, $password); + if (!$result) { + $users = \OC::$server->getUserManager()->getByEmail($loginName); + // we only allow login by email if unique + if (count($users) === 1) { + $result = self::getUserSession()->login($users[0]->getUID(), $password); + } + } if ($result) { // Refresh the token \OC::$server->getCsrfTokenManager()->refreshToken();