Guest User

Untitled

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