diff options
| -rw-r--r-- | client/js/controllers/home/main.js | 2 | ||||
| -rw-r--r-- | client/js/services/Compute.js | 21 | ||||
| -rw-r--r-- | client/js/services/Identity.js | 46 | ||||
| -rwxr-xr-x | server/core/App.php | 1 | ||||
| -rw-r--r-- | server/core/Image.php | 571 | ||||
| -rwxr-xr-x[-rw-r--r--] | server/core/LibOverride/genTokenOptions.php | 10 |
6 files changed, 487 insertions, 164 deletions
diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js index d93c376..4e3bcda 100644 --- a/client/js/controllers/home/main.js +++ b/client/js/controllers/home/main.js @@ -13,6 +13,8 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', function ($s // Retrieve all Data Compute.pullData(updatePage); + Compute.getMachines(function(adzda){}); + $scope.raiseShowMachineDetailsEvent=function(){ var machine={name: "Machine 1", online:true}; $rootScope.$broadcast("showMachineDetailsEvent", machine); diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index 70359ee..8148948 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -2,11 +2,12 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ - + // Create data var data={}; data.machines={}; + // Parser var parseGetMachinesAnswer=function(response, failedToSendRequest){ @@ -16,8 +17,24 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ // Get Machine var getMachines=function(callback){ + var params={ + "token" : Identity.getToken(), + "task" : "compute", + "action":"getServer", + "serverId":"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd" + }; + var result=$http.post('../server/index.php', - $.param({"token" : Identity.profile.token, "task" : "Compute"})); + $.param(params)); + + // Wait and handle the response + result.then(function (response){ + console.log(response.data.Servers); + callback(parseGetMachinesAnswer(response, false)); + },function(response){ + alert(response.status); + callback(parseGetMachinesAnswer(response, true)); + }); }; diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 7604230..b1d2a48 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -9,42 +9,37 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ profile.projectname=null; var token=null; + /* * @returns {boolean} Return true if a cookie is found (and load it in profile) false else */ var isAlreadyLogin=function(){ + + // Load cookies var profileInCookie=$cookies.getObject('profile'); var tokenPart_0InCookie=$cookies.getObject('token.part_0'); var tokenPart_1InCookie=$cookies.getObject('token.part_1'); + // Check if cookie is defined if(typeof profileInCookie !== 'undefined' && typeof tokenPart_0InCookie !== 'undefined' && typeof tokenPart_1InCookie !== 'undefined' ){ + + // If yes, put it into variables angular.extend(profile, profileInCookie); token=tokenPart_0InCookie+tokenPart_1InCookie; - + + // Return I'm Login return true; } + // Return I'm not Login return false; } - /* - * Get the profile - */ - var getProfile=function(){ - return profile; - } - - /* - * Get the token - */ - var getToken=function(){ - return token; - } /* * Destroy profile cookies @@ -64,7 +59,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ */ var parseLoginAnswer=function(response, failedToSendRequest){ - + // Defined return object var requestParserResult={}; requestParserResult.status=1; requestParserResult.failReason=null; @@ -96,6 +91,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ return requestParserResult; }; + /** * Function to connect to OpenStack @@ -113,17 +109,31 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ profile.projectname=projectname; var result=$http.post('../server/index.php', - $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname})); + $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname})); // Wait and handle the response result.then(function (response){ - callback(parseLoginAnswer(response), false); + callback(parseLoginAnswer(response, false)); },function(response){ - callback(parseLoginAnswer(response), true) + callback(parseLoginAnswer(response, true)); }); }; + /* + * Get the profile + */ + var getProfile=function(){ + return profile; + } + + /* + * Get the token + */ + var getToken=function(){ + return token; + } + // Return services objects return { diff --git a/server/core/App.php b/server/core/App.php index 282a1db..edb75f6 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -105,6 +105,7 @@ class App{ public function show(){
echo json_encode($this->output);
+ //error_log(var_dump(json_encode($this->output), true), 0);
}
}
diff --git a/server/core/Image.php b/server/core/Image.php index 3001eea..4025595 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -1,7 +1,4 @@ <?php - -//require 'CoreInterface.php'; - /** * File containing the Image Class. * @@ -12,16 +9,18 @@ * * @todo Complete the functions with errors detection and finish the descriptions */ - - +use OpenStack\Common\Error\BadResponseError; +use OpenStack\Common\Error\BaseError; +use OpenStack\Common\Error\NotImplementedError; +use OpenStack\Common\Error\UserInputError; + /** * Image Class of the back-end application * * ADD CLASS DESCRIPTION * */ -class image{ - //implements Core +class image implements Core{ /** @var App $app protected, contains the main app object */ protected $app; @@ -29,10 +28,6 @@ class image{ /** @var OpenStack\Identity $libClass protected, contains the library Identity object */ protected $libClass; - /** @var array $actions protected, contains the functions which can be call by the front-end */ - protected $actions = array(); - - /** * Image constructor * @@ -43,12 +38,36 @@ class image{ * @return Image */ public function __construct($app){ - $this->app = $app; - $this->libClass = $app->getLibClass("Image"); + if(!isset($app)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + $this->app = $app; + $this->libClass = $app->getLibClass("Image"); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } - + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + + $this->{$action.""}(); + + } /** * Details about an image @@ -57,55 +76,96 @@ class image{ * options for the image creation * **/ - public function create_image(array $opt){ - // VOIR SI MAUVAIS TYPE - $options = Array(); - if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris - } - else{ - //ERROR - } - if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn - $options['id'] = $opt['id']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker - $options['containerFormat'] = $opt['containerFormat']; - } - if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso - $options['diskFormat'] = $opt['diskFormat']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; + private function createImage(array $opt){ + + if(!isset($opt)){ + $this->app->setOutput("Error", "Incorrect parameter"); } - if(isset($opt['properties'])){ // type dict ? - $options['properties'] = $opt['properties']; - } - $image = $this->oidentity->createImage($options); + try{ + // VOIR SI MAUVAIS TYPE + $options = Array(); + if(isset($opt['name'])){ // if the image name already exists -> error + $imagesList = listImage(); + if(isset($images)){ + foreach($imagesList as $image){ + if(strcmp($image->name, $opt['name']) == 0){ + + } + } + } + + } + else{ + $this->app->setOutput("Error", "Image name already exists"); + } + if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn + if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error + + } + $options['id'] = $opt['id']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker + $options['containerFormat'] = $opt['containerFormat']; + } + if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso + $options['diskFormat'] = $opt['diskFormat']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['properties'])){ // type dict ? + $options['properties'] = $opt['properties']; + } + + $image = $this->libClass->createImage($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $image; } - /* - * List images + /** + * List the images of the server + * + * @return the list with all images on the server */ - public function list_images(){ - // vérifier si au moins une image - $service = $this->oidentity; - $images = $service->listImages(); - return $images; + private function listImage(){ + try{ + $l = $this->libClass->listImages(); + if(!isset($l)){ // if the list is empty there is no images + $this->app->setOutput("Error", "No image"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + return $l; + } /** @@ -115,11 +175,27 @@ class image{ * identifier of the image * **/ - public function image_details($id){ - //vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - return $image; + private function detailsImage($id){ + if(!isset($id)){ + // Renvoyer erreur + } + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + + return $image; + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -131,33 +207,53 @@ class image{ * @param array $opt * options for the image creation **/ - public function update_image($id, array $opt){ - //vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $options = Array(); - - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; + private function updateImage($id, array $opt){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect id parameter"); } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; + if(!isset($opt)){ + $this->app->setOutput("Error", "Incorrect opt parameter"); } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + + $options = Array(); + + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $image; } @@ -167,11 +263,30 @@ class image{ * @param string $id * identifier of the image **/ - public function delete_image($id){ + private function deleteImage($id){ // si protected = true, demander de le mettre a false // vérifier existence image - $service = $this->oidentity; - $service->getImage($id)->delete(); + if(!isset($id)){ + $this->app->setOutput("Error", "Image doesn't exist"); + } + + try{ + $service = $this->libClass; + $image = $this->libClass->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } /** @@ -180,11 +295,27 @@ class image{ * @param string $id * identifier of the image **/ - public function reactivate_image($id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $image->reactivate(); + private function reactivateImage($id){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->reactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -193,11 +324,27 @@ class image{ * @param string $id * identifier of the image **/ - public function desactivate_image($id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $image->deactivate(); + private function desactivateImage($id){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->deactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -209,12 +356,31 @@ class image{ * @param string $file_name * path of the image **/ - public function upload_image($id, $file_name){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR - $image->uploadData($stream); + private function uploadImage($id, $file_name){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect id parameter"); + } + if(!isset($file_name)){ + $this->app->setOutput("Error", "Incorrect file_name parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $image->uploadData($stream); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -223,12 +389,28 @@ class image{ * @param string $id * identifier of the image **/ - public function download_image($id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $stream = $image->downloadData(); - return $stream; + private function downloadImage($id){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = $image->downloadData(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + return $stream; } /** @@ -240,12 +422,30 @@ class image{ * @param string $member_id * identifier of the member **/ - public function add_member($image_id, $member_id){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $member_id = $service>getImage($image_id)->addMember($member_id); + private function addMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member_id = $image->addMember($member_id); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } @@ -255,11 +455,33 @@ class image{ * @param string $image_id * identifier of the image **/ - public function list_member($image_id, $member_id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($image_id); - $members = $image->listMembers(); + private function listMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $members = $image->listMembers(); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "No member"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $members; } @@ -272,12 +494,37 @@ class image{ * @param string $member_id * identifier of the member **/ - public function detail_member($image_id, $member_id){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $member = $service>getImage($image_id)->getMember($member_id); + private function detailMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $member; } @@ -290,12 +537,34 @@ class image{ * @param string $member_id * identifier of the member **/ - public function remove_member($image_id, $member_id){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $service>getImage($image_id)->getMember($member_id)->delete(); + private function removeMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -310,13 +579,35 @@ class image{ * @param string $status * new status for the member **/ - public function update_member($image_id, $member_id, $status){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); + private function updateMemberImage($image_id, $member_id, $status){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->updateStatus($status); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } } -?> +?>
\ No newline at end of file diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index b71defa..50826ed 100644..100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -260,13 +260,14 @@ class genTokenOptions public function loadBackup($back){ $backup = unserialize($back); + $this->backup["roles"] = $backup["roles"]; $this->backup["project"] = $backup["project"]; $this->backup["user"] = $backup["user"]; - loadComputeBackup($backup["Compute"]); - loadIdentityBackup($backup["Identity"]); - loadImageBackup($backup["Image"]); - loadNetworkBackup($backup["Network"]); + $this->loadComputeBackup($backup["Compute"]); + $this->loadIdentityBackup($backup["Identity"]); + $this->loadImageBackup($backup["Image"]); + $this->loadNetworkBackup($backup["Network"]); } @@ -324,6 +325,7 @@ class genTokenOptions private function unserializeToken($tokenSerialized){ $Saved = file_get_contents("core/LibOverride/projectTokenData/".$this->backup["project"]); + $Saved = unserialize($Saved); $api = new Api(); $token = new Models\Token($this->httpClient, $api); $token->methods = unserialize($tokenSerialized["methods"]); |
