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

Source for file Auth.php

Documentation is available at Auth.php

  1. <?php
  2. /**
  3. * DotBoost Technologies Inc.
  4. * DotKernel Application Framework
  5. *
  6. @category   DotKernel
  7. @package    DotLibrary
  8. @copyright  Copyright (c) 2009 DotBoost  Technologies (http://www.dotboost.com)
  9. @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  10. @version    $Id: Auth.php 156 2010-06-23 12:24:13Z teo $
  11. */
  12.  
  13. /**
  14. * Authorize user methods, used in all DotKernel Applications
  15. @category   DotKernel
  16. @package    DotLibrary
  17. @author     DotKernel Team <team@dotkernel.com>
  18. */
  19.  
  20. class Dot_Auth
  21. {                    
  22.     /**
  23.      * Check permission to a certain page/content
  24.      * Set wanted url if user is not logged
  25.      * @access public
  26.      * @static
  27.      * @todo extension to check user level
  28.      * @return bool 
  29.      */
  30.     public static function checkIdentity($who='user')
  31.     {        
  32.         $config Zend_Registry::get('configuration');
  33.         $session Zend_Registry::get('session');
  34.         if(!self::hasIdentity($who))
  35.         {
  36.             //register wanted url
  37.             if(!isset($session->wantUrl))
  38.             {
  39.                 $dotSeo new Dot_Seo();
  40.                 $session->wantUrl $dotSeo->createCanonicalUrl();
  41.             }
  42.             if(Zend_Registry::isRegistered('option'))
  43.             {
  44.                 $option Zend_Registry::get('option');
  45.                 $session->message['txt'$option->warningMessage->userPermission;
  46.                 $session->message['type''warning';
  47.             }    
  48.             //create login url    
  49.             switch ($who
  50.             {
  51.                 case 'admin':
  52.                     $loginUrl $config->website->params->url '/admin/admin/login';    
  53.                 break;                
  54.                 default:
  55.                     $loginUrl $config->website->params->url '/' $who '/login';
  56.                 break;
  57.             }
  58.             header('Location: ' $loginUrl);
  59.             exit;
  60.         }
  61.         //redirect user to wanted url
  62.         if(isset($session->wantUrl))
  63.         {
  64.             $wantUrl $session->wantUrl;
  65.             unset($session->wantUrl);
  66.             header('Location: ' $wantUrl);
  67.             exit;
  68.         }
  69.         return true;
  70.     }
  71.     /**
  72.      * Check to see if identity exists - is log in
  73.      * @access public
  74.      * @static
  75.      * @param string $who [optional]
  76.      * @return bool 
  77.      */    
  78.     public static function hasIdentity($who='user')
  79.     {
  80.         $session Zend_Registry::get('session');
  81.         if(isset($session->$who&& !empty($session->$who))
  82.         {
  83.             return true;
  84.         }
  85.         return false;
  86.     }    
  87.     public static function reguireLogin($who)
  88.     {
  89.         $session Zend_Registry::get('session');
  90.         if(!isset($session->wantUrl))
  91.         {
  92.             $dotSeo new Dot_Seo();
  93.             $session->wantUrl $dotSeo->createCanonicalUrl();
  94.         }
  95.     }
  96.     /**
  97.      * Return identity of $who
  98.      * @access public
  99.      * @static
  100.      * @param string $who [optional]
  101.      * @return object 
  102.      */
  103.     public static function getIdentity($who='user')
  104.     {
  105.         $session Zend_Registry::get('session');
  106.         if(self::hasIdentity($who))
  107.         {
  108.             return $session->$who;
  109.         }
  110.         return NULL;
  111.     }
  112.     /**
  113.      * Clear the identity - log out
  114.      * @access public
  115.      * @static
  116.      * @param string $who [optional]
  117.      * @return void 
  118.      */
  119.     public static function clearIdentity($who='user')
  120.     {
  121.         $session Zend_Registry::get('session');
  122.         if(self::hasIdentity($who))
  123.         {
  124.             unset($session->$who);
  125.         }
  126.     }      
  127. }

Documentation generated on Wed, 21 Jul 2010 07:34:38 +0000 by phpDocumentor 1.4.3