From 5a6553232adbd67c5d83f958d3d510d3d0b8b409 Mon Sep 17 00:00:00 2001 From: velz Date: Thu, 20 Sep 2018 12:13:49 +0530 Subject: [PATCH] SINGED URL AND NEW ENTITY BUCKET CREATION --- api/application/config/constants.php | 4 +-- .../Entity_Management_Controller.php | 11 +++++++- .../User_Management_Controller.php | 2 +- api/application/libraries/AWS_S3.php | 6 ++--- .../models/User_Management_Model.php | 25 ++++++++++++++++++- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/api/application/config/constants.php b/api/application/config/constants.php index 59f6682b..68f55acd 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -86,10 +86,10 @@ defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest auto // define login route name for token verification //defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', '(listLessPDDetails/:any)'); // no errors -defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', 'login'); // no errors +defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', 'getListOfUsers'); // no errors /*********************AWS resources Constants*************************************************/ -defined('PROFILEPICTUREBUCKETNAME') OR define('PROFILEPICTUREBUCKETNAME','sineedgedevprofilepic'); +defined('PROFILE_PICTURE_BUCKET_NAME') OR define('PROFILE_PICTURE_BUCKET_NAME','sineedgedevprofilepic'); /*********************AWS resources Constants*************************************************/ diff --git a/api/application/controllers/Entity_Management_Controller.php b/api/application/controllers/Entity_Management_Controller.php index c856a51c..36e76147 100644 --- a/api/application/controllers/Entity_Management_Controller.php +++ b/api/application/controllers/Entity_Management_Controller.php @@ -18,6 +18,7 @@ class Entity_Management_Controller extends REST_Controller { // Construct the parent class parent::__construct(); $this->load->model('Entity_Management_Model'); + $this->load->library('AWS_S3'); } @@ -64,7 +65,15 @@ class Entity_Management_Controller extends REST_Controller { } } - + if($entity_id != '' || $entity_id != null) + { + if($entity['fk_entity_type_id'] == 2)// If New Entity is Lender(2) type then create a S3 bucket. + { + $bucket_name = 'lender'.$entity_id; + $bucket_status = $this->aws_s3->createNewBucket($bucket_name); + + } + } if($entity_id != '' || $entity_id != null) { diff --git a/api/application/controllers/User_Management_Controller.php b/api/application/controllers/User_Management_Controller.php index fa212bf4..275ed13b 100644 --- a/api/application/controllers/User_Management_Controller.php +++ b/api/application/controllers/User_Management_Controller.php @@ -89,7 +89,7 @@ class User_Management_Controller extends REST_Controller { } } - $bucketname = PROFILEPICTUREBUCKETNAME; + $bucketname = PROFILE_PICTURE_BUCKET_NAME; $key = $profilepics3path; $sourcefile = $profilepic; diff --git a/api/application/libraries/AWS_S3.php b/api/application/libraries/AWS_S3.php index 962d24df..a7c958bf 100644 --- a/api/application/libraries/AWS_S3.php +++ b/api/application/libraries/AWS_S3.php @@ -77,7 +77,7 @@ class AWS_S3 } /* This Function return signed URI of single S3 Object*/ - public function getSingleObjectInaBucketAsSignedURI($bucket_name,$folder_name)//get as singed url + public function getSingleObjectInaBucketAsSignedURI($bucket_name,$folder_name,$time = '+5 minutes')//get as singed url { $result = array(); @@ -95,12 +95,12 @@ class AWS_S3 'Key' => $folder_name ]); - $request = $this->S3->createPresignedRequest($cmd, '+60 seconds'); + $request = $this->S3->createPresignedRequest($cmd, $time); $presignedUrl = (string) $request->getUri(); } catch(AwsException $e) { - echo $e->getMessage(); + return $e->getMessage(); } return $presignedUrl; diff --git a/api/application/models/User_Management_Model.php b/api/application/models/User_Management_Model.php index 464a35c7..cba504da 100644 --- a/api/application/models/User_Management_Model.php +++ b/api/application/models/User_Management_Model.php @@ -7,6 +7,7 @@ class User_Management_Model extends SPARQ_Model { public function __construct() { parent::__construct(); + $this->load->library('AWS_S3'); } @@ -31,7 +32,29 @@ class User_Management_Model extends SPARQ_Model { $result = $this->db->get()->result_array(); - if($result !=''){ + + if($result['profilepic'] != '' || $result['profilepic'] != null) + { + $profilepics3path = ''; + if($result['fk_entity_id'] == 1) //1 means sine_edge Profile + { + $profilepics3path = 'sineedge/'.$result['profilepic']; + } + else if($result['fk_entity_id'] == 2)//1 means lender Profile + { + $profilepics3path = 'lender/'.$result['profilepic']; + } + else // else or 3 means vendor Profile + { + $profilepics3path = 'vendor/'.$result['profilepic']; + } + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI(PROFILE_PICTURE_BUCKET_NAME, $profilepics3path,'+5 mintues'); + + $result['profilepic_singed_url'] = $singed_uri; + + } + + if($result != '' ){ foreach($result as $key =>$roles){ $role = $this->db->get_where(USERPROFILEROLES.' as USERPROFILEROLES',array('fk_userid'=>$roles['userid'],'isactive'=>1))->result_array();