Subversion Repositories php_users

Rev

Rev 7 | Rev 16 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 rodolico 1
<!DOCTYPE html>
2
<?php
3
   include_once( '../UsersDataSourceMySQLi.class.php' );
4
   include_once( '../Users.class.php' );
5
   session_start();
6
   //session_destroy(); die;
8 rodolico 7
   // make a connection to the database
8
   mysqli_report( MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT );
9
   $mysqlConnection = new mysqli( 'localhost', 'test', 'test', 'test' );
10
   // create a data source
11
   $connection = new usersDataSource( $mysqlConnection );
12
   // check if table exists and, if not, create it with username admin, password admin
13
   if ( ! $connection->test() ) {
14
      $connection->buildTable( 'admin', 'admin' );
15
   }
16
   // create an empty Users instance and save it in the session
4 rodolico 17
   if ( ! isset( $_SESSION['user'] ) ) { 
8 rodolico 18
      $_SESSION['user'] = new Users( );
4 rodolico 19
   }
8 rodolico 20
   // if they asked to log out, log out
4 rodolico 21
   if ( isset( $_REQUEST['logout'] ) )
22
      $_SESSION['user']->logout();
23
 
24
   $url = htmlentities($_SERVER["PHP_SELF"]);
25
 
26
?>
27
<html>
28
	<head>
29
		<meta charset="utf-8">
30
		<title>Login</title>
31
     <link href='users.css' rel='stylesheet' type='text/css'>
32
	</head>
33
	<body>
8 rodolico 34
      <!-- this div is only shown if we need to log in -->
4 rodolico 35
      <div class="login">
8 rodolico 36
         <?php
37
            // displays/processes login page if needed, empty otherwise
38
            print $_SESSION['user']->HTML($connection); 
4 rodolico 39
         ?>
40
      </div>
8 rodolico 41
      <!-- Our menu. Shows who is logged in, and gives a change password
42
            and logout menu options
43
      -->
4 rodolico 44
      <div class='menu'>
45
         <ul>
46
         <?php
47
            if ( isset( $_SESSION['user'] ) && $_SESSION['user']->name() ) {
48
               print "<p>Logged in as " . $_SESSION['user']->name() . '</p>';
49
               print "<li><a href='$url?doAdmin=1'>Change Password</a></li>\n";
50
               print "<li><a href='$url?logout=1'>Log Out</a></li>";
51
            }
52
         ?>
53
         </ul>
54
      </div>
8 rodolico 55
      <!--
56
      this is where I'd put my content. The only thing in it right now
57
      is the code to do the admin page if "Change Password" was clicked above
58
      -->
4 rodolico 59
      <div class='content'>
60
         <?php
61
            if ( isset( $_REQUEST['doAdmin'] ) ) {
62
               print $_SESSION['user']->admin($connection);
7 rodolico 63
               print $_SESSION['user']->errors();
64
               $_SESSION['user']->clearErrors();
4 rodolico 65
            }
66
         ?>
67
      </div>
68
	</body>
69
</html>