PM Rest: adding first action for GET method of application api class
This commit is contained in:
@@ -5175,16 +5175,18 @@ function getDirectorySize($path,$maxmtime=0)
|
|||||||
|
|
||||||
$rest = new Restler();
|
$rest = new Restler();
|
||||||
$rest->setSupportedFormats('JsonFormat', 'XmlFormat');
|
$rest->setSupportedFormats('JsonFormat', 'XmlFormat');
|
||||||
|
$namespace = 'Services_Rest_';
|
||||||
|
|
||||||
// override global REQUEST_URI to pass to Restler library
|
// override global REQUEST_URI to pass to Restler library
|
||||||
$_SERVER['REQUEST_URI'] = $uri;
|
$_SERVER['REQUEST_URI'] = '/' . strtolower($namespace) . ltrim($uri, '/');
|
||||||
|
|
||||||
// getting all services class
|
// getting all services class
|
||||||
$srvClasses = glob(PATH_SERVICES_REST . '*.php');
|
$srvClasses = glob(PATH_SERVICES_REST . '*.php');
|
||||||
|
|
||||||
foreach ($srvClasses as $classFile) {
|
foreach ($srvClasses as $classFile) {
|
||||||
require_once $classFile;
|
require_once $classFile;
|
||||||
$className = str_replace('.php', '', basename($classFile));
|
|
||||||
|
$className = $namespace . str_replace('.php', '', basename($classFile));
|
||||||
$reflClass = new ReflectionClass($className);
|
$reflClass = new ReflectionClass($className);
|
||||||
|
|
||||||
// verify if there is an auth class implementing 'iAuthenticate'
|
// verify if there is an auth class implementing 'iAuthenticate'
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Application
|
class Services_Rest_Application
|
||||||
{
|
{
|
||||||
protected function get($id = null)
|
protected function get($id = '', $type = null, $start = null, $limit = null)
|
||||||
{
|
{
|
||||||
if (is_null($id)) {
|
if (empty($id)) {
|
||||||
// getting all records.
|
// getting all records.
|
||||||
G::loadClass('applications');
|
G::loadClass('applications');
|
||||||
$app->getAll($userUid, $start=null, $limit=null, $action=null);
|
$app = new Applications();
|
||||||
|
$userUid = Services_Rest_Auth::$userId;
|
||||||
|
|
||||||
|
return $app->getAll($userUid, $start, $limit, $type);
|
||||||
} else {
|
} else {
|
||||||
// get a specific record.
|
// get a specific record.
|
||||||
G::loadClass('wsBase');
|
G::loadClass('wsBase');
|
||||||
$case = new wsBase();
|
$wsBase = new wsBase();
|
||||||
$case->getCaseInfo($id);
|
return $wsBase->getCaseInfo($id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,13 @@
|
|||||||
G::LoadClass('sessions');
|
G::LoadClass('sessions');
|
||||||
G::LoadClass('wsBase');
|
G::LoadClass('wsBase');
|
||||||
|
|
||||||
class Auth implements iAuthenticate
|
class Services_Rest_Auth implements iAuthenticate
|
||||||
{
|
{
|
||||||
public $realm = 'Restricted API';
|
public $realm = 'Restricted API';
|
||||||
|
|
||||||
|
public static $userId = '';
|
||||||
|
public static $authKey = '';
|
||||||
|
|
||||||
function __isAuthenticated()
|
function __isAuthenticated()
|
||||||
{
|
{
|
||||||
if (array_key_exists('HTTP_AUTH_KEY', $_SERVER)) {
|
if (array_key_exists('HTTP_AUTH_KEY', $_SERVER)) {
|
||||||
@@ -20,18 +23,13 @@ class Auth implements iAuthenticate
|
|||||||
$session = $sessions->verifySession($authKey);
|
$session = $sessions->verifySession($authKey);
|
||||||
|
|
||||||
if (is_array($session)) {
|
if (is_array($session)) {
|
||||||
|
$sesInfo = $sessions->getSessionUser($authKey);
|
||||||
|
self::$userId = $sesInfo['USR_UID'];
|
||||||
|
self::$authKey = $authKey;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RestException(401, 'Wrong Credentials!');
|
throw new RestException(401, 'Wrong Credentials!');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @url POST
|
|
||||||
*/
|
|
||||||
public function login($user, $passwd)
|
|
||||||
{
|
|
||||||
$wsBase = new wsBase();
|
|
||||||
return $wsBase->login($user, $passwd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
G::loadClass('wsBase');
|
G::loadClass('wsBase');
|
||||||
G::LoadClass('sessions');
|
G::LoadClass('sessions');
|
||||||
|
|
||||||
class Login
|
class Services_Rest_Login
|
||||||
{
|
{
|
||||||
public function post($user, $passwd)
|
public function post($user, $passwd)
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,6 @@ class Login
|
|||||||
if ($result->status_code == 0) {
|
if ($result->status_code == 0) {
|
||||||
return array(
|
return array(
|
||||||
'auth_key' => $result->message,
|
'auth_key' => $result->message,
|
||||||
//'timestamp' => $result->timestamp,
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new RestException(401, $result->message);
|
throw new RestException(401, $result->message);
|
||||||
|
|||||||
Reference in New Issue
Block a user