Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/libraries/joomla/user/authentication.php
f43d1a4680a9
6.3 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | <?php
/**
* @version $Id: authentication.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla.Framework
* @subpackage User
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
jimport('joomla.base.observable');
/**
* This is the status code returned when the authentication is success.
*/
define('JAUTHENTICATE_STATUS_SUCCESS', 1);
/**
* Status to indicate cancellation of authentication.
*/
define('JAUTHENTICATE_STATUS_CANCEL', 2);
/**
* This is the status code returned when the authentication failed
*/
define('JAUTHENTICATE_STATUS_FAILURE', 4);
/**
* Authenthication class, provides an interface for the Joomla authentication system
*
* @package Joomla.Framework
* @subpackage User
* @since 1.5
*/
class JAuthentication extends JObservable
{
/**
* Constructor
*
* @access protected
*/
function __construct()
{
$isLoaded = JPluginHelper::importPlugin('authentication');
if (!$isLoaded) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('JAuthentication::__construct: Could not load authentication libraries.'));
}
}
/**
* Returns a reference to a global authentication object, only creating it
* if it doesn't already exist.
*
* This method must be invoked as:
* <pre> $auth = &JAuthentication::getInstance();</pre>
*
* @static
* @access public
* @return object The global JAuthentication object
* @since 1.5
*/
function & getInstance()
{
static $instances;
if (!isset ($instances)) {
$instances = array ();
}
if (empty ($instances[0])) {
$instances[0] = new JAuthentication();
}
return $instances[0];
}
/**
* Finds out if a set of login credentials are valid by asking all obvserving
* objects to run their respective authentication routines.
*
* @access public
* @param array Array holding the user credentials
* @return mixed Integer userid for valid user if credentials are valid or
* boolean false if they are not
* @since 1.5
*/
function authenticate($credentials, $options)
{
// Initialize variables
$auth = false;
// Get plugins
$plugins = JPluginHelper::getPlugin('authentication');
// Create authencication response
$response = new JAuthenticationResponse();
/*
* Loop through the plugins and check of the creditials can be used to authenticate
* the user
*
* Any errors raised in the plugin should be returned via the JAuthenticationResponse
* and handled appropriately.
*/
foreach ($plugins as $plugin)
{
$className = 'plg'.$plugin->type.$plugin->name;
if (class_exists( $className )) {
$plugin = new $className($this, (array)$plugin);
}
// Try to authenticate
$plugin->onAuthenticate($credentials, $options, $response);
// If authentication is successfull break out of the loop
if($response->status === JAUTHENTICATE_STATUS_SUCCESS)
{
if (empty( $response->type )) {
$response->type = isset( $plugin->_name ) ? $plugin->_name : $plugin->name;
}
if (empty( $response->username )) {
$response->username = $credentials['username'];
}
if (empty( $response->fullname )) {
$response->fullname = $credentials['username'];
}
if (empty( $response->password )) {
$response->password = $credentials['password'];
}
break;
}
}
return $response;
}
}
/**
* Authorization response class, provides an object for storing user and error details
*
* @package Joomla.Framework
* @subpackage User
* @since 1.5
*/
class JAuthenticationResponse extends JObject
{
/**
* Response status (see status codes)
*
* @var type string
* @access public
*/
var $status = JAUTHENTICATE_STATUS_FAILURE;
/**
* The type of authentication that was successful
*
* @var type string
* @access public
*/
var $type = '';
/**
* The error message
*
* @var error_message string
* @access public
*/
var $error_message = '';
/**
* Any UTF-8 string that the End User wants to use as a username.
*
* @var fullname string
* @access public
*/
var $username = '';
/**
* Any UTF-8 string that the End User wants to use as a password.
*
* @var password string
* @access public
*/
var $password = '';
/**
* The email address of the End User as specified in section 3.4.1 of [RFC2822]
*
* @var email string
* @access public
*/
var $email = '';
/**
* UTF-8 string free text representation of the End User's full name.
*
* @var fullname string
* @access public
*/
var $fullname = '';
/**
* The End User's date of birth as YYYY-MM-DD. Any values whose representation uses
* fewer than the specified number of digits should be zero-padded. The length of this
* value MUST always be 10. If the End User user does not want to reveal any particular
* component of this value, it MUST be set to zero.
*
* For instance, if a End User wants to specify that his date of birth is in 1980, but
* not the month or day, the value returned SHALL be "1980-00-00".
*
* @var fullname string
* @access public
*/
var $birthdate = '';
/**
* The End User's gender, "M" for male, "F" for female.
*
* @var fullname string
* @access public
*/
var $gender = '';
/**
* UTF-8 string free text that SHOULD conform to the End User's country's postal system.
*
* @var fullname string
* @access public
*/
var $postcode = '';
/**
* The End User's country of residence as specified by ISO3166.
*
* @var fullname string
* @access public
*/
var $country = '';
/**
* End User's preferred language as specified by ISO639.
*
* @var fullname string
* @access public
*/
var $language = '';
/**
* ASCII string from TimeZone database
*
* @var fullname string
* @access public
*/
var $timezone = '';
/**
* Constructor
*
* @param string $name The type of the response
* @since 1.5
*/
function __construct() { }
}
|