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] 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();