issue#135 Allow email login

This commit is contained in:
Marcin Łojewski
2020-03-29 22:08:35 +02:00
parent 94714ae987
commit 953dae293e
9 changed files with 56 additions and 7 deletions

View File

@@ -2,7 +2,7 @@
/**
* Nextcloud - user_sql
*
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
* @author Marcin Łojewski <dev@mlojewski.me>
*
* This program is free software: you can redistribute it and/or modify
@@ -318,8 +318,14 @@ final class UserBackend extends ABackend implements
}
$caseSensitive = empty($this->properties[Opt::CASE_INSENSITIVE_USERNAME]);
$user = $this->userRepository->findByUid($uid, $caseSensitive);
if (!($user instanceof User) || ($caseSensitive && $user->uid !== $uid)) {
$emailLogin = !empty($this->properties[Opt::EMAIL_LOGIN]);
if ($emailLogin) {
$user = $this->userRepository->findByUidOrEmail($uid, $caseSensitive);
} else {
$user = $this->userRepository->findByUid($uid, $caseSensitive);
}
if (!($user instanceof User)) {
return false;
}

View File

@@ -34,6 +34,7 @@ final class Opt
const CRYPTO_PARAM_0 = "opt.crypto_param_0";
const CRYPTO_PARAM_1 = "opt.crypto_param_1";
const CRYPTO_PARAM_2 = "opt.crypto_param_2";
const EMAIL_LOGIN = "opt.email_login";
const EMAIL_SYNC = "opt.email_sync";
const HOME_LOCATION = "opt.home_location";
const HOME_MODE = "opt.home_mode";

View File

@@ -2,7 +2,7 @@
/**
* Nextcloud - user_sql
*
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
* @author Marcin Łojewski <dev@mlojewski.me>
*
* This program is free software: you can redistribute it and/or modify
@@ -35,6 +35,8 @@ final class Query
const FIND_GROUP_USERS = "find_group_users";
const FIND_GROUPS = "find_groups";
const FIND_USER = "find_user";
const FIND_USER_BY_UID_OR_EMAIL = "find_user_by_uid_or_email";
const FIND_USER_BY_UID_OR_EMAIL_CASE_INSENSITIVE = "find_user_by_uid_or_email_case_insensitive";
const FIND_USER_CASE_INSENSITIVE = "find_user_case_insensitive";
const FIND_USER_GROUPS = "find_user_groups";
const FIND_USERS = "find_users";

View File

@@ -174,7 +174,7 @@ class Properties implements \ArrayAccess
{
return in_array(
$param, [
Opt::APPEND_SALT, Opt::CASE_INSENSITIVE_USERNAME,
Opt::APPEND_SALT, Opt::CASE_INSENSITIVE_USERNAME, Opt::EMAIL_LOGIN,
Opt::NAME_CHANGE, Opt::PASSWORD_CHANGE, Opt::PREPEND_SALT,
Opt::PROVIDE_AVATAR, Opt::REVERSE_ACTIVE, Opt::SAFE_STORE,
Opt::USE_CACHE

View File

@@ -2,7 +2,7 @@
/**
* Nextcloud - user_sql
*
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
* @author Marcin Łojewski <dev@mlojewski.me>
*
* This program is free software: you can redistribute it and/or modify
@@ -151,6 +151,18 @@ class QueryProvider implements \ArrayAccess
"WHERE u.$uUID = :$uidParam " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled"),
Query::FIND_USER_BY_UID_OR_EMAIL =>
"SELECT $userColumns, u.$uPassword AS password " .
"FROM $user u " .
"WHERE u.$uUID = :$uidParam OR u.$uEmail = :$emailParam " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled"),
Query::FIND_USER_BY_UID_OR_EMAIL_CASE_INSENSITIVE =>
"SELECT $userColumns, u.$uPassword AS password " .
"FROM $user u " .
"WHERE lower(u.$uUID) = lower(:$uidParam) OR lower(u.$uEmail) = lower(:$emailParam) " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled"),
Query::FIND_USER_CASE_INSENSITIVE =>
"SELECT $userColumns, u.$uPassword AS password " .
"FROM $user u " .

View File

@@ -2,7 +2,7 @@
/**
* Nextcloud - user_sql
*
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
* @author Marcin Łojewski <dev@mlojewski.me>
*
* This program is free software: you can redistribute it and/or modify
@@ -75,6 +75,31 @@ class UserRepository
}
}
/**
* Get an user entity object.
*
* @param string $query The user ID or email address.
* @param bool $caseSensitive TRUE for case sensitive search,
* FALSE for case insensitive search.
*
* @return User The user entity, NULL if it does not exists or
* FALSE on failure.
*/
public function findByUidOrEmail($query, $caseSensitive = true)
{
if ($caseSensitive) {
return $this->dataQuery->queryEntity(
Query::FIND_USER_BY_UID_OR_EMAIL, User::class,
[Query::UID_PARAM => $query, Query::EMAIL_PARAM => $query]
);
} else {
return $this->dataQuery->queryEntity(
Query::FIND_USER_BY_UID_OR_EMAIL_CASE_INSENSITIVE, User::class,
[Query::UID_PARAM => $query, Query::EMAIL_PARAM => $query]
);
}
}
/**
* Get an array of user entity objects.
*