Subversion Repositories php_users

Rev

Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8 Rev 16
Line 9... Line 9...
9
   $mysqlConnection = new mysqli( 'localhost', 'test', 'test', 'test' );
9
   $mysqlConnection = new mysqli( 'localhost', 'test', 'test', 'test' );
10
   // create a data source
10
   // create a data source
11
   $connection = new usersDataSource( $mysqlConnection );
11
   $connection = new usersDataSource( $mysqlConnection );
12
   // check if table exists and, if not, create it with username admin, password admin
12
   // check if table exists and, if not, create it with username admin, password admin
13
   if ( ! $connection->test() ) {
13
   if ( ! $connection->test() ) {
-
 
14
      $initValues = array( 
-
 
15
         'users' => array( 
-
 
16
            'login' => 'admin', 
-
 
17
            'pass' => password_hash( 'admin', PASSWORD_DEFAULT ),
-
 
18
            'admin' => 1, 
-
 
19
         )
-
 
20
         );
-
 
21
      $connection->buildTable( );
14
      $connection->buildTable( 'admin', 'admin' );
22
      $connection->initTables( $initValues );
15
   }
23
   }
16
   // create an empty Users instance and save it in the session
24
   // create an empty Users instance and save it in the session
17
   if ( ! isset( $_SESSION['user'] ) ) { 
25
   if ( ! isset( $_SESSION['user'] ) ) { 
18
      $_SESSION['user'] = new Users( );
26
      $_SESSION['user'] = new Users( );
19
   }
27
   }
Line 33... Line 41...
33
	<body>
41
	<body>
34
      <!-- this div is only shown if we need to log in -->
42
      <!-- this div is only shown if we need to log in -->
35
      <div class="login">
43
      <div class="login">
36
         <?php
44
         <?php
37
            // displays/processes login page if needed, empty otherwise
45
            // displays/processes login page if needed, empty otherwise
-
 
46
            if ( isset( $_SESSION['user'] ) )
38
            print $_SESSION['user']->HTML($connection); 
47
               print $_SESSION['user']->HTML($connection); 
39
         ?>
48
         ?>
40
      </div>
49
      </div>
41
      <!-- Our menu. Shows who is logged in, and gives a change password
50
      <!-- Our menu. Shows who is logged in, and gives a change password
42
            and logout menu options
51
            and logout menu options
43
      -->
52
      -->