function getJMUserID() { static $user_id; if (!$user_id) { $user_id = JMAuthentication::getInstance()->authenticate(); } return $user_id; }
function __construct(JMPlugin $plugin) { parent::__construct($plugin); $auth_handler = JMAuthentication::getInstance('user'); $user_id = $auth_handler->authenticate(); if (false === $user_id) { throw new Exception($auth_handler->getError(), 403); } $this->plugin->setResourceAccess(array('token'), 'public'); // $this->plugin->set('skip_request_limit', true); $this->plugin->set('user', $user_id); }
/** * Finds and calls the requested resource * @param string $resource_name Requested resource name * @return string */ public final function fetchResource($resource_name = null) { if ($resource_name == null) { $resource_name = $this->get('resource'); } $resource_obj = JMResource::getInstance($resource_name, $this); if ($resource_obj === false) { $this->checkInternally($resource_name); } $access = $this->getResourceAccess($resource_name, $this->request_method); if ($access == 'protected') { $auth_handler = JMAuthentication::getInstance(); $user = $auth_handler->authenticateRequest(); if ($user === false) { throw new Exception($auth_handler->getError(), 403); } $this->set('user', $user); } if (!$this->checkRequestLimit()) { throw new Exception(JText::_('COM_JM_RATE_LIMIT_EXCEEDED'), 403); } $this->log(); if ($resource_obj !== false) { $resource_obj->invoke(); } else { call_user_func(array($this, $resource_name)); } $output = $this->encode(); return $output; }