]> gitweb.hamatoma.de Git - piman.git/commitdiff
V 0.1.4 Layout web.php User
authorWinfried Kappeler <winfried.kappeler@infeos.eu>
Mon, 24 Mar 2025 17:16:02 +0000 (18:16 +0100)
committerWinfried Kappeler <winfried.kappeler@infeos.eu>
Mon, 24 Mar 2025 17:16:02 +0000 (18:16 +0100)
- User: new: isGuest()
- Layout: non auth mode: no "administration", "login" button
- web.php: "/": depending in auth mode

CHANGELOG.md
app/Models/User.php
resources/views/layouts/piman.blade.php
routes/web.php

index 19ef767e77e49ff4b3e197c0fae2923af533432e..df59d19f9c3daf21e22c813985958efc5160b670 100644 (file)
@@ -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
index 20ab419aed25b26b97338aeec5d6d6922ae665ac..65e8ddef9b0eb19d6863e5b9685850273be9e2c6 100644 (file)
@@ -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;
+    }
 }
index 7ec66db92526934ed275885961191119d44ad6df..4b05c05b324870c83613d5f348c8c48d5950a575 100644 (file)
             <div id="navbarTop" class="collapse navbar-collapse">
                 <ul class="navbar-nav mr-auto">
                     <li class="nav-item active">
-                        <a class="nav-link" href="/page-showmenu/main">Start</a>
+                        @auth
+                        <a class="nav-link" href="/page-startpage">Start</a>
+                        @else
+                        <a class="nav-link" href="/page-startpublic">Start</a>
+                        @endauth
                     </li>
+                    @auth
                     <li class="nav-item active">
                         <a class="nav-link" href="/menuitem-menu_main">Verwaltung</a>
                     </li>
+                    @endauth
                     <li>
-                        <a class="nav-link" href="/public/doc/Impressum.pdf" target="_blank">{{ __('Imprint') }}</a>
+                        <a class="nav-link" href="/page-showbyname/imprint/1141">{{ __('Imprint') }}</a>
                     </li>
                     <li>
-                        <a class="nav-link" href="/public/doc/Datenschutz.pdf" target="_blank">{{ __('Privacy') }}</a>
+                        <a class="nav-link" href="/page-showbyname/privacy/1141">{{ __('Privacy') }}</a>
                     </li>
                 </ul>
                 <ul id="lkn-navbar-right" class="navbar-nav mr-auto lkn-logout">
                     <li class="nav-item border rounded-3">
                         <a class="nav-link" href="/user-edit-current">{{ session('userName') }}</a>
                     </li>
-                    @endauth
                     <li class="nav-item border rounded-3">
                         <a class="nav-link" href="/user-logout">{{ __('Logout')  }}</a>
                     </li>
+                    @else
+                    <li class="nav-item border rounded-3">
+                        <a class="nav-link" href="/user-login">{{ __('Login')  }}</a>
+                    </li>
+                    @endauth
                 </ul>
            </div>                
         </nav>
index 1699bd942017d765e52a8cc9db1bd29e6d352b10..908ddfca831803b1ee51db0795ea713699c65df7 100644 (file)
@@ -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();