mirror of
https://github.com/standardebooks/web.git
synced 2025-07-18 20:36:38 -04:00
Add admin form to view and edit users
This commit is contained in:
parent
32607fb220
commit
8ad3291a35
35 changed files with 902 additions and 72 deletions
59
www/users/edit.php
Normal file
59
www/users/edit.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?
|
||||
use function Safe\session_unset;
|
||||
|
||||
session_start();
|
||||
|
||||
$exception = HttpInput::SessionObject('exception', Exceptions\AppException::class);
|
||||
$user = HttpInput::SessionObject('user', User::class);
|
||||
$generateNewUuid = HttpInput::Bool(SESSION, 'generate-new-uuid') ?? false;
|
||||
$passwordAction = HttpInput::SessionObject('password-action', Enums\PasswordActionType::class) ?? Enums\PasswordActionType::None;
|
||||
|
||||
try{
|
||||
if($user === null){
|
||||
$user = User::Get(HttpInput::Int(GET, 'user-id'));
|
||||
}
|
||||
|
||||
if(Session::$User === null){
|
||||
throw new Exceptions\LoginRequiredException();
|
||||
}
|
||||
|
||||
if(!Session::$User->Benefits->CanReviewOwnArtwork){
|
||||
throw new Exceptions\InvalidPermissionsException();
|
||||
}
|
||||
|
||||
// We got here because a `User` update had errors and the user has to try again.
|
||||
if($exception){
|
||||
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||
session_unset();
|
||||
}
|
||||
}
|
||||
catch(Exceptions\UserNotFoundException){
|
||||
Template::Emit404();
|
||||
}
|
||||
catch(Exceptions\LoginRequiredException){
|
||||
Template::RedirectToLogin();
|
||||
}
|
||||
catch(Exceptions\InvalidPermissionsException){
|
||||
Template::Emit403(); // No permissions to edit artwork.
|
||||
}
|
||||
?>
|
||||
<?= Template::Header(
|
||||
[
|
||||
'title' => 'Edit user #' . $user->UserId,
|
||||
'css' => ['/css/user.css'],
|
||||
'highlight' => ''
|
||||
]
|
||||
) ?>
|
||||
<main>
|
||||
<section class="narrow">
|
||||
<h1>Edit User #<?= $user->UserId ?></h1>
|
||||
|
||||
<?= Template::Error(['exception' => $exception]) ?>
|
||||
|
||||
<form class="create-update-artwork" method="<?= Enums\HttpMethod::Post->value ?>" action="<?= $user->Url ?>" autocomplete="off">
|
||||
<input type="hidden" name="_method" value="<?= Enums\HttpMethod::Patch->value ?>" />
|
||||
<?= Template::UserForm(['user' => $user, 'isEditForm' => true, 'generateNewUuid' => $generateNewUuid, 'passwordAction' => $passwordAction]) ?>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
<?= Template::Footer() ?>
|
Loading…
Add table
Add a link
Reference in a new issue