From a63c6a44ed049b82548ddf6d070aae46c38eb671 Mon Sep 17 00:00:00 2001 From: Winfried Kappeler Date: Mon, 24 Mar 2025 18:16:02 +0100 Subject: [PATCH] V 0.1.4 Layout web.php User - User: new: isGuest() - Layout: non auth mode: no "administration", "login" button - web.php: "/": depending in auth mode --- CHANGELOG.md | 6 ++++ app/Models/User.php | 45 +++++++++++++++++++++++++ resources/views/layouts/piman.blade.php | 18 +++++++--- routes/web.php | 13 +++++-- 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19ef767..df59d19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# V 0.1.4 Layout + +- User: new: isGuest() +- Layout: non auth mode: no "administration", "login" button +- web.php: "/": depending in auth mode + # V 0.1.3 i18n # V 0.1.2 view/change diff --git a/app/Models/User.php b/app/Models/User.php index 20ab419..65e8dde 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,7 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Support\Facades\Auth; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -48,4 +49,48 @@ class User extends Authenticatable ]; } + /** + * Returns the role of the user. + * + * @return Role the role of the user + */ + protected function findRole() + { + if ($this->role == null){ + $this->role = Role::find($this->role_id); + } + return $this->role; + } + /** + * Tests whether the user has a role with a priority less than or equal to the given priority. The lower the priority, the more powerful the role. + * @param int $priority the priority to test against + * @return bool True if the user has a role with a priority less than or equal to the given priority, False otherwise + */ + public function hasRole(int $priority): bool + { + $role = $this->findRole(); + $rc = $this->role->priority <= $priority; + return $rc; + } + /** + * Tests whether the user is an admin. + + * @return bool True if the user is an admin, False otherwise + */ + public function isAdmin(): bool + { + $this->findRole(); + $rc = $this->role->priority <= 19; + return $rc; + } + /** + * Tests whether the user is a guest (not logged in). + + * @return bool True if the user is a guest + */ + public static function isGuest(): bool + { + $rc = ! Auth::check(); + return $rc; + } } diff --git a/resources/views/layouts/piman.blade.php b/resources/views/layouts/piman.blade.php index 7ec66db..4b05c05 100644 --- a/resources/views/layouts/piman.blade.php +++ b/resources/views/layouts/piman.blade.php @@ -25,16 +25,22 @@ diff --git a/routes/web.php b/routes/web.php index 1699bd9..908ddfc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,9 +19,16 @@ use App\Http\Controllers\MandatorController; use App\Http\Controllers\AccountController; use App\Http\Controllers\TransactionController; -Route::get('/', function () { - return redirect('/menuitem-menu_main'); -}); +if (User::isGuest()) { + Route::get('/', function () { + return redirect('/page-startpublic'); + }); + +} else { + Route::get('/', function () { + return redirect('/page-start'); + }); +} RoleController::routes(); SPropertyController::routes(); UserController::routes(); -- 2.39.5