Add $user (authed user) to views
This commit is contained in:
parent
ca666e456a
commit
2c406ba3e9
app/Http
resources/views
domain
layouts/partials
user
@ -36,6 +36,7 @@ class Kernel extends HttpKernel
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
|
||||
\App\Http\Middleware\AddUserToView::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
|
50
app/Http/Middleware/AddUserToView.php
Normal file
50
app/Http/Middleware/AddUserToView.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class AddUserToView
|
||||
{
|
||||
/**
|
||||
* The View Factory.
|
||||
*
|
||||
* @var \Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
protected Factory $factory;
|
||||
|
||||
/**
|
||||
* The Authenticated user, if any.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
protected ?Authenticatable $user;
|
||||
|
||||
/**
|
||||
* Create a new Share Authenticated User instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\View\Factory $factory
|
||||
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
|
||||
*/
|
||||
public function __construct(Factory $factory,Authenticatable $user=NULL)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$this->factory->share('user',$this->user);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -150,7 +150,7 @@
|
||||
@guest
|
||||
To start an application to join this network please <a href="{{ url('login') }}">login</a>.
|
||||
@else
|
||||
@if(Auth::user()->isMember($o))
|
||||
@if($user->isMember($o))
|
||||
@else
|
||||
This website is not ready to take applications yet, check back soon!
|
||||
@endif
|
||||
|
@ -27,7 +27,7 @@
|
||||
<dl>
|
||||
<dt>Expore Networks</dt>
|
||||
@foreach (\App\Models\Domain::active()
|
||||
->when(! \Illuminate\Support\Facades\Auth::check(),function($query) { return $query->public(); })
|
||||
->when((! $user),function($query) { return $query->public(); })
|
||||
->orderBy('name')->get() as $o)
|
||||
<dd><a href="{{ url('network',['id'=>$o->id]) }}" title="{{ $o->description }}">{{ $o->name }}</a></dd>
|
||||
@endforeach
|
||||
|
@ -15,8 +15,8 @@
|
||||
|
||||
<ul class="float-end">
|
||||
@auth
|
||||
<li class="{{ Auth::user()->switched ? 'switched' : '' }}"><a href="{{ url('settings') }}"><span>{{ Auth::user()->name }}</span></a></li>
|
||||
@if(Auth::user()->switched)
|
||||
<li class="{{ $user->switched ? 'switched' : '' }}"><a href="{{ url('settings') }}"><span>{{ $user->name }}</span></a></li>
|
||||
@if($user->switched)
|
||||
<li><a href="{{ url('admin/switch/stop') }}">
|
||||
<span>Switch Back</span>
|
||||
</a></li>
|
||||
|
@ -62,11 +62,11 @@
|
||||
<div class="col-4">
|
||||
<label for="admin" class="form-label">Site Admin</label>
|
||||
<div class="input-group">
|
||||
<div class="btn-group" role="group" @if($o->id == Auth::user()->id)data-bs-toggle="tooltip" title="You cannot demote yourself" @endif>
|
||||
<div class="btn-group" role="group" @if($user->id == $o->id)data-bs-toggle="tooltip" title="You cannot demote yourself" @endif>
|
||||
<input type="radio" class="btn-check" name="admin" id="admin_yes" value="1" required @cannot('admin',$o)disabled @endcannot @if(old('admin',$o->admin))checked @endif>
|
||||
<label class="btn btn-outline-success" for="admin_yes">Yes</label>
|
||||
|
||||
<input type="radio" class="btn-check btn-danger" name="admin" id="admin_no" value="0" required @if($o->id == Auth::user()->id || Auth::user()->cannot('admin',$o)) disabled @endif @if(! old('admin',$o->admin))checked @endif>
|
||||
<input type="radio" class="btn-check btn-danger" name="admin" id="admin_no" value="0" required @if(($user->id == $o->id) || $user->cannot('admin',$o)) disabled @endif @if(! old('admin',$o->admin))checked @endif>
|
||||
<label class="btn btn-outline-danger" for="admin_no">No</label>
|
||||
</div>
|
||||
</div>
|
||||
@ -100,7 +100,7 @@
|
||||
@endsection
|
||||
|
||||
@section('page-scripts')
|
||||
@if($o->id == Auth::user()->id)
|
||||
@if($user->id == $o->id)
|
||||
<script>
|
||||
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
||||
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
||||
|
@ -28,7 +28,7 @@
|
||||
<tbody>
|
||||
@foreach (\App\Models\User::orderBy('email')->cursor() as $oo)
|
||||
<tr class="{{ $oo->admin ? 'admin' : '' }}">
|
||||
<td><a href="{{ url('user/addedit',[$oo->id]) }}">{{ $oo->id }}</a> @if(Auth::user()->admin && (Auth::id() !== $oo->id))<span class="float-end"><a href="{{ url('admin/switch/start',[$oo->id]) }}"><i class="bi bi-person-bounding-box"></i></a></span>@endif</td>
|
||||
<td><a href="{{ url('user/addedit',[$oo->id]) }}">{{ $oo->id }}</a> @if($user->admin && ($user->id !== $oo->id))<span class="float-end"><a href="{{ url('admin/switch/start',[$oo->id]) }}"><i class="bi bi-person-bounding-box"></i></a></span>@endif</td>
|
||||
<td>{{ $oo->email }}</td>
|
||||
<td>{{ $oo->name }}</td>
|
||||
<td>{{ $oo->active ? 'YES' : 'NO' }}</td>
|
||||
|
Loading…
Reference in New Issue
Block a user