Skip to content

Commit a995dd6

Browse files
authored
Merge pull request #856 from nik2208/Docs_configurableUsertableFields
Docs configurable usertable fields
2 parents 5c7dfda + 4bf16fa commit a995dd6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ You can tune the middleware behavior using middleware specific configuration par
674674
- "dbAuth.usernameColumn": The users table column that holds usernames ("username")
675675
- "dbAuth.passwordColumn": The users table column that holds passwords ("password")
676676
- "dbAuth.returnedColumns": The columns returned on successful login, empty means 'all' ("")
677+
- "dbAuth.usernameFormField": The name of the property used as username request field, empty means 'username' ("")
678+
- "dbAuth.passwordFormField": The name of the property used as password request field, empty means 'password' ("")
679+
- "dbAuth.newPasswordFormField": The name of the property used as newPassword request field, empty means 'newPassword' ("")
677680
- "dbAuth.registerUser": JSON user data (or "1") in case you want the /register endpoint enabled ("")
678681
- "dbAuth.passwordLength": Minimum length that the password must have ("12")
679682
- "dbAuth.sessionName": The name of the PHP session that is started ("")

src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
4444
$method = $request->getMethod();
4545
if ($method == 'POST' && in_array($path, ['login', 'register', 'password'])) {
4646
$body = $request->getParsedBody();
47-
$username = isset($body->username) ? $body->username : '';
48-
$password = isset($body->password) ? $body->password : '';
49-
$newPassword = isset($body->newPassword) ? $body->newPassword : '';
47+
$usernameFormFieldName = $this->getProperty('usernameFormField', 'username');
48+
$passwordFormFieldName = $this->getProperty('passwordFormField', 'username');
49+
$newPasswordFormFieldName = $this->getProperty('newPasswordFormField', 'username');
50+
$username = isset($body->usernameFormFieldName) ? $body->usernameFormFieldName : '';
51+
$password = isset($body->passwordFormFieldName) ? $body->passwordFormFieldName : '';
52+
$newPassword = isset($body->newPasswordFormFieldName) ? $body->newPasswordFormFieldName : '';
5053
$tableName = $this->getProperty('usersTable', 'users');
5154
$table = $this->reflection->getTable($tableName);
5255
$usernameColumnName = $this->getProperty('usernameColumn', 'username');

0 commit comments

Comments
 (0)