From 92478e187e7397c5f7a3a98010b181c4933cc2fe Mon Sep 17 00:00:00 2001 From: Maurits van der Schee Date: Wed, 1 Feb 2023 22:28:36 +0100 Subject: [PATCH] fix for #952 --- api.include.php | 9 ++++++--- api.php | 9 ++++++--- src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php | 9 ++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api.include.php b/api.include.php index f9a4332e..a81ebc51 100644 --- a/api.include.php +++ b/api.include.php @@ -8342,10 +8342,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $username = isset($body->$usernameFormFieldName) ? $body->$usernameFormFieldName : ''; $password = isset($body->$passwordFormFieldName) ? $body->$passwordFormFieldName : ''; $newPassword = isset($body->$newPasswordFormFieldName) ? $body->$newPasswordFormFieldName : ''; - if ($path === 'login') - $tableName = $this->getProperty('loginTable', 'users'); //add separate property for login as this could be a view joining users table to other table such as roles, details etc. At a minimum, the view output should include the $usernameColumn and $passwordColumn - else + //add separate property for login as this could be a view joining users table to other table + //such as roles, details etc. At a minimum, the view output should include the $usernameColumn and $passwordColumn + if ($path === 'login') { + $tableName = $this->getProperty('loginTable', $this->getProperty('usersTable', 'users')); + } else { $tableName = $this->getProperty('usersTable', 'users'); + } $table = $this->reflection->getTable($tableName); $usernameColumnName = $this->getProperty('usernameColumn', 'username'); $usernameColumn = $table->getColumn($usernameColumnName); diff --git a/api.php b/api.php index 6a9136d8..bfd8feb9 100644 --- a/api.php +++ b/api.php @@ -8342,10 +8342,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $username = isset($body->$usernameFormFieldName) ? $body->$usernameFormFieldName : ''; $password = isset($body->$passwordFormFieldName) ? $body->$passwordFormFieldName : ''; $newPassword = isset($body->$newPasswordFormFieldName) ? $body->$newPasswordFormFieldName : ''; - if ($path === 'login') - $tableName = $this->getProperty('loginTable', 'users'); //add separate property for login as this could be a view joining users table to other table such as roles, details etc. At a minimum, the view output should include the $usernameColumn and $passwordColumn - else + //add separate property for login as this could be a view joining users table to other table + //such as roles, details etc. At a minimum, the view output should include the $usernameColumn and $passwordColumn + if ($path === 'login') { + $tableName = $this->getProperty('loginTable', $this->getProperty('usersTable', 'users')); + } else { $tableName = $this->getProperty('usersTable', 'users'); + } $table = $this->reflection->getTable($tableName); $usernameColumnName = $this->getProperty('usernameColumn', 'username'); $usernameColumn = $table->getColumn($usernameColumnName); diff --git a/src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php b/src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php index 0c914f84..fb6aba9f 100644 --- a/src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php +++ b/src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php @@ -60,10 +60,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $username = isset($body->$usernameFormFieldName) ? $body->$usernameFormFieldName : ''; $password = isset($body->$passwordFormFieldName) ? $body->$passwordFormFieldName : ''; $newPassword = isset($body->$newPasswordFormFieldName) ? $body->$newPasswordFormFieldName : ''; - if ($path === 'login') - $tableName = $this->getProperty('loginTable', 'users'); //add separate property for login as this could be a view joining users table to other table such as roles, details etc. At a minimum, the view output should include the $usernameColumn and $passwordColumn - else + //add separate property for login as this could be a view joining users table to other table + //such as roles, details etc. At a minimum, the view output should include the $usernameColumn and $passwordColumn + if ($path === 'login') { + $tableName = $this->getProperty('loginTable', $this->getProperty('usersTable', 'users')); + } else { $tableName = $this->getProperty('usersTable', 'users'); + } $table = $this->reflection->getTable($tableName); $usernameColumnName = $this->getProperty('usernameColumn', 'username'); $usernameColumn = $table->getColumn($usernameColumnName);