software:dailydata:libraries:php_user
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
software:dailydata:libraries:php_user [2021/08/25 21:24] – rodolico | software:dailydata:libraries:php_user [2021/09/22 01:30] (current) – rodolico | ||
---|---|---|---|
Line 3: | Line 3: | ||
I got frustrated trying to find a class or library to authenticate user logins in PHP. The ones I found were either too simplistic, or required me to " | I got frustrated trying to find a class or library to authenticate user logins in PHP. The ones I found were either too simplistic, or required me to " | ||
- | So, I decided to dust off the neurons and see if I could build one. I decided to make it as flexible as possible, with only the very basics, but able to be enhanced via data calls. I also decided to make the data access independent of the class itself so data access classes could be (re)written for tasks other than MySQL using the mysqli library. | + | So, I decided to dust off the neurons and see if I could build one. I decided to make it as flexible as possible, with only the very basics, but able to be enhanced via data calls. I also decided to make the data access independent of the class itself so data access classes could be written for tasks other than MySQL using the mysqli library. |
+ | |||
+ | Because of this, usersDataSource is an abstract class which can not be instantiated. Instead, you must extend the class, defining all of the abstract methods in the abstract. We've done this with the UsersDataSourceMySQLi class. | ||
By itself, the users class (with a data access class usersDataSource like the included UsersDataSourceMySQLi class) handles basic login/ | By itself, the users class (with a data access class usersDataSource like the included UsersDataSourceMySQLi class) handles basic login/ | ||
Line 13: | Line 15: | ||
You can get a copy of this from our subversion repository | You can get a copy of this from our subversion repository | ||
<code bash> | <code bash> | ||
- | svn co http:// | + | svn co http:// |
</ | </ | ||
My working copy is at | My working copy is at | ||
http:// | http:// | ||
but I recommend NOT using that as I use trunk as my personal playground and will commit broken code to it regularly | but I recommend NOT using that as I use trunk as my personal playground and will commit broken code to it regularly | ||
+ | |||
+ | An extension of this basic class which adds boolean permissions is the [[software: | ||
==== Basic System ==== | ==== Basic System ==== | ||
Line 26: | Line 30: | ||
create or replace table _users ( | create or replace table _users ( | ||
| | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
| | ||
); | ); | ||
Line 39: | Line 43: | ||
* users with enabled set to false (0) will not be able to log in | * users with enabled set to false (0) will not be able to log in | ||
- | NOTE: the usersDataSource | + | NOTE: the usersDataSourceMySQLi |
IMPORTANT: to allow the Users class to work with a wide variety of data types, it does no data access itself. It requires a data access class. | IMPORTANT: to allow the Users class to work with a wide variety of data types, it does no data access itself. It requires a data access class. | ||
Line 52: | Line 56: | ||
| | ||
| | ||
- | | + | |
null, | null, | ||
| | ||
Line 75: | Line 79: | ||
</ | </ | ||
- | This example is using the usersDataSource | + | This example is using the UsersDataSourceMySQLi |
If you run it the first time with <code php> | If you run it the first time with <code php> | ||
Line 140: | Line 144: | ||
</ | </ | ||
- | Now, when we instantiate a new object of class Users AND class usersDataSource, we simply pass this array in. | + | Now, when we instantiate a new object of class Users AND class UsersDataSourceMySQLi, we simply pass this array in. |
< | < | ||
- | $connection = new usersDataSource( | + | $connection = new UsersDataSourceMySQLi( |
null, | null, | ||
| | ||
Line 212: | Line 216: | ||
==== usersDataSource ==== | ==== usersDataSource ==== | ||
- | This is our data access class. | + | This is our data access class. |
This code accesses the data (duh), and is consistently called $connection in the Users class. The only requirement is that it must be able to implement the following functions | This code accesses the data (duh), and is consistently called $connection in the Users class. The only requirement is that it must be able to implement the following functions | ||
Line 226: | Line 230: | ||
I separated this out from the Users class because not all programs need database access. For instance, the favorites_urls app uses file based storage, so by writing a new access class for it, we will hopefully be able to get the same functionality, | I separated this out from the Users class because not all programs need database access. For instance, the favorites_urls app uses file based storage, so by writing a new access class for it, we will hopefully be able to get the same functionality, | ||
- | ==== Future ==== | ||
- | * I think I have a way of making it match things like INPUT TYPE=' | ||
- | * This is only the initial part of this particular project. I now intend to extend both classes to allow boolean permissions which will be integrated into our new version of CAMP, giving very granular rights to users. It will be available as a second set of files in this repository and is planned for release by October 2021. | ||
software/dailydata/libraries/php_user.1629944682.txt.gz · Last modified: 2021/08/25 21:24 by rodolico