ImageController serving images only for authorized users that are MEMBER or ADMIN
24
motorradig/app/Http/Controllers/ImageController.php
Normal 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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
|
@ -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'),
|
||||
|
|
|
|||
BIN
motorradig/public/img/placeholder/icon_unknown.png
Normal file
|
After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 100 KiB |
|
|
@ -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" >
|
||||
|
|
|
|||
|
|
@ -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" >
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
BIN
motorradig/storage/img_storage/user/1.jpg
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
motorradig/storage/img_storage/user/1_gross.jpg
Normal file
|
After Width: | Height: | Size: 100 KiB |