Merge branch 'logging' into 'main'

Logging

See merge request ase22ws/abschlussprojekt-device-manager-timon-lorenz!6
This commit is contained in:
lot17014 2023-04-04 16:46:55 +02:00
commit d24d167436
16 changed files with 152 additions and 6 deletions

View File

@ -7,6 +7,7 @@
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Log;
class DeviceController extends Controller class DeviceController extends Controller
{ {
@ -39,6 +40,8 @@ public function store(Request $request)
Device::create($formFields); Device::create($formFields);
Log::info('Device saved successfully');
return redirect('/devices'); return redirect('/devices');
} }
@ -63,6 +66,8 @@ public function update(Device $device, Request $request)
$device->update($formFields); $device->update($formFields);
Log::info('Device updated successfully');
return back(); return back();
} }
@ -70,6 +75,7 @@ public function destroy(Device $device): RedirectResponse
{ {
$this->authorize('admin-only'); $this->authorize('admin-only');
$device->delete(); $device->delete();
Log::info('Device deleted successfully');
return redirect('devices'); return redirect('devices');
} }

View File

@ -5,6 +5,7 @@
use App\Models\Device; use App\Models\Device;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\LocationTransaction; use App\Models\LocationTransaction;
use Illuminate\Support\Facades\Log;
class LocationTransactionController extends Controller class LocationTransactionController extends Controller
{ {
@ -23,6 +24,8 @@ public function store(Device $device, Request $request)
$formFields['device_id'] = $device->device_id; $formFields['device_id'] = $device->device_id;
LocationTransaction::create($formFields); LocationTransaction::create($formFields);
Log::info('Location saved successfully');
return redirect('/'); return redirect('/');
} }
@ -42,6 +45,8 @@ public function update(LocationTransaction $location, Request $request)
$location->update($formFields); $location->update($formFields);
Log::info('Location updated successfully');
return redirect('/'); return redirect('/');
} }
@ -49,6 +54,9 @@ public function destroy(LocationTransaction $location)
{ {
$this->authorize('admin-only'); $this->authorize('admin-only');
$location->delete(); $location->delete();
Log::info('Location deleted successfully');
return back(); return back();
} }
} }

View File

@ -5,6 +5,7 @@
use App\Models\Device; use App\Models\Device;
use App\Models\OwnerTransaction; use App\Models\OwnerTransaction;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class OwnerTransactionController extends Controller class OwnerTransactionController extends Controller
{ {
@ -23,6 +24,8 @@ public function store(Device $device, Request $request)
$formFields['device_id'] = $device->device_id; $formFields['device_id'] = $device->device_id;
OwnerTransaction::create($formFields); OwnerTransaction::create($formFields);
Log::info('Owner saved successfully');
return redirect('/'); return redirect('/');
} }
@ -42,6 +45,8 @@ public function update(OwnerTransaction $owner, Request $request)
$owner->update($formFields); $owner->update($formFields);
Log::info('Owner updated successfully');
return redirect('/'); return redirect('/');
} }
@ -49,6 +54,9 @@ public function destroy(OwnerTransaction $owner)
{ {
$this->authorize('admin-only'); $this->authorize('admin-only');
$owner->delete(); $owner->delete();
Log::info('Owner deleted successfully');
return back(); return back();
} }
} }

View File

@ -3,8 +3,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Device; use App\Models\Device;
use App\Models\PurchasingInformation;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class PurchasingInformationController extends Controller class PurchasingInformationController extends Controller
{ {
@ -27,6 +27,8 @@ public function update(Device $device, Request $request)
$device->purchasing->update($formFields); $device->purchasing->update($formFields);
Log::info('Purchasing Information updated successfully');
return redirect('/'); return redirect('/');
} }
} }

View File

@ -3,8 +3,9 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\User; use App\Models\User;
use Illuminate\Validation\Rule;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Log;
class UserController extends Controller class UserController extends Controller
{ {
@ -29,6 +30,8 @@ public function store(Request $request)
$user = User::create($formFields); $user = User::create($formFields);
auth()->login($user); auth()->login($user);
Log::info('User successfully created');
return redirect('/home'); return redirect('/home');
} }
@ -47,6 +50,8 @@ public function authenticate(Request $request)
if (auth()->attempt($formFields)) { if (auth()->attempt($formFields)) {
$request->session()->regenerate(); $request->session()->regenerate();
Log::info('User authenticated successfully');
return redirect('/home'); return redirect('/home');
} }
} }
@ -58,6 +63,8 @@ public function logout(Request $request)
$request->session()->invalidate(); $request->session()->invalidate();
$request->session()->regenerateToken(); $request->session()->regenerateToken();
Log::info('User successfully logged out');
return redirect('/home'); return redirect('/home');
} }
} }

