Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
pdf-customizer
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
b443899a
authored
2016-07-20 16:26:23 -0400
by
Jeff Balicki
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
file upload to Gdrive done
1 parent
1638e7b7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
13 deletions
app/Http/Controllers/ApiController.php
app/Http/Controllers/AuthenticateController.php
app/Http/Controllers/GoogledriveuploadpdfController.php
app/Http/routes.php
app/pdfModel.php
app/Http/Controllers/ApiController.php
View file @
b443899
...
...
@@ -144,7 +144,7 @@ class ApiController extends Controller
$response
=
$pdfId
;
$statusCode
=
200
;
$UploaqdPdf
=
new
GoogledriveuploadpdfController
();
$UploaqdPdf
=
$UploaqdPdf
->
google_drive_upload
(
$folder
,
'new_'
.
$pdfLocation
);
$UploaqdPdf
->
google_drive_upload
(
$folder
,
'new_'
.
$pdfLocation
,
$pdfId
);
return
Response
::
json
(
$response
,
$statusCode
);
...
...
app/Http/Controllers/AuthenticateController.php
View file @
b443899
...
...
@@ -4,6 +4,7 @@ use JWTAuth;
//use Tymon\JWTAuth\Exceptions\JWTException;
use
Illuminate\Http\Request
;
use
App\User
;
use
App\pdfModel
;
class
AuthenticateController
extends
Controller
...
...
@@ -25,6 +26,13 @@ class AuthenticateController extends Controller
}
// all good so return the token
session_start
();
$user
=
new
pdfModel
();
$user
=
$user
->
getUserId
(
$credentials
[
'email'
])
->
get
();;
$_SESSION
[
'user_id'
]
=
$user
[
0
]
->
id
;
return
response
()
->
json
(
compact
(
'token'
));
}
public
function
getAuthenticatedUser
()
...
...
app/Http/Controllers/GoogledriveuploadpdfController.php
View file @
b443899
...
...
@@ -26,30 +26,34 @@ use Imagick;
class
GoogledriveuploadpdfController
extends
Controller
{
public
function
google_drive_upload
(
$folder
,
$filename
)
public
function
google_drive_upload
(
$folder
,
$filename
,
$PdfId
)
{
session_start
();
$pdffile
=
new
FileEntryController
();
$pdfFile
=
$pdffile
->
getPDF
(
$folder
,
$filename
);
//error_log($_SESSION['user_id']);
$user
=
new
pdfModel
();
$user
=
$user
->
getGoogleUserOath
(
$_SESSION
[
'user_id'
]
)
->
get
();;
$client
=
new
\Google_Client
();
$client
->
setScopes
(
array
(
'https://www.googleapis.com/auth/drive.file'
));
$client
->
setClientId
(
'206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
);
$client
->
setClientSecret
(
'qmUMAi09SU4wU4R3uOkvsiwK'
);
$client
->
setRedirectUri
(
'http://pdf-customizer.synapsus.co/auth/google/token'
);
//$client->setRedirectUri('http://localhost:8888/pdf-customizer/public/auth/google/token');
$client
->
setClientId
(
$user
[
0
]
->
google_client_id
);
$client
->
setClientSecret
(
$user
[
0
]
->
google_client_secret
);
$client
->
setRedirectUri
(
$user
[
0
]
->
redirect_uri
);
// error_log(print_r($client,true));
session_start
();
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
$client
->
refreshToken
(
'1/PZ1OjsCxkeGJx6iVnsQnHOkFYj1_PXir2w-fnugqIkg'
);
$client
->
refreshToken
(
$user
[
0
]
->
refresh_token
);
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
...
...
@@ -61,7 +65,7 @@ class GoogledriveuploadpdfController extends Controller
$file
=
new
\Google_Service_Drive_DriveFile
();
$parent
=
new
\Google_Service_Drive_ParentReference
();
$parent
->
setId
(
'0B2R_Tz3gJKhwMUUwclozRWxsRTA'
);
$parent
->
setId
(
$user
[
0
]
->
save_folder
);
$file
->
setParents
(
array
(
$parent
));
...
...
@@ -83,7 +87,9 @@ class GoogledriveuploadpdfController extends Controller
'mimeType'
=>
$mimetype
,
//text/plain',
'uploadType'
=>
$uploadType
));
$GoogleId
=
$createdFile
->
getId
();
$pdfId
=
new
pdfModel
();
$pdfId
=
$pdfId
->
setPdfGoogleId
(
$GoogleId
,
$PdfId
);
}
...
...
@@ -102,7 +108,7 @@ class GoogledriveuploadpdfController extends Controller
$client
->
setClientId
(
'206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
);
$client
->
setClientSecret
(
'qmUMAi09SU4wU4R3uOkvsiwK'
);
$client
->
setRedirectUri
(
'http://pdf-customizer.synapsus.co/auth/google/tokenCallback'
);
//$client->setRedirectUri('http://localhost:8888/pdf-customizer/public/auth/google/tokenCallback');
$client
->
setAccessType
(
'offline'
);
if
(
isset
(
$_GET
[
'code'
]))
{
...
...
app/Http/routes.php
View file @
b443899
...
...
@@ -52,7 +52,7 @@ Route::get('fileentry/getPDF/{folder}/{filename}', 'FileEntryController@getPDF'
Route
::
post
(
'fileentry/add'
,[
'as'
=>
'addentry'
,
'uses'
=>
'FileEntryController@add'
]);
Route
::
get
(
'api/googlePdfUpload/{folder}/{filename}'
,
'GoogledriveuploadpdfController@google_drive_upload'
);
Route
::
get
(
'api/googlePdfUpload/{folder}/{filename}
/{pdfid}/{id}
'
,
'GoogledriveuploadpdfController@google_drive_upload'
);
Route
::
get
(
'auth/google/callback'
,
'GoogledriveuploadpdfController@google_drive_upload'
);
Route
::
get
(
'auth/google/token'
,
'GoogledriveuploadpdfController@GoogleToken'
);
Route
::
get
(
'auth/google/tokenCallback'
,
'GoogledriveuploadpdfController@GoogleToken'
);
\ No newline at end of file
...
...
app/pdfModel.php
View file @
b443899
...
...
@@ -147,4 +147,35 @@ class pdfModel extends Model
}
public
function
setPdfGoogleId
(
$Googleid
,
$pdfId
){
$rows
=
DB
::
table
(
'googleDriveID'
)
->
insertGetId
(
array
(
'pdfid'
=>
$pdfId
,
'googledriveId'
=>
$Googleid
));
return
$rows
;
}
public
function
getGoogleUserOath
(
$id
){
$rows
=
DB
::
table
(
'googleOuth'
)
->
where
(
'googleOuth.user_id'
,
'='
,
$id
);
return
$rows
;
}
public
function
getUserId
(
$id
){
$rows
=
DB
::
table
(
'users'
)
->
select
(
'id'
)
->
where
(
'email'
,
'='
,
$id
);
return
$rows
;
}
}
...
...
Please
register
or
sign in
to post a comment