You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-5Lines changed: 20 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,7 @@ These are all the configuration options and their default value between brackets
60
60
- "command": Extra SQL to initialize the database connection (none)
61
61
- "tables": Comma separated list of tables to publish (defaults to 'all')
62
62
- "mapping": Comma separated list of table/column mappings (no mappping)
63
+
- "geometrySrid": SRID assumed when converting from WKT to geometry (`4326`)
63
64
- "middlewares": List of middlewares to load (`cors`)
64
65
- "controllers": List of controllers to load (`records,geojson,openapi,status`)
65
66
- "customControllers": List of user custom controllers to load (no default)
@@ -134,6 +135,7 @@ Related projects:
134
135
-[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.
135
136
-[PHP-SP-API](https://github.com/mevdschee/php-sp-api): Single file PHP script that adds a REST API to a SQL database.
136
137
-[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/).
137
139
138
140
There are also ports of this script in:
139
141
@@ -283,7 +285,7 @@ On list operations you may apply filters and joins.
283
285
### Filters
284
286
285
287
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:
287
289
288
290
- "cs": contain string (string contains value)
289
291
- "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
570
572
[1,1]
571
573
572
574
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
574
576
contain the list of error documents. In the following response the first operation succeeded and the second operation
575
577
of the batch failed due to an integrity violation:
576
578
@@ -604,6 +606,7 @@ For spatial support there is an extra set of filters that can be applied on geom
604
606
- "siv": spatial is valid (geometry is valid)
605
607
606
608
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).
607
610
608
611
#### GeoJSON
609
612
@@ -664,7 +667,7 @@ You can enable the following middleware using the "middlewares" config parameter
664
667
- "multiTenancy": Restricts tenants access in a multi-tenant scenario
665
668
- "pageLimits": Restricts list operations to prevent database scraping
666
669
- "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
668
671
- "customization": Provides handlers for request and response customization
669
672
- "json": Support read/write of JSON strings as JSON objects/arrays
670
673
- "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
695
698
- "apiKeyDbAuth.apiKeyColumn": The users table column that holds the API key ("api_key")
696
699
- "dbAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
697
700
- "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")
698
702
- "dbAuth.usernameColumn": The users table column that holds usernames ("username")
699
703
- "dbAuth.passwordColumn": The users table column that holds passwords ("password")
700
704
- "dbAuth.returnedColumns": The columns returned on successful login, empty means 'all' ("")
701
705
- "dbAuth.usernameFormField": The name of the form field that holds the username ("username")
702
706
- "dbAuth.passwordFormField": The name of the form field that holds the password ("password")
703
707
- "dbAuth.newPasswordFormField": The name of the form field that holds the new password ("newPassword")
704
708
- "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 ("")
705
710
- "dbAuth.passwordLength": Minimum length that the password must have ("12")
706
711
- "dbAuth.sessionName": The name of the PHP session that is started ("")
707
712
- "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.
758
763
### Authentication
759
764
760
765
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.
762
767
The following overview shows the kinds of authentication middleware that you can enable.
763
768
764
769
| 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.
775
780
776
781
API key authentication works by sending an API key in a request header.
777
782
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).
779
784
780
785
X-API-Key: 02c042aa-c3c2-4d11-9dae-1a6e230ea95e
781
786
@@ -823,6 +828,13 @@ users can freely add, modify or delete any account! The minimal configuration is
823
828
824
829
Note that this middleware uses session cookies and stores the logged in state on the server.
825
830
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
+
826
838
#### Basic authentication
827
839
828
840
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:
1380
1392
| 1017 | 403 Forbidden | Bad or missing XSRF token
1381
1393
| 1018 | 403 Forbidden | Only AJAX requests allowed
1382
1394
| 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
1383
1398
| 9999 | 500 Internal server error | Unknown error
0 commit comments