View File

@ -3,6 +3,7 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Opcodes\LogViewer\Facades\LogViewer;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
@ -19,6 +20,8 @@ public function register(): void
*/ */
public function boot(): void public function boot(): void
{ {
// LogViewer::auth(function ($request) {
return $request->user()->has_admin_privileges ?? false;
});
} }
} }

View File

@ -9,7 +9,8 @@
"guzzlehttp/guzzle": "^7.2", "guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.0", "laravel/framework": "^10.0",
"laravel/sanctum": "^3.2", "laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8" "laravel/tinker": "^2.8",
"opcodesio/log-viewer": "^2.4"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.9.1", "fakerphp/faker": "^1.9.1",

View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "121ea3a2fffe49b3ef9aa4d064b28c19", "content-hash": "c44663c5494a74be165db681dcf19ddb",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -2203,6 +2203,84 @@
], ],
"time": "2023-02-08T01:06:31+00:00" "time": "2023-02-08T01:06:31+00:00"
}, },
{
"name": "opcodesio/log-viewer",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/opcodesio/log-viewer.git",
"reference": "eed37452d580e8929045e34dc7016420d9bd9bcd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/opcodesio/log-viewer/zipball/eed37452d580e8929045e34dc7016420d9bd9bcd",
"reference": "eed37452d580e8929045e34dc7016420d9bd9bcd",
"shasum": ""
},
"require": {
"illuminate/contracts": "^8.0|^9.0|^10.0",
"php": "^8.0"
},
"conflict": {
"arcanedev/log-viewer": "^8.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.2",
"itsgoingd/clockwork": "^5.1",
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0",
"orchestra/testbench": "^7.6|^8.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpunit/phpunit": "^9.5",
"spatie/test-time": "^1.3"
},
"suggest": {
"guzzlehttp/guzzle": "Required for multi-host support. ^7.2"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Opcodes\\LogViewer\\LogViewerServiceProvider"
],
"aliases": {
"LogViewer": "Opcodes\\LogViewer\\Facades\\LogViewer"
}
}
},
"autoload": {
"psr-4": {
"Opcodes\\LogViewer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Arunas Skirius",
"email": "arukomp@gmail.com",
"role": "Developer"
}
],
"description": "Fast and easy-to-use log viewer for your Laravel application",
"homepage": "https://github.com/opcodesio/log-viewer",
"keywords": [
"arukompas",
"better-log-viewer",
"laravel",
"log viewer",
"logs",
"opcodesio"
],
"support": {
"issues": "https://github.com/opcodesio/log-viewer/issues",
"source": "https://github.com/opcodesio/log-viewer/tree/v2.4.0"
},
"time": "2023-03-31T07:50:32+00:00"
},
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
"version": "1.9.1", "version": "1.9.1",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,19 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

View File

@ -0,0 +1,7 @@
{
"/app.js": "/app.js?id=2a99c3e02b0ac95a07b0b1ee6c098c2a",
"/app.css": "/app.css?id=2d577fa607de6eeef7cfb84d3b72b864",
"/img/log-viewer-128.png": "/img/log-viewer-128.png?id=d576c6d2e16074d3f064e60fe4f35166",
"/img/log-viewer-32.png": "/img/log-viewer-32.png?id=f8ec67d10f996aa8baf00df3b61eea6d",
"/img/log-viewer-64.png": "/img/log-viewer-64.png?id=8902d596fc883ca9eb8105bb683568c6"
}

View File

@ -3,4 +3,8 @@
@section('content') @section('content')
<h1>Welcome</h1> <h1>Welcome</h1>
<a href="/devices">To List</a> <a href="/devices">To List</a>
<br/>
@can('admin-only')
<a href="/log-viewer">To Log Viewer</a>
@endcan
@endsection @endsection