-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ba2ddc
commit 7254d21
Showing
29 changed files
with
635 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class IsAdmin | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param Closure(Request): (Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
if ($request->user()->role !== "admin") { | ||
return redirect("/"); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\User; | ||
use Closure; | ||
use Illuminate\View\View; | ||
use LivewireUI\Modal\ModalComponent; | ||
|
||
class DeleteUser extends ModalComponent | ||
{ | ||
public User $user; | ||
|
||
public function render(): View|Closure|string | ||
{ | ||
return view("livewire.delete-user"); | ||
} | ||
|
||
public function delete(): void | ||
{ | ||
if (!$this->user->exists()) abort(400, message: "User does not exist"); | ||
|
||
$this->user->delete(); | ||
$this->closeModal(); | ||
|
||
$this->js("window.location.reload()"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\User; | ||
use Closure; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\View\View; | ||
use LivewireUI\Modal\ModalComponent; | ||
use Throwable; | ||
|
||
class EditUser extends ModalComponent | ||
{ | ||
public User $user; | ||
public string $newPassword = ""; | ||
|
||
public function render(): View|Closure|string | ||
{ | ||
return view("livewire.edit-user"); | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
public function save(): void | ||
{ | ||
$this->user->password = Hash::make($this->newPassword); | ||
|
||
$this->user->saveOrFail(); | ||
$this->closeModal(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\View\Pages; | ||
|
||
use App\Http\Resources\BookResource; | ||
use App\Interfaces\PageComponent; | ||
use App\Models\Book; | ||
use App\Models\User; | ||
use Closure; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Http\Request; | ||
|
||
class UsersPage extends PageComponent | ||
{ | ||
/** | ||
* Get the view / contents that represent the component. | ||
*/ | ||
protected function _render(Request $request): View|Closure|string | ||
{ | ||
return view("admin.users", [ | ||
"users" => User::all() | ||
->map(fn($user) => [ | ||
"id" => $user->id, | ||
"name" => $user->name, | ||
"username" => $user->username, | ||
]) | ||
->toArray() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.