Skip to content

Commit

Permalink
Merge pull request #856 from nik2208/Docs_configurableUsertableFields
Browse files Browse the repository at this point in the history
Docs configurable usertable fields
  • Loading branch information
mevdschee authored Feb 17, 2022
2 parents 5c7dfda + 4bf16fa commit a995dd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ You can tune the middleware behavior using middleware specific configuration par
- "dbAuth.usernameColumn": The users table column that holds usernames ("username")
- "dbAuth.passwordColumn": The users table column that holds passwords ("password")
- "dbAuth.returnedColumns": The columns returned on successful login, empty means 'all' ("")
- "dbAuth.usernameFormField": The name of the property used as username request field, empty means 'username' ("")
- "dbAuth.passwordFormField": The name of the property used as password request field, empty means 'password' ("")
- "dbAuth.newPasswordFormField": The name of the property used as newPassword request field, empty means 'newPassword' ("")
- "dbAuth.registerUser": JSON user data (or "1") in case you want the /register endpoint enabled ("")
- "dbAuth.passwordLength": Minimum length that the password must have ("12")
- "dbAuth.sessionName": The name of the PHP session that is started ("")
Expand Down
9 changes: 6 additions & 3 deletions src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$method = $request->getMethod();
if ($method == 'POST' && in_array($path, ['login', 'register', 'password'])) {
$body = $request->getParsedBody();
$username = isset($body->username) ? $body->username : '';
$password = isset($body->password) ? $body->password : '';
$newPassword = isset($body->newPassword) ? $body->newPassword : '';
$usernameFormFieldName = $this->getProperty('usernameFormField', 'username');
$passwordFormFieldName = $this->getProperty('passwordFormField', 'username');
$newPasswordFormFieldName = $this->getProperty('newPasswordFormField', 'username');
$username = isset($body->usernameFormFieldName) ? $body->usernameFormFieldName : '';
$password = isset($body->passwordFormFieldName) ? $body->passwordFormFieldName : '';
$newPassword = isset($body->newPasswordFormFieldName) ? $body->newPasswordFormFieldName : '';
$tableName = $this->getProperty('usersTable', 'users');
$table = $this->reflection->getTable($tableName);
$usernameColumnName = $this->getProperty('usernameColumn', 'username');
Expand Down

0 comments on commit a995dd6

Please sign in to comment.