auth
Showing
11 changed files
with
614 additions
and
71 deletions
| ... | @@ -159,15 +159,6 @@ class ApiController extends Controller | ... | @@ -159,15 +159,6 @@ class ApiController extends Controller |
| 159 | 159 | ||
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | public function getApi($json) | ||
| 163 | { | ||
| 164 | $file = Storage::disk('public')->get('interface.js'); | ||
| 165 | return $file; | ||
| 166 | |||
| 167 | return (new Response($file, 200)) | ||
| 168 | ->header('Content-Type', 'text/html'); | ||
| 169 | } | ||
| 170 | |||
| 171 | 162 | ||
| 172 | 163 | ||
| 173 | public function getPdf($json) | 164 | public function getPdf($json) | ... | ... |
| 1 | <?php namespace App\Http\Controllers; | ||
| 2 | |||
| 3 | use JWTAuth; | ||
| 4 | use Tymon\JWTAuth\Exceptions\JWTException; | ||
| 5 | use Illuminate\Http\Request; | ||
| 6 | use App\User; | ||
| 7 | |||
| 8 | |||
| 9 | class AuthenticateController extends Controller | ||
| 10 | { | ||
| 11 | public function authenticate(Request $request) | ||
| 12 | { | ||
| 13 | // grab credentials from the request | ||
| 14 | //return User::create(['email' => 'jeffmbalicki@gmail.com', 'password' => bcrypt('518862')]); | ||
| 15 | $credentials = $request->only('email', 'password'); | ||
| 16 | |||
| 17 | try { | ||
| 18 | // attempt to verify the credentials and create a token for the user | ||
| 19 | if (! $token = JWTAuth::attempt($credentials)) { | ||
| 20 | return response()->json(['error' => 'invalid_credentials'], 401); | ||
| 21 | } | ||
| 22 | } catch (JWTException $e) { | ||
| 23 | // something went wrong whilst attempting to encode the token | ||
| 24 | return response()->json(['error' => 'could_not_create_token'], 500); | ||
| 25 | } | ||
| 26 | |||
| 27 | // all good so return the token | ||
| 28 | return response()->json(compact('token')); | ||
| 29 | } | ||
| 30 | public function getAuthenticatedUser() | ||
| 31 | { | ||
| 32 | try { | ||
| 33 | |||
| 34 | if (! $user = JWTAuth::parseToken()->authenticate()) { | ||
| 35 | return response()->json(['user_not_found'], 404); | ||
| 36 | } | ||
| 37 | |||
| 38 | } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { | ||
| 39 | |||
| 40 | return response()->json(['token_expired'], $e->getStatusCode()); | ||
| 41 | |||
| 42 | } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) { | ||
| 43 | |||
| 44 | return response()->json(['token_invalid'], $e->getStatusCode()); | ||
| 45 | |||
| 46 | } catch (Tymon\JWTAuth\Exceptions\JWTException $e) { | ||
| 47 | |||
| 48 | return response()->json(['token_absent'], $e->getStatusCode()); | ||
| 49 | |||
| 50 | } | ||
| 51 | |||
| 52 | // the token is valid and we have found the user via the sub claim | ||
| 53 | return response()->json(compact('user')); | ||
| 54 | } | ||
| 55 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -69,40 +69,7 @@ class FileEntryController extends Controller { | ... | @@ -69,40 +69,7 @@ class FileEntryController extends Controller { |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | public function postUpload(){ | 72 | |
| 73 | |||
| 74 | $files = Input::file('files'); | ||
| 75 | |||
| 76 | $json = array( | ||
| 77 | 'files' => array() | ||
| 78 | ); | ||
| 79 | |||
| 80 | foreach( $files as $file ): | ||
| 81 | |||
| 82 | $filename = $file->getClientOriginalName().".".$file->getClientOriginalExtension(); | ||
| 83 | |||
| 84 | $json['files'][] = array( | ||
| 85 | 'name' => $filename, | ||
| 86 | 'size' => $file->getSize(), | ||
| 87 | 'type' => $file->getMimeType(), | ||
| 88 | 'url' => '/uploads/files/'.$filename, | ||
| 89 | 'deleteType' => 'DELETE', | ||
| 90 | 'deleteUrl' => self::$route.'/deleteFile/'.$filename, | ||
| 91 | ); | ||
| 92 | |||
| 93 | $upload = $file->move( public_path().'/files', $filename ); | ||
| 94 | |||
| 95 | |||
| 96 | endforeach; | ||
| 97 | |||
| 98 | |||
| 99 | |||
| 100 | |||
| 101 | |||
| 102 | return Response::json($json); | ||
| 103 | |||
| 104 | } | ||
| 105 | |||
| 106 | 73 | ||
| 107 | 74 | ||
| 108 | 75 | ||
| ... | @@ -113,7 +80,7 @@ class FileEntryController extends Controller { | ... | @@ -113,7 +80,7 @@ class FileEntryController extends Controller { |
| 113 | $file = Storage::disk('public')->get('js/interface.js'); | 80 | $file = Storage::disk('public')->get('js/interface.js'); |
| 114 | 81 | ||
| 115 | return (new Response($file, 200)) | 82 | return (new Response($file, 200)) |
| 116 | ->header('Content-Type', 'text/html'); | 83 | ->header('Content-Type', 'application/x-javascript'); |
| 117 | } | 84 | } |
| 118 | 85 | ||
| 119 | } | 86 | } | ... | ... |
| ... | @@ -28,7 +28,8 @@ class Kernel extends HttpKernel | ... | @@ -28,7 +28,8 @@ class Kernel extends HttpKernel |
| 28 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, | 28 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, |
| 29 | \Illuminate\Session\Middleware\StartSession::class, | 29 | \Illuminate\Session\Middleware\StartSession::class, |
| 30 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, | 30 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, |
| 31 | \App\Http\Middleware\VerifyCsrfToken::class, | 31 | // \App\Http\Middleware\VerifyCsrfToken::class, |
| 32 | |||
| 32 | ], | 33 | ], |
| 33 | 34 | ||
| 34 | 'api' => [ | 35 | 'api' => [ |
| ... | @@ -50,5 +51,7 @@ class Kernel extends HttpKernel | ... | @@ -50,5 +51,7 @@ class Kernel extends HttpKernel |
| 50 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, | 51 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, |
| 51 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, | 52 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, |
| 52 | 'cors' => \App\Http\Middleware\Cors::class, | 53 | 'cors' => \App\Http\Middleware\Cors::class, |
| 54 | 'jwt.auth' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class, | ||
| 55 | 'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class | ||
| 53 | ]; | 56 | ]; |
| 54 | } | 57 | } | ... | ... |
| ... | @@ -11,7 +11,7 @@ class VerifyCsrfToken extends BaseVerifier | ... | @@ -11,7 +11,7 @@ class VerifyCsrfToken extends BaseVerifier |
| 11 | * | 11 | * |
| 12 | * @var array | 12 | * @var array |
| 13 | */ | 13 | */ |
| 14 | protected $except = [ 'api/update' | 14 | protected $except = [ 'api/update', 'api/authenticate' |
| 15 | // | 15 | // |
| 16 | ]; | 16 | ]; |
| 17 | } | 17 | } | ... | ... |
| ... | @@ -29,10 +29,14 @@ Route::group(array('prefix' => 'api/v1'), function($json) | ... | @@ -29,10 +29,14 @@ Route::group(array('prefix' => 'api/v1'), function($json) |
| 29 | Route::resource('get-list', 'ApiController@getList'); | 29 | Route::resource('get-list', 'ApiController@getList'); |
| 30 | Route::resource('get-pdf', 'ApiController@getpdf'); | 30 | Route::resource('get-pdf', 'ApiController@getpdf'); |
| 31 | Route::resource('api', 'FileEntryController@getApi'); | 31 | Route::resource('api', 'FileEntryController@getApi'); |
| 32 | |||
| 32 | 33 | ||
| 33 | }); | 34 | }); |
| 34 | 35 | ||
| 35 | Route::any('api/update', 'ApiController@update'); | 36 | Route::any('api/update', 'ApiController@update'); |
| 37 | Route::post('api/authenticate', 'AuthenticateController@authenticate'); | ||
| 38 | Route::get('api/authenticate/user', 'AuthenticateController@getAuthenticatedUser'); | ||
| 39 | |||
| 36 | 40 | ||
| 37 | Route::any('fileentry/postUpload', 'FileEntryController@postUpload'); | 41 | Route::any('fileentry/postUpload', 'FileEntryController@postUpload'); |
| 38 | 42 | ... | ... |
| 1 | <?php | 1 | <? |
| 2 | |||
| 3 | namespace App; | 2 | namespace App; |
| 3 | use Illuminate\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Foundation\Auth\Access\Authorizable; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; | ||
| 4 | class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract { use Authenticatable, Authorizable, CanResetPassword; | ||
| 5 | /** | ||
| 6 | * The database table used by the model. | ||
| 7 | * | ||
| 8 | * @var string | ||
| 9 | */ | ||
| 10 | protected $table = 'users'; | ||
| 4 | 11 | ||
| 5 | use Illuminate\Foundation\Auth\User as Authenticatable; | 12 | /** |
| 6 | 13 | * The attributes that are mass assignable. | |
| 7 | class User extends Authenticatable | 14 | * |
| 8 | { | 15 | * @var array |
| 9 | /** | 16 | */ |
| 10 | * The attributes that are mass assignable. | 17 | protected $fillable = ['first_name', 'last_name', 'username', 'email', 'password']; |
| 11 | * | 18 | /** |
| 12 | * @var array | 19 | * The attributes excluded from the model's JSON form. |
| 13 | */ | 20 | * |
| 14 | protected $fillable = [ | 21 | * @var array |
| 15 | 'name', 'email', 'password', | 22 | */ |
| 16 | ]; | 23 | protected $hidden = ['password']; |
| 17 | 24 | } | |
| 18 | /** | ||
| 19 | * The attributes that should be hidden for arrays. | ||
| 20 | * | ||
| 21 | * @var array | ||
| 22 | */ | ||
| 23 | protected $hidden = [ | ||
| 24 | 'password', 'remember_token', | ||
| 25 | ]; | ||
| 26 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -147,7 +147,7 @@ return [ | ... | @@ -147,7 +147,7 @@ return [ |
| 147 | Illuminate\Translation\TranslationServiceProvider::class, | 147 | Illuminate\Translation\TranslationServiceProvider::class, |
| 148 | Illuminate\Validation\ValidationServiceProvider::class, | 148 | Illuminate\Validation\ValidationServiceProvider::class, |
| 149 | Illuminate\View\ViewServiceProvider::class, | 149 | Illuminate\View\ViewServiceProvider::class, |
| 150 | 150 | Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class, | |
| 151 | /* | 151 | /* |
| 152 | * Application Service Providers... | 152 | * Application Service Providers... |
| 153 | */ | 153 | */ |
| ... | @@ -201,6 +201,7 @@ return [ | ... | @@ -201,6 +201,7 @@ return [ |
| 201 | 'URL' => Illuminate\Support\Facades\URL::class, | 201 | 'URL' => Illuminate\Support\Facades\URL::class, |
| 202 | 'Validator' => Illuminate\Support\Facades\Validator::class, | 202 | 'Validator' => Illuminate\Support\Facades\Validator::class, |
| 203 | 'View' => Illuminate\Support\Facades\View::class, | 203 | 'View' => Illuminate\Support\Facades\View::class, |
| 204 | 'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class, | ||
| 204 | 205 | ||
| 205 | ], | 206 | ], |
| 206 | 207 | ... | ... |
config/jwt.php
0 → 100644
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of jwt-auth. | ||
| 5 | * | ||
| 6 | * (c) Sean Tymon <tymon148@gmail.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | return [ | ||
| 13 | |||
| 14 | /* | ||
| 15 | |-------------------------------------------------------------------------- | ||
| 16 | | JWT Authentication Secret | ||
| 17 | |-------------------------------------------------------------------------- | ||
| 18 | | | ||
| 19 | | Don't forget to set this, as it will be used to sign your tokens. | ||
| 20 | | A helper command is provided for this: `php artisan jwt:generate` | ||
| 21 | | | ||
| 22 | */ | ||
| 23 | |||
| 24 | 'secret' => env('JWT_SECRET', 'O1RUwmBjmDjsYJDpAgGB5GZLwnhDeGqS'), | ||
| 25 | |||
| 26 | /* | ||
| 27 | |-------------------------------------------------------------------------- | ||
| 28 | | JWT time to live | ||
| 29 | |-------------------------------------------------------------------------- | ||
| 30 | | | ||
| 31 | | Specify the length of time (in minutes) that the token will be valid for. | ||
| 32 | | Defaults to 1 hour | ||
| 33 | | | ||
| 34 | */ | ||
| 35 | |||
| 36 | 'ttl' => 60, | ||
| 37 | |||
| 38 | /* | ||
| 39 | |-------------------------------------------------------------------------- | ||
| 40 | | Refresh time to live | ||
| 41 | |-------------------------------------------------------------------------- | ||
| 42 | | | ||
| 43 | | Specify the length of time (in minutes) that the token can be refreshed | ||
| 44 | | within. I.E. The user can refresh their token within a 2 week window of | ||
| 45 | | the original token being created until they must re-authenticate. | ||
| 46 | | Defaults to 2 weeks | ||
| 47 | | | ||
| 48 | */ | ||
| 49 | |||
| 50 | 'refresh_ttl' => 20160, | ||
| 51 | |||
| 52 | /* | ||
| 53 | |-------------------------------------------------------------------------- | ||
| 54 | | JWT hashing algorithm | ||
| 55 | |-------------------------------------------------------------------------- | ||
| 56 | | | ||
| 57 | | Specify the hashing algorithm that will be used to sign the token. | ||
| 58 | | | ||
| 59 | | See here: https://github.com/namshi/jose/tree/2.2.0/src/Namshi/JOSE/Signer | ||
| 60 | | for possible values | ||
| 61 | | | ||
| 62 | */ | ||
| 63 | |||
| 64 | 'algo' => 'HS256', | ||
| 65 | |||
| 66 | /* | ||
| 67 | |-------------------------------------------------------------------------- | ||
| 68 | | User Model namespace | ||
| 69 | |-------------------------------------------------------------------------- | ||
| 70 | | | ||
| 71 | | Specify the full namespace to your User model. | ||
| 72 | | e.g. 'Acme\Entities\User' | ||
| 73 | | | ||
| 74 | */ | ||
| 75 | |||
| 76 | 'user' => 'App\User', | ||
| 77 | |||
| 78 | /* | ||
| 79 | |-------------------------------------------------------------------------- | ||
| 80 | | User identifier | ||
| 81 | |-------------------------------------------------------------------------- | ||
| 82 | | | ||
| 83 | | Specify a unique property of the user that will be added as the 'sub' | ||
| 84 | | claim of the token payload. | ||
| 85 | | | ||
| 86 | */ | ||
| 87 | |||
| 88 | 'identifier' => 'userid', | ||
| 89 | |||
| 90 | /* | ||
| 91 | |-------------------------------------------------------------------------- | ||
| 92 | | Required Claims | ||
| 93 | |-------------------------------------------------------------------------- | ||
| 94 | | | ||
| 95 | | Specify the required claims that must exist in any token. | ||
| 96 | | A TokenInvalidException will be thrown if any of these claims are not | ||
| 97 | | present in the payload. | ||
| 98 | | | ||
| 99 | */ | ||
| 100 | |||
| 101 | 'required_claims' => ['iss', 'iat', 'exp', 'nbf', 'sub', 'jti'], | ||
| 102 | |||
| 103 | /* | ||
| 104 | |-------------------------------------------------------------------------- | ||
| 105 | | Blacklist Enabled | ||
| 106 | |-------------------------------------------------------------------------- | ||
| 107 | | | ||
| 108 | | In order to invalidate tokens, you must have the the blacklist enabled. | ||
| 109 | | If you do not want or need this functionality, then set this to false. | ||
| 110 | | | ||
| 111 | */ | ||
| 112 | |||
| 113 | 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true), | ||
| 114 | |||
| 115 | /* | ||
| 116 | |-------------------------------------------------------------------------- | ||
| 117 | | Providers | ||
| 118 | |-------------------------------------------------------------------------- | ||
| 119 | | | ||
| 120 | | Specify the various providers used throughout the package. | ||
| 121 | | | ||
| 122 | */ | ||
| 123 | |||
| 124 | 'providers' => [ | ||
| 125 | |||
| 126 | /* | ||
| 127 | |-------------------------------------------------------------------------- | ||
| 128 | | User Provider | ||
| 129 | |-------------------------------------------------------------------------- | ||
| 130 | | | ||
| 131 | | Specify the provider that is used to find the user based | ||
| 132 | | on the subject claim | ||
| 133 | | | ||
| 134 | */ | ||
| 135 | |||
| 136 | 'user' => 'Tymon\JWTAuth\Providers\User\EloquentUserAdapter', | ||
| 137 | |||
| 138 | /* | ||
| 139 | |-------------------------------------------------------------------------- | ||
| 140 | | JWT Provider | ||
| 141 | |-------------------------------------------------------------------------- | ||
| 142 | | | ||
| 143 | | Specify the provider that is used to create and decode the tokens. | ||
| 144 | | | ||
| 145 | */ | ||
| 146 | |||
| 147 | 'jwt' => 'Tymon\JWTAuth\Providers\JWT\NamshiAdapter', | ||
| 148 | |||
| 149 | /* | ||
| 150 | |-------------------------------------------------------------------------- | ||
| 151 | | Authentication Provider | ||
| 152 | |-------------------------------------------------------------------------- | ||
| 153 | | | ||
| 154 | | Specify the provider that is used to authenticate users. | ||
| 155 | | | ||
| 156 | */ | ||
| 157 | |||
| 158 | 'auth' => 'Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter', | ||
| 159 | |||
| 160 | /* | ||
| 161 | |-------------------------------------------------------------------------- | ||
| 162 | | Storage Provider | ||
| 163 | |-------------------------------------------------------------------------- | ||
| 164 | | | ||
| 165 | | Specify the provider that is used to store tokens in the blacklist | ||
| 166 | | | ||
| 167 | */ | ||
| 168 | |||
| 169 | 'storage' => 'Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter', | ||
| 170 | |||
| 171 | ], | ||
| 172 | |||
| 173 | ]; |
| ... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
| 15 | RewriteCond %{REQUEST_FILENAME} !-f | 15 | RewriteCond %{REQUEST_FILENAME} !-f |
| 16 | RewriteRule ^ index.php [L] | 16 | RewriteRule ^ index.php [L] |
| 17 | 17 | ||
| 18 | RewriteCond %{HTTP:Authorization} ^(.*) | ||
| 19 | RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] | ||
| 18 | # Handle Authorization Header | 20 | # Handle Authorization Header |
| 19 | 21 | ||
| 20 | </IfModule> | 22 | </IfModule> | ... | ... |
public/files/js/interface.js
0 → 100644
| 1 | function getAuth(){ | ||
| 2 | |||
| 3 | jQuery(document).ready(function($) { | ||
| 4 | |||
| 5 | var settings = { | ||
| 6 | "async": true, | ||
| 7 | "crossDomain": true, | ||
| 8 | "url": "http://localhost:8888/pdf-customizer/public/api/authenticate", | ||
| 9 | "method": "POST", | ||
| 10 | "headers": { | ||
| 11 | "authorization": "Basic amVmZkBnb3RlbnppbmcuY29tOjUxODg2Mg==", | ||
| 12 | "cache-control": "no-cache", | ||
| 13 | "postman-token": "fe3549e8-0ba4-6214-c850-35863ef49a92" | ||
| 14 | }, | ||
| 15 | "processData": false, | ||
| 16 | "contentType": false, | ||
| 17 | "mimeType": "multipart/form-data", | ||
| 18 | "data": form, | ||
| 19 | "success": function (data) { | ||
| 20 | getJson(user_id); | ||
| 21 | }, | ||
| 22 | error: function (xhr, ajaxOptions, thrownError) { //Add these parameters to display the required response | ||
| 23 | //alert(xhr.status); | ||
| 24 | document.getElementById('contentArea').innerHTML =xhr.responseText; | ||
| 25 | } | ||
| 26 | |||
| 27 | } | ||
| 28 | |||
| 29 | $.ajax(settings).done(function (response) { | ||
| 30 | console.log(response); | ||
| 31 | token = response; | ||
| 32 | |||
| 33 | |||
| 34 | }); | ||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | }); | ||
| 39 | |||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | function getJson(user_id){ | ||
| 47 | |||
| 48 | jQuery(document).ready(function($) { | ||
| 49 | |||
| 50 | $.getJSON("http://localhost:8888/pdf-customizer/public/api/v1/get-list/"+user_id, function (data) { | ||
| 51 | // Get the element with id summary and set the inner text to the result. | ||
| 52 | var json = JSON.stringify(data); | ||
| 53 | pickPdfFromList(json); | ||
| 54 | |||
| 55 | }); | ||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | }); | ||
| 60 | } | ||
| 61 | |||
| 62 | function getOneJson(id){ | ||
| 63 | |||
| 64 | jQuery(document).ready(function($) { | ||
| 65 | |||
| 66 | $.getJSON("http://localhost:8888/pdf-customizer/public/api/v1/get-pdf/"+id, function (data) { | ||
| 67 | // Get the element with id summary and set the inner text to the result. | ||
| 68 | var json = JSON.stringify(data); | ||
| 69 | |||
| 70 | changePdfOptions(json); | ||
| 71 | |||
| 72 | }); | ||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | }); | ||
| 77 | } | ||
| 78 | |||
| 79 | function pickPdfFromList(json){ | ||
| 80 | json = JSON.parse(json); | ||
| 81 | |||
| 82 | |||
| 83 | var strVar=""; | ||
| 84 | strVar += "<link rel=\"stylesheet\" href=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.min.css\">"; | ||
| 85 | strVar += " <link href=\"http:\/\/cdnjs.cloudflare.com\/ajax\/libs\/foundicons\/3.0.0\/foundation-icons.css\" rel=\"stylesheet\" type=\"text\/css\">"; | ||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | var i; | ||
| 90 | var pdflist = ""; | ||
| 91 | for (i = 0; i < json.length; ++i) { | ||
| 92 | pdflist += "<div class=\"column\">"; | ||
| 93 | pdflist += '<a href=\"#\" onclick=\"getOneJson(' +json[i].idPDF+');\"> <img class=\"thumbnail\" src="http://localhost:8888/pdf-customizer/public/fileentry/getImage/' + json[i].folder + '/' + json[i].image + '" height=\"270px\"></a>'; | ||
| 94 | pdflist += " <h5>" + json[i].name + "<\/h5>"; | ||
| 95 | pdflist += "<\/div>"; | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | strVar += " <div class=\"callout primary\">"; | ||
| 100 | strVar += " <div class=\"row column\">"; | ||
| 101 | strVar += " <h1>Welcome to Synapsus Online PDF Editor<\/h1>"; | ||
| 102 | strVar += " <p class=\"lead\">Please pick a PDF<\/p>"; | ||
| 103 | strVar += " <\/div>"; | ||
| 104 | strVar += " <\/div>"; | ||
| 105 | |||
| 106 | strVar += " <div class=\"row small-up-2 medium-up-3 large-up-4\">"; | ||
| 107 | strVar += pdflist; | ||
| 108 | strVar += " <\/div>"; | ||
| 109 | strVar += " <hr>"; | ||
| 110 | strVar += ""; | ||
| 111 | strVar += " <\/div>"; | ||
| 112 | strVar += " <\/div>"; | ||
| 113 | strVar += " <\/div>"; | ||
| 114 | strVar += " <\/div>"; | ||
| 115 | strVar += "<\/div>"; | ||
| 116 | strVar += "<\/div>"; | ||
| 117 | strVar += ""; | ||
| 118 | strVar += "<script src=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.js\"><\/script>"; | ||
| 119 | strVar += "<script>"; | ||
| 120 | strVar += " $(document).foundation();"; | ||
| 121 | strVar += "<\/script>"; | ||
| 122 | strVar += ""; | ||
| 123 | strVar += ""; | ||
| 124 | document.getElementById('contentArea').innerHTML = strVar; | ||
| 125 | |||
| 126 | |||
| 127 | |||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | |||
| 132 | |||
| 133 | } | ||
| 134 | |||
| 135 | |||
| 136 | function changePdfOptions(json){ | ||
| 137 | json = JSON.parse(json); | ||
| 138 | |||
| 139 | var strVar2=""; | ||
| 140 | strVar2 += "<link rel=\"stylesheet\" href=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.min.css\">"; | ||
| 141 | strVar2 += "<link href=\"http:\/\/cdnjs.cloudflare.com\/ajax\/libs\/foundicons\/3.0.0\/foundation-icons.css\" rel=\"stylesheet\" type=\"text\/css\">"; | ||
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | var pdflist =""; | ||
| 146 | |||
| 147 | pdflist += "<div class=\"column\">"; | ||
| 148 | pdflist += ' <img src=\"http://localhost:8888/pdf-customizer/public/fileentry/getImage/' + json[0].folder + '/' + json[0].image + '\" width=\"300px\">'; | ||
| 149 | pdflist += "<\/div>"; | ||
| 150 | var pdfChange="<br>"; | ||
| 151 | pdfChange += "<form id=\"changes\" name=\"changes\" enctype=\"multipart/form-data\" action=\"#\" METHOD=\"POST\"><h4>" + json[0].name+"</h4>"; | ||
| 152 | pdfChange += " <input type=\"hidden\" id=\"id\" name=\"id\" value=\""+json[0].idPDF+"\">"; | ||
| 153 | for (i = 0; i < json.length; ++i) { | ||
| 154 | if(json[i].change_type == "text"){ | ||
| 155 | |||
| 156 | |||
| 157 | pdfChange += " Text: <input id=\"content\" type=\"text\" name=\"content\" value=\""+json[i].content+"\">"; | ||
| 158 | |||
| 159 | |||
| 160 | ; | ||
| 161 | }if(json[i].change_type == "img"){ | ||
| 162 | |||
| 163 | pdfChange += "Image: <input class=\"fileupload\" id=\"content\" style=\"display: block; box-sizing: border-box; width: 100%; height: 2.4375rem; padding: .5rem; border: 1px solid #cacaca; margin: 0 0 1rem; font-family: inherit; font-size: 1rem; color: #8a8a8a; background-color: #fefefe; box-shadow: inset 0 1px 2px rgba(10,10,10,.1); border-radius: 0; transition: box-shadow .5s,border-color .25s ease-in-out; -webkit-appearance: none; -moz-appearance: none;\" type=\"file\" name=\"content\" >"; | ||
| 164 | } | ||
| 165 | |||
| 166 | } | ||
| 167 | pdfChange += " <input type=\"submit\" onclick=' ' value=\"Submit\">"; | ||
| 168 | pdfChange += "<\/form>"; | ||
| 169 | |||
| 170 | strVar2 += " <link rel=\"stylesheet\" href=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.min.css\">"; | ||
| 171 | |||
| 172 | strVar2 += " <div class=\"callout primary\">"; | ||
| 173 | strVar2 += " <div class=\"row column\">"; | ||
| 174 | strVar2 += " <h1>Welcome to Synapsus Online PDF Editor<\/h1>"; | ||
| 175 | strVar2 += " <p class=\"lead\">Please make your changes or return <a href=\"#\" onclick=\"getJson("+user_id+");\">back to the list</a><\/p>"; | ||
| 176 | strVar2 += " <\/div>"; | ||
| 177 | strVar2 += " <\/div>"; | ||
| 178 | strVar2 += " <div class=\"row small-up-2 medium-up-3 large-up-3\">"; | ||
| 179 | strVar2 += pdflist+"<div class=\"column\">"+pdfChange+"<\/div>"; | ||
| 180 | strVar2 += " <\/div>"; | ||
| 181 | strVar2 += " <hr>"; | ||
| 182 | strVar2 += ""; | ||
| 183 | strVar2 += " <\/div>"; | ||
| 184 | strVar2 += " <\/div>"; | ||
| 185 | strVar2 += " <\/div>"; | ||
| 186 | strVar2 += " <\/div>"; | ||
| 187 | strVar2 += "<\/div>"; | ||
| 188 | strVar2 += ""; | ||
| 189 | strVar2 += "<script src=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.js\"><\/script>"; | ||
| 190 | strVar2 += "<script>"; | ||
| 191 | strVar2 += " $(document).foundation();"; | ||
| 192 | strVar2 += "<\/script>"; | ||
| 193 | |||
| 194 | strVar2 += ""; | ||
| 195 | |||
| 196 | document.getElementById('contentArea').innerHTML =strVar2; | ||
| 197 | |||
| 198 | $("document").ready(function(){ | ||
| 199 | var files; | ||
| 200 | |||
| 201 | // Add events | ||
| 202 | $(".fileupload").change(function() { files = event.target.files; console.log(files); }); | ||
| 203 | |||
| 204 | |||
| 205 | $("#changes").submit(function(e) { | ||
| 206 | e.preventDefault(); | ||
| 207 | |||
| 208 | var form = $("#changes"); | ||
| 209 | // var values = {}; | ||
| 210 | //form.each(function() { | ||
| 211 | // values[this.name] = $(this).val(); | ||
| 212 | //}); | ||
| 213 | console.log(form); | ||
| 214 | |||
| 215 | returnfileOptions(files, form); | ||
| 216 | return false;}); | ||
| 217 | |||
| 218 | |||
| 219 | |||
| 220 | }) ; | ||
| 221 | |||
| 222 | } | ||
| 223 | |||
| 224 | function returnfileOptions(files,form) { | ||
| 225 | |||
| 226 | var data = new FormData(); | ||
| 227 | $.each(files, function(key, value) | ||
| 228 | { | ||
| 229 | data.append(key, value); | ||
| 230 | }); | ||
| 231 | |||
| 232 | $.ajax({ | ||
| 233 | url: 'http://localhost:8888/Forms/wp-content/plugins/pdf-customizer-plugin/admin/uploadfile.php?files', | ||
| 234 | type: 'POST', | ||
| 235 | data: data, | ||
| 236 | cache: false, | ||
| 237 | dataType: 'json', | ||
| 238 | processData: false, // Don't process the files | ||
| 239 | contentType: false, // Set content type to false as jQuery will tell the server its a query string request | ||
| 240 | success: function(data, textStatus, jqXHR) | ||
| 241 | { | ||
| 242 | if(typeof data.error === 'undefined') | ||
| 243 | { | ||
| 244 | returnOptions(form); | ||
| 245 | } | ||
| 246 | else | ||
| 247 | { | ||
| 248 | // Handle errors here | ||
| 249 | |||
| 250 | console.log('ERRORS: ' + data.error); | ||
| 251 | } | ||
| 252 | }, | ||
| 253 | error: function(jqXHR, textStatus, errorThrown) | ||
| 254 | { | ||
| 255 | // Handle errors here | ||
| 256 | console.log('ERRORS: ' + textStatus); | ||
| 257 | // STOP LOADING SPINNER | ||
| 258 | } | ||
| 259 | }); | ||
| 260 | |||
| 261 | |||
| 262 | } | ||
| 263 | |||
| 264 | |||
| 265 | function returnOptions(form) { | ||
| 266 | |||
| 267 | |||
| 268 | // console.log(form[0][1].value); | ||
| 269 | |||
| 270 | |||
| 271 | |||
| 272 | |||
| 273 | |||
| 274 | jQuery(document).ready(function ($) { | ||
| 275 | |||
| 276 | $.getJSON("http://localhost:8888/pdf-customizer/public/api/v1/get-pdf/" + id.value, function (dataReturnd) { | ||
| 277 | // Get the element with id summary and set the inner text to the result. | ||
| 278 | var json = dataReturnd; | ||
| 279 | //console.log(json); | ||
| 280 | |||
| 281 | |||
| 282 | var jsonReturn = '{"pdf":[{"name":"' + json[0].name + '", "folder":"' + json[0].folder + '", "pdfLocation":"' + json[0].file + '"}],"changes":[' | ||
| 283 | var e = 1; | ||
| 284 | for (i = 0; i < json.length; ++i) { | ||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | var style = JSON.stringify(json[i].style); | ||
| 289 | var content = JSON.stringify(form[0][e].value); | ||
| 290 | |||
| 291 | |||
| 292 | |||
| 293 | jsonReturn += '{"label":"' + json[i].label + '", "locationUp":"' + json[i].locationUp + '", "locationRight":"' + json[i].locationRight + '","width":"' + json[i].width + '","height":"' + json[i].height + '", "pages":"' + json[i].pages + '", "content":' + content + ', "z-index":null, "idstylesPDF":"' + json[i].idstylesPDF + '", "style":' + style + ', "order":"' + json[i].order + '", "idchange_typePDF":"' + json[i].idchange_typePDF + '", "change_type":"' + json[i].change_type + '", "fileLocation":"http://contact.gotenzing.com/wp-content/plugins/pdf-customizer-plugin/admin/images"}'; | ||
| 294 | |||
| 295 | |||
| 296 | if (i < json.length - 1){ | ||
| 297 | jsonReturn += ','; | ||
| 298 | } | ||
| 299 | ++e | ||
| 300 | } | ||
| 301 | jsonReturn += ' ]}'; | ||
| 302 | // console.log(jsonReturn); | ||
| 303 | |||
| 304 | |||
| 305 | |||
| 306 | |||
| 307 | $.ajax({ | ||
| 308 | url: "http://localhost:8888/pdf-customizer/public/api/update", | ||
| 309 | type: "POST", | ||
| 310 | dataType: 'json', | ||
| 311 | data: jsonReturn, | ||
| 312 | processData: false, | ||
| 313 | |||
| 314 | contentType: "application/json", | ||
| 315 | CrossDomain:true, | ||
| 316 | |||
| 317 | |||
| 318 | |||
| 319 | |||
| 320 | async: true, | ||
| 321 | success: function (data) { | ||
| 322 | document.getElementById('contentArea').innerHTML ='<a href="http://localhost:8888/pdf-customizer/public/fileentry/getPDF/'+json[0].folder+'/new_'+json[0].file+'" download="'+json[0].file+'" >Download Here</a>'; | ||
| 323 | }, | ||
| 324 | error: function (xhr, ajaxOptions, thrownError) { //Add these parameters to display the required response | ||
| 325 | alert(xhr.status); | ||
| 326 | document.getElementById('contentArea').innerHTML =xhr.responseText; | ||
| 327 | } | ||
| 328 | |||
| 329 | }); | ||
| 330 | |||
| 331 | |||
| 332 | |||
| 333 | |||
| 334 | |||
| 335 | |||
| 336 | |||
| 337 | |||
| 338 | |||
| 339 | }); | ||
| 340 | |||
| 341 | |||
| 342 | }); | ||
| 343 | |||
| 344 | |||
| 345 | } | ||
| 346 | |||
| 347 | |||
| 348 | |||
| 349 |
-
Please register or sign in to post a comment