summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/legacy/user.php14
-rw-r--r--lib/private/user/manager.php14
-rw-r--r--lib/public/iusermanager.php7
3 files changed, 32 insertions, 3 deletions
diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php
index 11c35daa0de..78eb4bab126 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();
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index 4371be134aa..37a3e5ba134 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 6442938a99b..00c0bbc8721 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);
}