Skip to content

Commit b48ca60

Browse files
committed
fix for mevdschee#944
2 parents a186435 + 2a7a3e3 commit b48ca60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1026
-741
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Maurits van der Schee
3+
Copyright (c) 2022 Maurits van der Schee
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ These are all the configuration options and their default value between brackets
6060
- "command": Extra SQL to initialize the database connection (none)
6161
- "tables": Comma separated list of tables to publish (defaults to 'all')
6262
- "mapping": Comma separated list of table/column mappings (no mappping)
63+
- "geometrySrid": SRID assumed when converting from WKT to geometry (`4326`)
6364
- "middlewares": List of middlewares to load (`cors`)
6465
- "controllers": List of controllers to load (`records,geojson,openapi,status`)
6566
- "customControllers": List of user custom controllers to load (no default)
@@ -134,6 +135,7 @@ Related projects:
134135
- [PHP-CRUD-ADMIN](https://github.com/mevdschee/php-crud-admin): Single file PHP script that adds a database admin interface to a PHP-CRUD-API project.
135136
- [PHP-SP-API](https://github.com/mevdschee/php-sp-api): Single file PHP script that adds a REST API to a SQL database.
136137
- [VUE-CRUD-UI](https://github.com/nlware/vue-crud-ui): Single file Vue.js script that adds a UI to a PHP-CRUD-API project.
138+
- [ra-data-treeql](https://github.com/nkappler/ra-data-treeql): NPM package that provides a [Data Provider](https://marmelab.com/react-admin/DataProviderIntroduction.html) for [React Admin](https://marmelab.com/react-admin/).
137139

138140
There are also ports of this script in:
139141

@@ -283,7 +285,7 @@ On list operations you may apply filters and joins.
283285
### Filters
284286

285287
Filters provide search functionality, on list calls, using the "filter" parameter. You need to specify the column
286-
name, a comma, the match type, another commma and the value you want to filter on. These are supported match types:
288+
name, a comma, the match type, another comma and the value you want to filter on. These are supported match types:
287289

288290
- "cs": contain string (string contains value)
289291
- "sw": start with (string starts with value)
@@ -570,7 +572,7 @@ This adjusts the titles of the posts. And the return values are the number of ro
570572
[1,1]
571573

572574
Which means that there were two update operations and each of them had set one row. Batch operations use database
573-
transactions, so they either all succeed or all fail (successful ones get roled back). If they fail the body will
575+
transactions, so they either all succeed or all fail (successful ones get rolled back). If they fail the body will
574576
contain the list of error documents. In the following response the first operation succeeded and the second operation
575577
of the batch failed due to an integrity violation:
576578

@@ -604,6 +606,7 @@ For spatial support there is an extra set of filters that can be applied on geom
604606
- "siv": spatial is valid (geometry is valid)
605607

606608
These filters are based on OGC standards and so is the WKT specification in which the geometry columns are represented.
609+
Note that the SRID that is assumed when converting from WKT to geometry is specified by the config variable `geometrySrid` and defaults to 4326 (WGS 84).
607610

608611
#### GeoJSON
609612

@@ -664,7 +667,7 @@ You can enable the following middleware using the "middlewares" config parameter
664667
- "multiTenancy": Restricts tenants access in a multi-tenant scenario
665668
- "pageLimits": Restricts list operations to prevent database scraping
666669
- "joinLimits": Restricts join parameters to prevent database scraping
667-
- "textSearch": Search in all text fields with a simple paramater
670+
- "textSearch": Search in all text fields with a simple parameter
668671
- "customization": Provides handlers for request and response customization
669672
- "json": Support read/write of JSON strings as JSON objects/arrays
670673
- "xml": Translates all input and output from JSON to XML
@@ -695,13 +698,15 @@ You can tune the middleware behavior using middleware specific configuration par
695698
- "apiKeyDbAuth.apiKeyColumn": The users table column that holds the API key ("api_key")
696699
- "dbAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
697700
- "dbAuth.usersTable": The table that is used to store the users in ("users")
701+
- "dbAuth.loginTable": The table or view that is used to retrieve the users info for login ("users")
698702
- "dbAuth.usernameColumn": The users table column that holds usernames ("username")
699703
- "dbAuth.passwordColumn": The users table column that holds passwords ("password")
700704
- "dbAuth.returnedColumns": The columns returned on successful login, empty means 'all' ("")
701705
- "dbAuth.usernameFormField": The name of the form field that holds the username ("username")
702706
- "dbAuth.passwordFormField": The name of the form field that holds the password ("password")
703707
- "dbAuth.newPasswordFormField": The name of the form field that holds the new password ("newPassword")
704708
- "dbAuth.registerUser": JSON user data (or "1") in case you want the /register endpoint enabled ("")
709+
- "dbAuth.loginAfterRegistration": 1 or zero if registered users should be logged in after registration ("")
705710
- "dbAuth.passwordLength": Minimum length that the password must have ("12")
706711
- "dbAuth.sessionName": The name of the PHP session that is started ("")
707712
- "jwtAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
@@ -758,7 +763,7 @@ In the sections below you find more information on the built-in middleware.
758763
### Authentication
759764

760765
Currently there are five types of authentication supported. They all store the authenticated user in the `$_SESSION` super global.
761-
This variable can be used in the authorization handlers to decide wether or not sombeody should have read or write access to certain tables, columns or records.
766+
This variable can be used in the authorization handlers to decide wether or not somebody should have read or write access to certain tables, columns or records.
762767
The following overview shows the kinds of authentication middleware that you can enable.
763768

764769
| Name | Middleware | Authenticated via | Users are stored in | Session variable |
@@ -775,7 +780,7 @@ Below you find more information on each of the authentication types.
775780

776781
API key authentication works by sending an API key in a request header.
777782
The header name defaults to "X-API-Key" and can be configured using the 'apiKeyAuth.header' configuration parameter.
778-
Valid API keys must be configured using the 'apiKeyAuth.keys' configuration parameter (comma seperated list).
783+
Valid API keys must be configured using the 'apiKeyAuth.keys' configuration parameter (comma separated list).
779784

780785
X-API-Key: 02c042aa-c3c2-4d11-9dae-1a6e230ea95e
781786

@@ -823,6 +828,13 @@ users can freely add, modify or delete any account! The minimal configuration is
823828

824829
Note that this middleware uses session cookies and stores the logged in state on the server.
825830

831+
**Login using views with joined table**
832+
833+
For login operations, it is possible to use a view as the usersTable. Such view can return a filtered result from the users table, e.g., *where active = true* or it may also return a result multiple tables thru a table join. At a minimum, the view should include the ***username*** and ***password*** and a field named ***id***.
834+
835+
However, views with joined tables are not insertable ([see issue 907](https://github.com/mevdschee/php-crud-api/issues/907) ). As a workaround, use the property ***loginTable*** to set a different reference table for login. The **usersTable** will still be set to the normal, insertable users table.
836+
837+
826838
#### Basic authentication
827839

828840
The Basic type supports a file (by default '.htpasswd') that holds the users and their (hashed) passwords separated by a colon (':').
@@ -1380,6 +1392,9 @@ The following errors may be reported:
13801392
| 1017 | 403 Forbidden | Bad or missing XSRF token
13811393
| 1018 | 403 Forbidden | Only AJAX requests allowed
13821394
| 1019 | 403 Forbidden | Pagination Forbidden
1395+
| 1020 | 409 Conflict | User already exists
1396+
| 1021 | 422 Unprocessable entity | Password too short
1397+
| 1022 | 422 Unprocessable entity | Username is empty
13831398
| 9999 | 500 Internal server error | Unknown error
13841399

13851400
The following JSON structure is used:

0 commit comments

Comments
 (0)