10 defined(
'JPATH_PLATFORM') or die;
27 const STATUS_SUCCESS = 1;
35 const STATUS_CANCEL = 2;
42 const STATUS_FAILURE = 4;
50 const STATUS_EXPIRED = 8;
57 const STATUS_DENIED = 16;
64 const STATUS_UNKNOWN = 32;
72 protected $observers = array();
80 protected $state = null;
88 protected $methods = array();
101 public function __construct()
103 $isLoaded = JPluginHelper::importPlugin(
'authentication');
119 public static function getInstance()
121 if (empty(self::$instance))
126 return self::$instance;
136 public function getState()
150 public function attach($observer)
152 if (is_array($observer))
154 if (!isset($observer[
'handler']) || !isset($observer[
'event']) || !is_callable($observer[
'handler']))
160 foreach ($this->observers as $check)
162 if (is_array($check) && $check[
'event'] == $observer[
'event'] && $check[
'handler'] == $observer[
'handler'])
168 $this->observers[] = $observer;
169 end($this->observers);
170 $methods = array($observer[
'event']);
180 $class = get_class($observer);
182 foreach ($this->observers as $check)
184 if ($check instanceof $class)
190 $this->observers[] = $observer;
191 $methods = array_diff(get_class_methods($observer), get_class_methods(
'JPlugin'));
194 $key = key($this->observers);
196 foreach ($methods as $method)
198 $method = strtolower($method);
200 if (!isset($this->methods[$method]))
202 $this->methods[$method] = array();
205 $this->methods[$method][] = $key;
218 public function detach($observer)
222 $key = array_search($observer, $this->observers);
226 unset($this->observers[$key]);
229 foreach ($this->methods as &$method)
231 $k = array_search($key, $method);
255 public function authenticate($credentials, $options = array())
258 $plugins = JPluginHelper::getPlugin(
'authentication');
270 foreach ($plugins as $plugin)
272 $className =
'plg' . $plugin->type . $plugin->name;
274 if (class_exists($className))
276 $plugin =
new $className($this, (array) $plugin);
286 $plugin->onUserAuthenticate($credentials, $options, $response);
289 if ($response->status === self::STATUS_SUCCESS)
291 if (empty($response->type))
293 $response->type = isset($plugin->_name) ? $plugin->_name : $plugin->name;
299 if (empty($response->username))
301 $response->username = $credentials[
'username'];
304 if (empty($response->fullname))
306 $response->fullname = $credentials[
'username'];
309 if (empty($response->password) && isset($credentials[
'password']))
311 $response->password = $credentials[
'password'];
327 public static function authorise($response, $options = array())
330 JPluginHelper::importPlugin(
'user');
332 JPluginHelper::importPlugin(
'authentication');
334 $results = $dispatcher->trigger(
'onUserAuthorisation', array($response, $options));