This commit is contained in:
Brandon Lee
2019-10-22 13:46:23 +00:00
parent 2fee2f340a
commit b4c210566d
8 changed files with 54 additions and 8 deletions

View File

@@ -301,15 +301,15 @@ final class UserBackend extends ABackend implements
* Check if the user's password is correct then return its ID or
* FALSE on failure.
*
* @param string $uid The user ID.
* @param string $username The user ID.
* @param string $password The password.
*
* @return string|bool The user ID on success, false otherwise.
*/
public function checkPassword(string $uid, string $password)
public function checkPassword(string $username, string $password)
{
$this->logger->debug(
"Entering checkPassword($uid, *)", ["app" => $this->appName]
"Entering checkPassword($username, *)", ["app" => $this->appName]
);
$passwordAlgorithm = $this->getPasswordAlgorithm();
@@ -318,8 +318,8 @@ 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)) {
$user = $this->userRepository->findByUsername($username, $caseSensitive);
if (!($user instanceof User) || ($caseSensitive && $user->username !== $username)) {
return false;
}

View File

@@ -55,4 +55,5 @@ final class DB
const USER_QUOTA_COLUMN = "db.table.user.column.quota";
const USER_SALT_COLUMN = "db.table.user.column.salt";
const USER_UID_COLUMN = "db.table.user.column.uid";
const USER_USERNAME_COLUMN = "db.table.user.column.username";
}

View File

@@ -36,6 +36,8 @@ final class Query
const FIND_GROUPS = "find_groups";
const FIND_USER = "find_user";
const FIND_USER_CASE_INSENSITIVE = "find_user_case_insensitive";
const FIND_USER_BY_USERNAME = "find_user_by_username";
const FIND_USER_BY_USERNAME_CASE_INSENSITIVE = "find_user_by_username_case_insensitive";
const FIND_USER_GROUPS = "find_user_groups";
const FIND_USERS = "find_users";
const UPDATE_DISPLAY_NAME = "update_display_name";
@@ -50,4 +52,5 @@ final class Query
const QUOTA_PARAM = "quota";
const SEARCH_PARAM = "search";
const UID_PARAM = "uid";
const USERNAME_PARAM = "username";
}

View File

@@ -29,9 +29,13 @@ namespace OCA\UserSQL\Model;
class User
{
/**
* @var string The UID (username).
* @var string The UID (uid).
*/
public $uid;
/**
* @var string The user's username for login.
*/
public $username;
/**
* @var string The user's email address.
*/

View File

@@ -76,6 +76,7 @@ class QueryProvider implements \ArrayAccess
$uQuota = $this->properties[DB::USER_QUOTA_COLUMN];
$uSalt = $this->properties[DB::USER_SALT_COLUMN];
$uUID = $this->properties[DB::USER_UID_COLUMN];
$uUsername = $this->properties[DB::USER_USERNAME_COLUMN];
$ugGID = $this->properties[DB::USER_GROUP_GID_COLUMN];
$ugUID = $this->properties[DB::USER_GROUP_UID_COLUMN];
@@ -87,6 +88,7 @@ class QueryProvider implements \ArrayAccess
$quotaParam = Query::QUOTA_PARAM;
$searchParam = Query::SEARCH_PARAM;
$uidParam = Query::UID_PARAM;
$usernameParam = Query::USERNAME_PARAM;
$reverseActiveOpt = $this->properties[Opt::REVERSE_ACTIVE];
@@ -156,6 +158,18 @@ class QueryProvider implements \ArrayAccess
"FROM $user u " .
"WHERE lower(u.$uUID) = lower(:$uidParam) " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled"),
Query::FIND_USER_BY_USERNAME =>
"SELECT $userColumns, u.$uPassword AS password " .
"FROM $user u " .
"WHERE u.$uUsername = :$usernameParam " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled"),
Query::FIND_USER_BY_USERNAME_CASE_INSENSITIVE =>
"SELECT $userColumns, u.$uPassword AS password " .
"FROM $user u " .
"WHERE lower(u.$uUsername) = lower(:$usernameParam) " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled"),
Query::FIND_USER_GROUPS =>
"SELECT $groupColumns " .

View File

@@ -74,6 +74,29 @@ class UserRepository
);
}
}
/**
* Get an user entity object.
*
* @param string $username The username.
* @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 findByUsername($username, $caseSensitive = true)
{
if ($caseSensitive) {
return $this->dataQuery->queryEntity(
Query::FIND_USER_BY_USERNAME, User::class, [Query::USERNAME_PARAM => $username]
);
} else {
return $this->dataQuery->queryEntity(
Query::FIND_USER_BY_USERNAME_CASE_INSENSITIVE, User::class, [Query::USERNAME_PARAM => $username]
);
}
}
/**
* Get an array of user entity objects.