Signed-off-by: Brandon Lee <blee@circuitid.com>
This commit is contained in:
Brandon Lee
2019-10-22 15:31:30 +00:00
parent 2fee2f340a
commit 5654bfac53
7 changed files with 53 additions and 8 deletions

View File

@@ -119,7 +119,7 @@ user_sql.adminSettingsUI = function () {
); );
autocomplete( autocomplete(
"#db-table-user-column-uid, #db-table-user-column-email, #db-table-user-column-quota, #db-table-user-column-home, #db-table-user-column-password, #db-table-user-column-name, #db-table-user-column-active, #db-table-user-column-disabled, #db-table-user-column-avatar, #db-table-user-column-salt", "#db-table-user-column-uid, #db-table-user-column-username, #db-table-user-column-email, #db-table-user-column-quota, #db-table-user-column-home, #db-table-user-column-password, #db-table-user-column-name, #db-table-user-column-active, #db-table-user-column-disabled, #db-table-user-column-avatar, #db-table-user-column-salt",
"/apps/user_sql/settings/autocomplete/table/user" "/apps/user_sql/settings/autocomplete/table/user"
); );

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

View File

@@ -55,4 +55,5 @@ final class DB
const USER_QUOTA_COLUMN = "db.table.user.column.quota"; const USER_QUOTA_COLUMN = "db.table.user.column.quota";
const USER_SALT_COLUMN = "db.table.user.column.salt"; const USER_SALT_COLUMN = "db.table.user.column.salt";
const USER_UID_COLUMN = "db.table.user.column.uid"; 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_GROUPS = "find_groups";
const FIND_USER = "find_user"; const FIND_USER = "find_user";
const FIND_USER_CASE_INSENSITIVE = "find_user_case_insensitive"; 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_USER_GROUPS = "find_user_groups";
const FIND_USERS = "find_users"; const FIND_USERS = "find_users";
const UPDATE_DISPLAY_NAME = "update_display_name"; const UPDATE_DISPLAY_NAME = "update_display_name";
@@ -50,4 +52,5 @@ final class Query
const QUOTA_PARAM = "quota"; const QUOTA_PARAM = "quota";
const SEARCH_PARAM = "search"; const SEARCH_PARAM = "search";
const UID_PARAM = "uid"; const UID_PARAM = "uid";
const USERNAME_PARAM = "username";
} }

View File

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

View File

@@ -76,6 +76,7 @@ class QueryProvider implements \ArrayAccess
$uQuota = $this->properties[DB::USER_QUOTA_COLUMN]; $uQuota = $this->properties[DB::USER_QUOTA_COLUMN];
$uSalt = $this->properties[DB::USER_SALT_COLUMN]; $uSalt = $this->properties[DB::USER_SALT_COLUMN];
$uUID = $this->properties[DB::USER_UID_COLUMN]; $uUID = $this->properties[DB::USER_UID_COLUMN];
$uUsername = $this->properties[DB::USER_USERNAME_COLUMN];
$ugGID = $this->properties[DB::USER_GROUP_GID_COLUMN]; $ugGID = $this->properties[DB::USER_GROUP_GID_COLUMN];
$ugUID = $this->properties[DB::USER_GROUP_UID_COLUMN]; $ugUID = $this->properties[DB::USER_GROUP_UID_COLUMN];
@@ -87,6 +88,7 @@ class QueryProvider implements \ArrayAccess
$quotaParam = Query::QUOTA_PARAM; $quotaParam = Query::QUOTA_PARAM;
$searchParam = Query::SEARCH_PARAM; $searchParam = Query::SEARCH_PARAM;
$uidParam = Query::UID_PARAM; $uidParam = Query::UID_PARAM;
$usernameParam = Query::USERNAME_PARAM;
$reverseActiveOpt = $this->properties[Opt::REVERSE_ACTIVE]; $reverseActiveOpt = $this->properties[Opt::REVERSE_ACTIVE];
@@ -95,7 +97,7 @@ class QueryProvider implements \ArrayAccess
(empty($gName) ? "g." . $gGID : "g." . $gName) . " AS name, " . (empty($gName) ? "g." . $gGID : "g." . $gName) . " AS name, " .
(empty($gAdmin) ? "false" : "g." . $gAdmin) . " AS admin"; (empty($gAdmin) ? "false" : "g." . $gAdmin) . " AS admin";
$userColumns $userColumns
= "u.$uUID AS uid, " . = "u.$uUID AS uid, u.$uUsername AS username, " .
(empty($uName) ? "u." . $uUID : "u." . $uName) . " AS name, " . (empty($uName) ? "u." . $uUID : "u." . $uName) . " AS name, " .
(empty($uEmail) ? "null" : "u." . $uEmail) . " AS email, " . (empty($uEmail) ? "null" : "u." . $uEmail) . " AS email, " .
(empty($uQuota) ? "null" : "u." . $uQuota) . " AS quota, " . (empty($uQuota) ? "null" : "u." . $uQuota) . " AS quota, " .
@@ -157,6 +159,18 @@ class QueryProvider implements \ArrayAccess
"WHERE lower(u.$uUID) = lower(:$uidParam) " . "WHERE lower(u.$uUID) = lower(:$uidParam) " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled"), (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 => Query::FIND_USER_GROUPS =>
"SELECT $groupColumns " . "SELECT $groupColumns " .
"FROM $group g, $userGroup ug " . "FROM $group g, $userGroup ug " .

View File

@@ -75,6 +75,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. * Get an array of user entity objects.
* *