includes/pageprocess.php
changeset 32 4d87aad3c4c0
parent 31 dc8741857bde
child 37 7267c2a67a93
--- a/includes/pageprocess.php	Thu Jun 28 15:26:40 2007 -0400
+++ b/includes/pageprocess.php	Sun Jul 01 14:08:39 2007 -0400
@@ -60,6 +60,13 @@
   var $perms = null;
   
   /**
+   * The SHA1 hash of the user-inputted password for the page
+   * @var string
+   */
+   
+  var $password = '';
+  
+  /**
    * Switch to track if redirects are allowed. Defaults to true.
    * @var bool
    */
@@ -143,6 +150,15 @@
         $this->send_headers = false;
         $strict_no_headers = true;
       }
+      if ( $paths->pages[$pathskey]['password'] != '' && $paths->pages[$pathskey]['password'] != sha1('') )
+      {
+        $password =& $paths->pages[$pathskey]['password'];
+        if ( $this->password != $password )
+        {
+          $this->err_wrong_password();
+          return false;
+        }
+      }
     }
     if ( $this->namespace == 'Special' || $this->namespace == 'Admin' )
     {
@@ -472,6 +488,7 @@
   function _handle_userpage()
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
+    global $email;
     
     if ( $this->page_id == $paths->cpage['urlname_nons'] && $this->namespace == $paths->namespace )
     {
@@ -689,7 +706,6 @@
     if ( $userdata['email_public'] == 1 )
     {
       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
-      global $email;
       $email_link = $email->encryptEmail($userdata['email']);
       echo '<tr><td class="'.$class.'">E-mail address: ' . $email_link . '</td></tr>';
     }
@@ -808,6 +824,36 @@
   }
   
   /**
+   * Inform the user of an incorrect or absent password
+   * @access private
+   */
+   
+  function err_wrong_password()
+  {
+    global $db, $session, $paths, $template, $plugins; // Common objects
+    
+    $title = 'Password required';
+    $message = ( empty($this->password) ) ? '<p>Access to this page requires a password. Please enter the password for this page below:</p>' : '<p>The password you entered for this page was incorrect. Please enter the password for this page below:</p>';
+    $message .= '<form action="' . makeUrlNS($this->namespace, $this->page_id) . '" method="post">
+                   <p>
+                     <label>Password: <input name="pagepass" type="password" /></label>&nbsp;&nbsp;<input type="submit" value="Submit" />
+                   </p>
+                 </form>';
+    if ( $this->send_headers )
+    {
+      $template->tpl_strings['PAGE_NAME'] = $title;
+      $template->header();
+      echo "$message";
+      $template->footer();
+    }
+    else
+    {
+      echo "<h2>$title</h2>
+            $message";
+    }
+  }
+  
+  /**
    * Send the error message to the user complaining that there weren't any rows.
    * @access private
    */