getAccessChecker()->canManageUsers()) { throw new Forbidden(); } if ($this->request->isPost()) { try { $validation = new Validation([ 'name' => 'required|length_between:3,36', 'password' => 'required|length_between:6,36', ]); $validation->validate($_POST); $user = $this->getAuth()->getUserFromSession(); $addingUserId = Uuid::uuid4(); User::add( $addingUserId, $_POST['name'], $_POST['password'], Role::user(), $user->id ); $this->response->redirect('/users/' . $addingUserId); } catch (\LogicException $e) { $this->renderView(['error' => $e->getMessage(), 'name' => $_POST['name']]); return; } } $this->renderView(); } private function getAuth(): Auth { return new Auth(); } private function getAccessChecker(): AccessChecker { return new AccessChecker(); } }