file upload to Gdrive done
Showing
5 changed files
with
58 additions
and
13 deletions
| ... | @@ -144,7 +144,7 @@ class ApiController extends Controller | ... | @@ -144,7 +144,7 @@ class ApiController extends Controller |
| 144 | $response = $pdfId; | 144 | $response = $pdfId; |
| 145 | $statusCode = 200; | 145 | $statusCode = 200; |
| 146 | $UploaqdPdf = new GoogledriveuploadpdfController(); | 146 | $UploaqdPdf = new GoogledriveuploadpdfController(); |
| 147 | $UploaqdPdf = $UploaqdPdf->google_drive_upload($folder, 'new_'.$pdfLocation); | 147 | $UploaqdPdf->google_drive_upload($folder, 'new_'.$pdfLocation,$pdfId); |
| 148 | return Response::json( $response, $statusCode); | 148 | return Response::json( $response, $statusCode); |
| 149 | 149 | ||
| 150 | 150 | ... | ... |
| ... | @@ -4,6 +4,7 @@ use JWTAuth; | ... | @@ -4,6 +4,7 @@ use JWTAuth; |
| 4 | //use Tymon\JWTAuth\Exceptions\JWTException; | 4 | //use Tymon\JWTAuth\Exceptions\JWTException; |
| 5 | use Illuminate\Http\Request; | 5 | use Illuminate\Http\Request; |
| 6 | use App\User; | 6 | use App\User; |
| 7 | use App\pdfModel; | ||
| 7 | 8 | ||
| 8 | 9 | ||
| 9 | class AuthenticateController extends Controller | 10 | class AuthenticateController extends Controller |
| ... | @@ -25,6 +26,13 @@ class AuthenticateController extends Controller | ... | @@ -25,6 +26,13 @@ class AuthenticateController extends Controller |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | // all good so return the token | 28 | // all good so return the token |
| 29 | |||
| 30 | session_start(); | ||
| 31 | $user = new pdfModel(); | ||
| 32 | $user = $user->getUserId($credentials['email'])->get();; | ||
| 33 | |||
| 34 | |||
| 35 | $_SESSION['user_id'] = $user[0]->id; | ||
| 28 | return response()->json(compact('token')); | 36 | return response()->json(compact('token')); |
| 29 | } | 37 | } |
| 30 | public function getAuthenticatedUser() | 38 | public function getAuthenticatedUser() | ... | ... |
| ... | @@ -26,30 +26,34 @@ use Imagick; | ... | @@ -26,30 +26,34 @@ use Imagick; |
| 26 | class GoogledriveuploadpdfController extends Controller | 26 | class GoogledriveuploadpdfController extends Controller |
| 27 | { | 27 | { |
| 28 | 28 | ||
| 29 | public function google_drive_upload($folder, $filename) | 29 | public function google_drive_upload($folder, $filename,$PdfId) |
| 30 | { | 30 | { |
| 31 | 31 | session_start(); | |
| 32 | $pdffile = new FileEntryController(); | 32 | $pdffile = new FileEntryController(); |
| 33 | $pdfFile = $pdffile->getPDF($folder, $filename); | 33 | $pdfFile = $pdffile->getPDF($folder, $filename); |
| 34 | //error_log($_SESSION['user_id']); | ||
| 35 | $user = new pdfModel(); | ||
| 36 | $user = $user->getGoogleUserOath($_SESSION['user_id'] )->get();; | ||
| 37 | |||
| 34 | 38 | ||
| 35 | 39 | ||
| 36 | $client = new \Google_Client(); | 40 | $client = new \Google_Client(); |
| 37 | $client->setScopes(array('https://www.googleapis.com/auth/drive.file')); | 41 | $client->setScopes(array('https://www.googleapis.com/auth/drive.file')); |
| 38 | $client->setClientId('206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'); | 42 | $client->setClientId($user[0]->google_client_id); |
| 39 | $client->setClientSecret('qmUMAi09SU4wU4R3uOkvsiwK'); | 43 | $client->setClientSecret($user[0]->google_client_secret); |
| 40 | $client->setRedirectUri('http://pdf-customizer.synapsus.co/auth/google/token'); | 44 | $client->setRedirectUri($user[0]->redirect_uri); |
| 41 | //$client->setRedirectUri('http://localhost:8888/pdf-customizer/public/auth/google/token'); | 45 | |
| 42 | 46 | ||
| 43 | 47 | ||
| 44 | 48 | ||
| 45 | // error_log(print_r($client,true)); | 49 | // error_log(print_r($client,true)); |
| 46 | 50 | ||
| 47 | session_start(); | 51 | |
| 48 | 52 | ||
| 49 | $_SESSION['access_token'] = $client->getAccessToken(); | 53 | $_SESSION['access_token'] = $client->getAccessToken(); |
| 50 | 54 | ||
| 51 | 55 | ||
| 52 | $client->refreshToken('1/PZ1OjsCxkeGJx6iVnsQnHOkFYj1_PXir2w-fnugqIkg'); | 56 | $client->refreshToken($user[0]->refresh_token); |
| 53 | 57 | ||
| 54 | $_SESSION['access_token']= $client->getAccessToken(); | 58 | $_SESSION['access_token']= $client->getAccessToken(); |
| 55 | 59 | ||
| ... | @@ -61,7 +65,7 @@ class GoogledriveuploadpdfController extends Controller | ... | @@ -61,7 +65,7 @@ class GoogledriveuploadpdfController extends Controller |
| 61 | $file = new \Google_Service_Drive_DriveFile(); | 65 | $file = new \Google_Service_Drive_DriveFile(); |
| 62 | 66 | ||
| 63 | $parent = new \Google_Service_Drive_ParentReference(); | 67 | $parent = new \Google_Service_Drive_ParentReference(); |
| 64 | $parent->setId('0B2R_Tz3gJKhwMUUwclozRWxsRTA'); | 68 | $parent->setId($user[0]->save_folder); |
| 65 | $file->setParents(array($parent)); | 69 | $file->setParents(array($parent)); |
| 66 | 70 | ||
| 67 | 71 | ||
| ... | @@ -83,7 +87,9 @@ class GoogledriveuploadpdfController extends Controller | ... | @@ -83,7 +87,9 @@ class GoogledriveuploadpdfController extends Controller |
| 83 | 'mimeType' => $mimetype, //text/plain', | 87 | 'mimeType' => $mimetype, //text/plain', |
| 84 | 'uploadType' => $uploadType | 88 | 'uploadType' => $uploadType |
| 85 | )); | 89 | )); |
| 86 | 90 | $GoogleId = $createdFile->getId(); | |
| 91 | $pdfId = new pdfModel(); | ||
| 92 | $pdfId = $pdfId->setPdfGoogleId($GoogleId,$PdfId); | ||
| 87 | 93 | ||
| 88 | 94 | ||
| 89 | } | 95 | } |
| ... | @@ -102,7 +108,7 @@ class GoogledriveuploadpdfController extends Controller | ... | @@ -102,7 +108,7 @@ class GoogledriveuploadpdfController extends Controller |
| 102 | $client->setClientId('206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'); | 108 | $client->setClientId('206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'); |
| 103 | $client->setClientSecret('qmUMAi09SU4wU4R3uOkvsiwK'); | 109 | $client->setClientSecret('qmUMAi09SU4wU4R3uOkvsiwK'); |
| 104 | $client->setRedirectUri('http://pdf-customizer.synapsus.co/auth/google/tokenCallback'); | 110 | $client->setRedirectUri('http://pdf-customizer.synapsus.co/auth/google/tokenCallback'); |
| 105 | //$client->setRedirectUri('http://localhost:8888/pdf-customizer/public/auth/google/tokenCallback'); | 111 | |
| 106 | $client->setAccessType('offline'); | 112 | $client->setAccessType('offline'); |
| 107 | 113 | ||
| 108 | if (isset($_GET['code'])) { | 114 | if (isset($_GET['code'])) { | ... | ... |
| ... | @@ -52,7 +52,7 @@ Route::get('fileentry/getPDF/{folder}/{filename}', 'FileEntryController@getPDF' | ... | @@ -52,7 +52,7 @@ Route::get('fileentry/getPDF/{folder}/{filename}', 'FileEntryController@getPDF' |
| 52 | Route::post('fileentry/add',[ | 52 | Route::post('fileentry/add',[ |
| 53 | 'as' => 'addentry', 'uses' => 'FileEntryController@add']); | 53 | 'as' => 'addentry', 'uses' => 'FileEntryController@add']); |
| 54 | 54 | ||
| 55 | Route::get('api/googlePdfUpload/{folder}/{filename}', 'GoogledriveuploadpdfController@google_drive_upload'); | 55 | Route::get('api/googlePdfUpload/{folder}/{filename}/{pdfid}/{id}', 'GoogledriveuploadpdfController@google_drive_upload'); |
| 56 | Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload'); | 56 | Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload'); |
| 57 | Route::get('auth/google/token', 'GoogledriveuploadpdfController@GoogleToken'); | 57 | Route::get('auth/google/token', 'GoogledriveuploadpdfController@GoogleToken'); |
| 58 | Route::get('auth/google/tokenCallback', 'GoogledriveuploadpdfController@GoogleToken'); | 58 | Route::get('auth/google/tokenCallback', 'GoogledriveuploadpdfController@GoogleToken'); |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -147,4 +147,35 @@ class pdfModel extends Model | ... | @@ -147,4 +147,35 @@ class pdfModel extends Model |
| 147 | 147 | ||
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | |||
| 151 | public function setPdfGoogleId($Googleid,$pdfId){ | ||
| 152 | |||
| 153 | |||
| 154 | |||
| 155 | $rows = DB::table('googleDriveID')->insertGetId( array('pdfid' => $pdfId, 'googledriveId' => $Googleid )); | ||
| 156 | |||
| 157 | |||
| 158 | return $rows; | ||
| 159 | } | ||
| 160 | |||
| 161 | public function getGoogleUserOath($id){ | ||
| 162 | |||
| 163 | |||
| 164 | |||
| 165 | $rows = DB::table('googleOuth')->where('googleOuth.user_id','=', $id); | ||
| 166 | |||
| 167 | |||
| 168 | return $rows; | ||
| 169 | } | ||
| 170 | public function getUserId($id){ | ||
| 171 | |||
| 172 | |||
| 173 | |||
| 174 | $rows = DB::table('users')->select('id')->where('email','=', $id); | ||
| 175 | |||
| 176 | |||
| 177 | return $rows; | ||
| 178 | } | ||
| 179 | |||
| 180 | |||
| 150 | } | 181 | } | ... | ... |
-
Please register or sign in to post a comment