Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/user/authenticate.php

Documentation is available at authenticate.php

  1. <?php
  2. /**
  3. @version        $Id: authenticate.php 6694 2007-02-22 01:28:09Z CoolAcid $
  4. @package        Joomla.Framework
  5. @subpackage    User
  6. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * This is the status code returned when the authentication is success.
  20.  */
  21. define('JAUTHENTICATE_STATUS_SUCCESS'1);
  22.  
  23. /**
  24.  * Status to indicate cancellation of authentication.
  25.  */
  26. define('JAUTHENTICATE_STATUS_CANCEL'2);
  27.  
  28. /**
  29.  * This is the status code returned when the authentication failed
  30.  */
  31. define('JAUTHENTICATE_STATUS_FAILURE'4);
  32.  
  33. /**
  34.  * Authorization class, provides an interface for the Joomla authentication system
  35.  *
  36.  * @author         Louis Landry <[email protected]>
  37.  * @package     Joomla.Framework
  38.  * @subpackage    User
  39.  * @since        1.5
  40.  */
  41. class JAuthenticate extends JObject
  42. {
  43.     /**
  44.      * Constructor
  45.      *
  46.      * @access protected
  47.      */
  48.     function __construct()
  49.     {
  50.         // Get the global event dispatcher to load the plugins
  51.         $dispatcher =JEventDispatcher::getInstance();
  52.  
  53.         $plugins =JPluginHelper::getPlugin('authentication');
  54.  
  55.         $isLoaded false;
  56.         foreach ($plugins as $plugin{
  57.             $isLoaded |= $this->loadPlugin($plugin->element$dispatcher);
  58.         }
  59.  
  60.         if (!$isLoaded{
  61.             JError::raiseWarning('SOME_ERROR_CODE''JAuthenticate::__constructor: Could not load authentication libraries.'$plugins);
  62.         }
  63.     }
  64.  
  65.     /**
  66.      * Returns a reference to a global authentication object, only creating it
  67.      * if it doesn't already exist.
  68.      *
  69.      * This method must be invoked as:
  70.      *         <pre>  $auth = &JAuthenticate::getInstance();</pre>
  71.      *
  72.      * @static
  73.      * @access public
  74.      * @return object The global JAuthenticate object
  75.      * @since 1.5
  76.      */
  77.     function getInstance()
  78.     {
  79.         static $instances;
  80.  
  81.         if (!isset ($instances)) {
  82.             $instances array ();
  83.         }
  84.  
  85.         if (empty ($instances[0])) {
  86.             $instances[0new JAuthenticate();
  87.         }
  88.  
  89.         return $instances[0];
  90.     }
  91.  
  92.     /**
  93.      * Finds out if a set of login credentials are valid by asking all obvserving
  94.      * objects to run their respective authentication routines.
  95.      *
  96.      * @access public
  97.      * @param string     The username.
  98.      * @param string     The password.
  99.      * @return mixed Integer userid for valid user if credentials are valid or boolean false if they are not
  100.      * @since 1.5
  101.      */
  102.     function authenticate($username$password)
  103.     {
  104.         // Initialize variables
  105.         $auth false;
  106.  
  107.         // Get the global event dispatcher object
  108.         $dispatcher &JEventDispatcher::getInstance();
  109.  
  110.         // Time to authenticate the credentials.  Lets fire the auth event
  111.         $results $dispatcher->trigger'onAuthenticate'array($username$password));
  112.  
  113.         /*
  114.          * Check each of the results to see if a valid user ID was returned. and use the
  115.          * first ID to log into the system.
  116.  
  117.          * Any errors raised in the plugin should be returned via the JAuthenticateResponse
  118.          * and handled appropriately.
  119.          */
  120.         foreach($results as $result)
  121.         {
  122.             switch($result->status)
  123.             {
  124.                 case JAUTHENTICATE_STATUS_SUCCESS :
  125.                 {
  126.                     if(empty($result->username)) {
  127.                         $result->username $username;
  128.                     }
  129.  
  130.                     if(empty($result->fullname)) {
  131.                         $result->fullname $username;
  132.                     }
  133.  
  134.                     //TODO :: this needs to be changed, should only return at the end
  135.                     return $result;
  136.  
  137.                 }    break;
  138.  
  139.                 case JAUTHENTICATE_STATUS_CANCEL :
  140.                 {
  141.                     jimport('joomla.utilities.log');
  142.                     $log JLog::getInstance();
  143.                     $errorlog array();
  144.                     $errorlog['status'$result->type " CANCELED: ";
  145.                     $errorlog['comment'$result->error_message;
  146.                     $log->addEntry($errorlog);
  147.                     // do nothing
  148.                 break;
  149.  
  150.                 case JAUTHENTICATE_STATUS_FAILURE :
  151.                 {
  152.                     jimport('joomla.utilities.log');
  153.                     $log JLog::getInstance();
  154.                     $errorlog array();
  155.                     $errorlog['status'$result->type " FAILURE: ";
  156.                     $errorlog['comment'$result->error_message;
  157.                     $log->addEntry($errorlog);
  158.                     //do nothing
  159.                 }    break;
  160.  
  161.                 default :
  162.                 {
  163.                     jimport('joomla.utilities.log');
  164.                     $log JLog::getInstance();
  165.                     $errorlog array();
  166.                     $errorlog['status'$result->type " UNKNOWN ERROR: ";
  167.                     $errorlog['comment'$result->error_message;
  168.                     $log->addEntry($errorlog);
  169.                     //do nothing
  170.                 }    break;
  171.             }
  172.         }
  173.  
  174.         return false;
  175.     }
  176.  
  177.     /**
  178.      * Static method to load an auth plugin and attach it to the JEventDispatcher
  179.      * object.
  180.      *
  181.      * This method should be invoked as:
  182.      *         <pre>  $isLoaded = JAuthenticate::loadPlugin($plugin, $subject);</pre>
  183.      *
  184.      * @access public
  185.      * @static
  186.      * @param string $plugin The authentication plugin to use.
  187.      * @param object $subject Observable object for the plugin to observe
  188.      * @return boolean True if plugin is loaded
  189.      * @since 1.5
  190.      */
  191.     function loadPlugin($plugin$subject)
  192.     {
  193.         static $instances;
  194.  
  195.         if (!isset ($instances)) {
  196.             $instances array ();
  197.         }
  198.  
  199.         if (empty ($instances[$plugin])) {
  200.  
  201.             if(JPluginHelper::importPlugin('authentication'$plugin)) {
  202.                 // Build authentication plugin classname
  203.                 $name 'plgAuthenticate'.$plugin;
  204.                 $instances[$pluginnew $name ($subject);
  205.             }
  206.         }
  207.         return is_object($instances[$plugin]);
  208.     }
  209. }
  210.  
  211. /**
  212.  * Authorization response class, provides an object for storing user and error details
  213.  *
  214.  * @author         Samuel Moffatt <[email protected]>
  215.  * @package     Joomla.Framework
  216.  * @subpackage    User
  217.  * @since        1.5
  218.  */
  219. {
  220.     /**
  221.      * User type (refers to the authentication method used)
  222.      *
  223.      * @var name string
  224.      * @access public
  225.      */
  226.     var $type    = '';
  227.  
  228.     /**
  229.      * Response status (see status codes)
  230.      *
  231.      * @var type string
  232.      * @access public
  233.      */
  234.     var $status         = 4;
  235.  
  236.     /**
  237.      *  The error message
  238.      *
  239.      * @var error_message string
  240.      * @access public
  241.      */
  242.     var $error_message     = '';
  243.  
  244.     /**
  245.      * Any UTF-8 string that the End User wants to use as a username.
  246.      *
  247.      * @var fullname string
  248.      * @access public
  249.      */
  250.     var $username         = '';
  251.  
  252.     /**
  253.      * The email address of the End User as specified in section 3.4.1 of [RFC2822]
  254.      *
  255.      * @var email string
  256.      * @access public
  257.      */
  258.     var $email            = '';
  259.  
  260.     /**
  261.      * UTF-8 string free text representation of the End User's full name.
  262.      *
  263.      * @var fullname string
  264.      * @access public
  265.      */
  266.     var $fullname         = '';
  267.  
  268.     /**
  269.      * The End User's date of birth as YYYY-MM-DD. Any values whose representation uses
  270.      * fewer than the specified number of digits should be zero-padded. The length of this
  271.      * value MUST always be 10. If the End User user does not want to reveal any particular
  272.      * component of this value, it MUST be set to zero.
  273.      *
  274.      * For instance, if a End User wants to specify that his date of birth is in 1980, but
  275.      * not the month or day, the value returned SHALL be "1980-00-00".
  276.      *
  277.      * @var fullname string
  278.      * @access public
  279.      */
  280.     var $birthdate         = '';
  281.  
  282.     /**
  283.      * The End User's gender, "M" for male, "F" for female.
  284.      *
  285.      * @var fullname string
  286.      * @access public
  287.      */
  288.     var $gender         = '';
  289.  
  290.     /**
  291.      * UTF-8 string free text that SHOULD conform to the End User's country's postal system.
  292.      *
  293.      * @var fullname string
  294.      * @access public
  295.      */
  296.     var $postcode         = '';
  297.  
  298.     /**
  299.      * The End User's country of residence as specified by ISO3166.
  300.      *
  301.      * @var fullname string
  302.      * @access public
  303.      */
  304.     var $country         = '';
  305.  
  306.     /**
  307.      * End User's preferred language as specified by ISO639.
  308.      *
  309.      * @var fullname string
  310.      * @access public
  311.      */
  312.     var $language         = '';
  313.  
  314.     /**
  315.      * ASCII string from TimeZone database
  316.      *
  317.      * @var fullname string
  318.      * @access public
  319.      */
  320.     var $timezone         = '';
  321.  
  322.     /**
  323.      * Constructor
  324.      *
  325.      * @param string $name The type of the response
  326.      * @since 1.5
  327.      */
  328.     function __construct($type{
  329.         $this->type = $type;
  330.     }
  331. }
  332. ?>

Documentation generated on Mon, 05 Mar 2007 20:52:43 +0000 by phpDocumentor 1.3.1