ImageController serving images only for authorized users that are MEMBER or ADMIN

This commit is contained in:
tschneider 2020-10-27 10:33:47 +01:00
parent c180d2be9d
commit c0fe97246a
12 changed files with 232 additions and 916 deletions

View file

@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
class ImageController extends Controller
{
public function getImage($category, $imageName) {
$user=Auth::user();
error_log("getImage");
if ($user) {
error_log("User exists");
if ($user->role == "ADMIN" || $user->role == "GUEST") {
error_log("User has proper role: ".$user->role);
return response()->file(storage_path() . "/img_storage/".$category."/" . $imageName);
}
}
error_log("User is not authorized");
return response()->file(public_path()."/img/placeholder/icon_unknown.png");
}
}

View file

@ -102,17 +102,22 @@ class UserController extends Controller
if ($breite>$hoehe) {
Image::make($request->bild)
->widen(1200)
->save(public_path().'/img/user/'.$user->id.'_gross.jpg');
->save(public_path().'/img/user/'.$user->id.'_gross.jpg')
->save(storage_path().'/img/user/'.$user->id.'_gross.jpg');
Image::make($request->bild)
->widen(64)
->save(public_path().'/img/user/'.$user->id.'.jpg');
->save(public_path().'/img/user/'.$user->id.'.jpg')
->save(storage_path().'/img/user/'.$user->id.'.jpg');
}else {
Image::make($request->bild)
->heighten(900)
->save(public_path().'/img/user/'.$user->id.'_gross.jpg');
->save(public_path().'/img/user/'.$user->id.'_gross.jpg')
->save(storage_path().'/img/user/'.$user->id.'_gross.jpg');
Image::make($request->bild)
->widen(96)
->save(public_path().'/img/user/'.$user->id.'.jpg');
->save(public_path().'/img/user/'.$user->id.'.jpg')
->save(storage_path().'/img/user/'.$user->id.'.jpg');
}
}

1090
motorradig/composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -33,6 +33,12 @@ return [
'stores' => [
'none' => [
'driver' => 'null'
],
'apc' => [
'driver' => 'apc',
],
@ -52,7 +58,6 @@ return [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 100 KiB

Before After
Before After

View file

@ -26,10 +26,10 @@
<div class="form-group" style="display:flex;">
<label class="ml-2 mt-4" style="width:150px; text-align:left;" for="bild" ><h4>Bild:</h4></label>
@if(file_exists (public_path ('img/user/'.$user->id.'.jpg')))
@if(file_exists (storage_path().'/img_storage/user/'.$user->id.'.jpg'))
<!--File exists -->
<a href="/img/user/{{$user->id}}_gross.jpg" data-lightbox="{{$user->id}}_gross.jpg" data-title="{{ $user->name }}">
<img src="/img/user/{{$user->id}}.jpg" class="mt-3 ml-3" >
<a href="/img_storage/user/{{$user->id}}_gross.jpg" data-lightbox="{{$user->id}}_gross.jpg" data-title="{{ $user->name }}">
<img src="/img_storage/user/{{$user->id}}.jpg" class="mt-3 ml-3" >
</a>
@else
<img src="/img/placeholder/user64x96.jpg" class="mt-3 ml-3" >

View file

@ -25,10 +25,10 @@
<div class="form-group" style="display:flex;">
<label class="ml-2 mt-4" style="width:150px; text-align:left;" for="bild" ><h4>Bild:</h4></label>
@if(file_exists (public_path ('img/user/'.$user->id.'.jpg')))
@if(file_exists (storage_path().'/img_storage/user/'.$user->id.'.jpg'))
<!--File exists -->
<a href="/img/user/{{$user->id}}_gross.jpg" data-lightbox="{{$user->id}}_gross.jpg" data-title="{{ $user->name }}">
<img src="/img/user/{{$user->id}}.jpg" class="mt-3 ml-3" >
<a href="/img_storage/user/{{$user->id}}_gross.jpg" data-lightbox="{{$user->id}}_gross.jpg" data-title="{{ $user->name }}">
<img src="/img_storage/user/{{$user->id}}.jpg" class="mt-3 ml-3" >
</a>
@else
<img src="/img/placeholder/user64x96.jpg" class="mt-3 ml-3" >

View file

@ -50,6 +50,8 @@ Route::get('/tour/{tour_id}/join', 'TourController@join');
Route::get('/tour/{tour_id}/cancelBooking', 'TourController@cancelBooking');
Route::get('/tour/{tour_id}/cancelBookingAdmin/{user_id}', 'TourController@cancelBookingAdmin');
Route::get('/img_storage/{category}/{imageName}','ImageController@getImage');
Auth::routes();
//Route::get('/home', 'HomeController@index')->name('home');

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB