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

@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Support for Nextcloud 19
- Argon2id support
- System wide values option
- Allow email login option
## [4.4.1] - 2020-02-02
### Fixed

View File

@@ -49,6 +49,7 @@ Here are all currently supported options.
Name | Description | Details
--- | --- | ---
**Allow display name change** | With this option enabled user can change its display name. The display name change is propagated to the database. | Optional.<br/>Default: *false*.<br/>Requires: user *Display name* column.
**Allow email login** | User input at login is considered to be either UID or email. | Optional.<br/>Default: *false*.<br/>Requires: user *Email* column.
**Allow password change** | Can user change its password. The password change is propagated to the database. See [Hash algorithms](#hash-algorithms). | Optional.<br/>Default: *false*.
**Allow providing avatar** | Can user provide its avatar. The value is used when column *Provide avatar* is not set. | Optional.<br/>Default: *false*.
**Case-insensitive username** | Whether user query should be case-sensitive or case-insensitive. | Optional.<br/>Default: *false*.

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]);
$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) || ($caseSensitive && $user->uid !== $uid)) {
}
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.
*

View File

@@ -110,6 +110,7 @@ function print_select_options(
<p class="settings-hint"><?php p($l->t("Here are all currently supported options.")); ?></p>
<fieldset><?php
print_checkbox_input($l, "opt-name_change", "Allow display name change", $_["opt.name_change"]);
print_checkbox_input($l, "opt-email_login", "Allow email login", $_["opt.email_login"]);
print_checkbox_input($l, "opt-password_change", "Allow password change", $_["opt.password_change"]);
print_checkbox_input($l, "opt-provide_avatar", "Allow providing avatar", $_["opt.provide_avatar"]);
print_checkbox_input($l, "opt-case_insensitive_username", "Case-insensitive username", $_["opt.case_insensitive_username"]);