Subversion Repositories php_users

Rev

Rev 27 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 28
Line 18... Line 18...
18
</code>
18
</code>
19
My working copy is at
19
My working copy is at
20
http://svn.dailydata.net/svn/php_users/trunk
20
http://svn.dailydata.net/svn/php_users/trunk
21
but I recommend NOT using that as I use trunk as my personal playground and will commit broken code to it regularly
21
but I recommend NOT using that as I use trunk as my personal playground and will commit broken code to it regularly
22
 
22
 
-
 
23
An extension of this basic class which adds boolean permissions is the [[software:dailydata:libraries:php_user_permissions|UsersPermissions]] class. It is part of the same library.
-
 
24
 
23
==== Basic System ====
25
==== Basic System ====
24
 
26
 
25
With no modification, the system will store username, password and two booleans, isAdmin and enabled. The default table is created as
27
With no modification, the system will store username, password and two booleans, isAdmin and enabled. The default table is created as
26
 
28
 
27
<code sql>
29
<code sql>
Line 51... Line 53...
51
<code php>
53
<code php>
52
<?php
54
<?php
53
   include_once( 'UsersDataSourceMySQLi.class.php' );
55
   include_once( 'UsersDataSourceMySQLi.class.php' );
54
   include_once( 'Users.class.php' );
56
   include_once( 'Users.class.php' );
55
   session_start();
57
   session_start();
56
   $connection = new usersDataSource( 
58
   $connection = new UsersDataSourceMySQLi( 
57
         null,
59
         null,
58
         null, 
60
         null, 
59
         array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ) 
61
         array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ) 
60
      );
62
      );
61
   //$connection->buildTable( 'admin', 'admin' ); die;
63
   //$connection->buildTable( 'admin', 'admin' ); die;
Line 74... Line 76...
74
      </div>
76
      </div>
75
   </body>
77
   </body>
76
</html>
78
</html>
77
</code>
79
</code>
78
 
80
 
79
This example is using the usersDataSource definition of  data access (included)
81
This example is using the UsersDataSourceMySQLi definition of  data access (included)
80
 
82
 
81
If you run it the first time with <code php>$connection->buildTable( 'admin', 'admin' ); die;</code> uncommented, it will build the table. Comment that line out on the next run and you will be presented with a login screen.
83
If you run it the first time with <code php>$connection->buildTable( 'admin', 'admin' ); die;</code> uncommented, it will build the table. Comment that line out on the next run and you will be presented with a login screen.
82
 
84
 
83
Class function HTML() displays various things to allow login, then quits displaying anything. Setting $_REQUEST['logout'] = 1 before calling HTML() will initiate a log out which will destroy the session variable
85
Class function HTML() displays various things to allow login, then quits displaying anything. Setting $_REQUEST['logout'] = 1 before calling HTML() will initiate a log out which will destroy the session variable
84
 
86
 
Line 139... Line 141...
139
            )
141
            )
140
      );
142
      );
141
 ?>
143
 ?>
142
 </code>
144
 </code>
143
 
145
 
144
 Now, when we instantiate a new object of class Users AND class usersDataSource, we simply pass this array in.
146
 Now, when we instantiate a new object of class Users AND class UsersDataSourceMySQLi, we simply pass this array in.
145
 
147
 
146
 <code php>
148
 <code php>
147
    $connection = new usersDataSource( 
149
    $connection = new UsersDataSourceMySQLi( 
148
         null,
150
         null,
149
         $customFields, 
151
         $customFields, 
150
         array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ) 
152
         array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ) 
151
      );
153
      );
152
   if ( ! isset( $_SESSION['user'] ) ) { 
154
   if ( ! isset( $_SESSION['user'] ) ) { 
Line 211... Line 213...
211
== default ==
213
== default ==
212
For database creation, sets the DEFAULT attribute for the column
214
For database creation, sets the DEFAULT attribute for the column
213
 
215
 
214
==== usersDataSource ====
216
==== usersDataSource ====
215
 
217
 
216
This is our data access class. It really doesn't matter what it is called, though I plan to call it the same when I add more data access objects.
218
This is our data access class. As stated earlier, it is an abstract class, with UsersDataSourceMySQLi a class built on it.
217
 
219
 
218
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
220
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
219
 
221
 
220
getPassword( $username ) returns encrypted password
222
getPassword( $username ) returns encrypted password
221
getRecord( $username ) returns array containing the values for a user
223
getRecord( $username ) returns array containing the values for a user