Filter
[ class tree: Filter ] [ index: Filter ] [ all elements ]

Source for file HttpAuthFilter.php

Documentation is available at HttpAuthFilter.php

  1. <?php
  2. /**
  3.  * MVClasses
  4.  *
  5.  * LICENSE
  6.  *
  7.  * "THE BEER-WARE LICENSE" (Revision 42):
  8.  * "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
  9.  * As long as you retain this notice you can do whatever you want with
  10.  * this stuff. If we meet some day, and you think this stuff is worth it,
  11.  * you can buy me a beer in return.
  12.  *
  13.  * @category    MVClasses
  14.  * @package     Filter
  15.  * @copyright   Copyright (c) 2007 Sven Strittmatter
  16.  */
  17.  
  18. /**
  19.  * @see Filter
  20.  */
  21. require_once dirname(__FILE__)."/Filter.php";
  22. /**
  23.  * @see EventDispatcher
  24.  */
  25. require_once dirname(__FILE__)."/../Event/EventDispatcher.php";
  26.  
  27. /**
  28.  * Enter description here...
  29.  *
  30.  * Longdesc
  31.  *
  32.  * @todo complete description
  33.  *
  34.  * @category    MVClasses
  35.  * @package     Filter
  36.  * @copyright     Copyright (c) 2007 Sven Strittmatter
  37.  * @author    "Sven Strittmatter" <ausserirdisch@sven-space.de>
  38.  * @version     1.0
  39.  * @link        http://www.sven-space.de/code/php/MVClasses
  40.  */
  41. class HttpAuthFilter implements Filter {
  42.     private $_auth_data;
  43.  
  44.     public function __construct($auth_data{
  45.         $this->_auth_data $auth_data;
  46.     }
  47.  
  48.     public function execute(Request $reqResponse $res{
  49.         $auth_data $req->getAuthData();
  50.  
  51.         if (null === $auth_data{
  52.             $this->_sendAuthRequest($res);
  53.         }
  54.  
  55.         if (!isset($this->_auth_data[$auth_data['username']]||
  56.             $this->_auth_data[$auth_data['username']] !== $auth_data['password']{
  57.             EventDispatcher::getInstance()->triggerevent("onInvalidLogin"$this$auth_data);
  58.             $this->_sendAuthRequest($res);
  59.         }
  60.  
  61.         $event EventDispatcher::getInstance()->triggerEvent("onLogin"$this$auth_data);
  62.  
  63.         if ($event->isCancelled()) {
  64.             $this->_sendAuthRequest($res);
  65.         }
  66.     }
  67.  
  68.     private function _sendAuthRequest(Response $r{
  69.         $r->setStatus(HttpResponse::HTTP_STATUS_401);
  70.         $r->addHeader("WWW-Authenticate""Basic realm=\"RealCommunity\"");
  71.         $r->flush();
  72.         exit;
  73.     }
  74. }

Documentation generated on Sun, 02 Aug 2009 17:14:59 +0200 by phpDocumentor 1.4.2