Skip to content

Commit

Permalink
Task techjoomla#63 feat: Add support to JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
Amol Thite committed Oct 8, 2018
1 parent 584bca3 commit 7e9189c
Show file tree
Hide file tree
Showing 35 changed files with 2,513 additions and 63 deletions.
51 changes: 23 additions & 28 deletions code/site/api.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<?php
/**
* @package Joomla.Site
* @subpackage Com_api
* @package Com.Api
*
* @copyright Copyright (C) 2009-2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://techjoomla.com
* Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API)
* and the com_api extension by Brian Edgerton (http://www.edgewebworks.com)
* @copyright Copyright (C) 2005 - 2017 Techjoomla, Techjoomla Pvt. Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

$library_path = JPATH_COMPONENT . '/libraries';

JLoader::register('APIController', $library_path . '/controller.php');
JLoader::register('APIModel', $library_path . '/model.php');
JLoader::register('APIView', $library_path . '/view.php');
JLoader::register('APIPlugin', $library_path . '/plugin.php');
JLoader::register('APIError', $library_path . '/error.php');
JLoader::register('ApiException', $library_path . '/exception.php');
JLoader::register('APICache', $library_path . '/cache.php');
JLoader::register('APIResource', $library_path . '/resource.php');
JLoader::register('APIAuthentication', $library_path . '/authentication.php');
JLoader::register('APIAuthenticationKey', $library_path . '/authentication/key.php');
JLoader::register('APIAuthenticationLogin', $library_path . '/authentication/login.php');
JLoader::register('APIAuthenticationSession', $library_path . '/authentication/session.php');
JLoader::register('APIHelper', $library_path . '/helper.php');
$libraryPath = JPATH_COMPONENT . '/libraries';

JLoader::register('APIController', $libraryPath . '/controller.php');
JLoader::register('APIModel', $libraryPath . '/model.php');
JLoader::register('APIView', $libraryPath . '/view.php');
JLoader::register('APIPlugin', $libraryPath . '/plugin.php');
JLoader::register('APIError', $libraryPath . '/error.php');
JLoader::register('ApiException', $libraryPath . '/exception.php');
JLoader::register('APICache', $libraryPath . '/cache.php');
JLoader::register('APIResource', $libraryPath . '/resource.php');
JLoader::register('APIAuthentication', $libraryPath . '/authentication.php');
JLoader::register('APIAuthenticationKey', $libraryPath . '/authentication/key.php');
JLoader::register('APIAuthenticationLogin', $libraryPath . '/authentication/login.php');
JLoader::register('APIAuthenticationSession', $libraryPath . '/authentication/session.php');
JLoader::register('APIHelper', $libraryPath . '/helper.php');
JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_api/tables');
JLoader::discover('API', JPATH_COMPONENT . '/libraries/exceptions');

Expand All @@ -44,21 +40,20 @@
$c = $app->input->get('c', 'http', 'CMD');
}

$c_path = JPATH_COMPONENT . '/controllers/' . strtolower($c) . '.php';
$controllerPath = JPATH_COMPONENT . '/controllers/' . strtolower($c) . '.php';

if (file_exists($c_path))
if (file_exists($controllerPath))
{
include_once $c_path;
$c_name = 'ApiController' . ucwords($c);
include_once $controllerPath;
$className = 'ApiController' . ucwords($c);
}
else
{
// JError::raiseError(404, JText::_('COM_API_CONTROLLER_NOT_FOUND'));
throw new Exception(JText::_('COM_API_CONTROLLER_NOT_FOUND'), 404);
}

$command = $app->input->get('task', 'display', 'CMD');

$controller = new $c_name;
$controller = new $className;
$controller->execute($command);
$controller->redirect();
31 changes: 17 additions & 14 deletions code/site/controllers/http.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* @package Joomla.Site
* @subpackage Com_api
* @package Com.Api
*
* @copyright Copyright (C) 2009-2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://techjoomla.com
* Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API)
* and the com_api extension by Brian Edgerton (http://www.edgewebworks.com)
* @copyright Copyright (C) 2005 - 2017 Techjoomla, Techjoomla Pvt. Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');
Expand All @@ -21,6 +18,12 @@
*/
class ApiControllerHttp extends ApiController
{
/**
* Used to find callback in the url
*
* @var string
* @since 1.0
*/
public $callbackname = 'callback';

/**
Expand All @@ -29,7 +32,7 @@ class ApiControllerHttp extends ApiController
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return Mixed
* @return void
*
* @since 12.2
*/
Expand Down Expand Up @@ -79,9 +82,9 @@ public function display($cachable = false, $urlparams = array())
try
{
JResponse::setHeader('status', 200);
$resource_response = ApiPlugin::getInstance($name)->fetchResource();
$resourceResponse = ApiPlugin::getInstance($name)->fetchResource();

echo $this->respond($resource_response);
echo $this->respond($resourceResponse);
}
catch (Exception $e)
{
Expand All @@ -95,7 +98,7 @@ public function display($cachable = false, $urlparams = array())
*
* @param OBJECT $response exception
*
* @return json
* @return void
*
* @since 2.0
*/
Expand Down Expand Up @@ -140,11 +143,11 @@ private function respond($response)
break;
}

$output_overrride = JPATH_ROOT . '/templates/' . $app->getTemplate() . '/' . $format . '/api.php';
$outputOverrride = JPATH_ROOT . '/templates/' . $app->getTemplate() . '/' . $format . '/api.php';

if (file_exists($output_overrride))
if (file_exists($outputOverrride))
{
require_once $output_overrride;
require_once $outputOverrride;
}
else
{
Expand Down
17 changes: 9 additions & 8 deletions code/site/helpers/menus.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
/**
* @package com_api
* @copyright Copyright (C) 2009 2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://techjoomla.com
* Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API)
* and the com_api extension by Brian Edgerton (http://www.edgewebworks.com)
*/
* @package Com.Api
*
* @copyright Copyright (C) 2005 - 2017 Techjoomla, Techjoomla Pvt. Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Just as a place holder to include the correct helper file
require_once JPATH_ADMINISTRATOR.'/components/com_menus/helpers/menus.php';

// @FIXME Find the purpose of this file and remove it
require_once JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php';
Loading

0 comments on commit 7e9189c

Please sign in to comment.