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->setSupportedFormats('JsonFormat', 'XmlFormat');
|
||||
$namespace = 'Services_Rest_';
|
||||
|
||||
// override global REQUEST_URI to pass to Restler library
|
||||
$_SERVER['REQUEST_URI'] = $uri;
|
||||
$_SERVER['REQUEST_URI'] = '/' . strtolower($namespace) . ltrim($uri, '/');
|
||||
|
||||
// getting all services class
|
||||
$srvClasses = glob(PATH_SERVICES_REST . '*.php');
|
||||
|
||||
foreach ($srvClasses as $classFile) {
|
||||
require_once $classFile;
|
||||
$className = str_replace('.php', '', basename($classFile));
|
||||
|
||||
$className = $namespace . str_replace('.php', '', basename($classFile));
|
||||
$reflClass = new ReflectionClass($className);
|
||||
|
||||
// verify if there is an auth class implementing 'iAuthenticate'
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
<?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.
|
||||
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 {
|
||||
// get a specific record.
|
||||
G::loadClass('wsBase');
|
||||
$case = new wsBase();
|
||||
$case->getCaseInfo($id);
|
||||
$wsBase = new wsBase();
|
||||
return $wsBase->getCaseInfo($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
G::LoadClass('sessions');
|
||||
G::LoadClass('wsBase');
|
||||
|
||||
class Auth implements iAuthenticate
|
||||
class Services_Rest_Auth implements iAuthenticate
|
||||
{
|
||||
public $realm = 'Restricted API';
|
||||
|
||||
public static $userId = '';
|
||||
public static $authKey = '';
|
||||
|
||||
function __isAuthenticated()
|
||||
{
|
||||
if (array_key_exists('HTTP_AUTH_KEY', $_SERVER)) {
|
||||
@@ -20,18 +23,13 @@ class Auth implements iAuthenticate
|
||||
$session = $sessions->verifySession($authKey);
|
||||
|
||||
if (is_array($session)) {
|
||||
$sesInfo = $sessions->getSessionUser($authKey);
|
||||
self::$userId = $sesInfo['USR_UID'];
|
||||
self::$authKey = $authKey;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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('sessions');
|
||||
|
||||
class Login
|
||||
class Services_Rest_Login
|
||||
{
|
||||
public function post($user, $passwd)
|
||||
{
|
||||
@@ -12,7 +12,6 @@ class Login
|
||||
if ($result->status_code == 0) {
|
||||
return array(
|
||||
'auth_key' => $result->message,
|
||||
//'timestamp' => $result->timestamp,
|
||||
);
|
||||
} else {
|
||||
throw new RestException(401, $result->message);
|
||||
|
||||
Reference in New Issue
Block a user