added error check on domain creation

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-02-13 16:35:38 +01:00
parent 8f2545dd7e
commit f1732c4f26

View File

@ -361,14 +361,14 @@ class RequestController
function handleDomainPostRequest(): void
{
$name = $_POST['name'] ?? '';
$panelID = intval(value: $_POST['panel_id'] ?? 0);
$panel = $_POST['panel'] ?? '';
$content = $_POST['content'] ?? '';
if (empty($name)) {
$this->header = "400 Bad Request";
$this->status = "400 Bad Request";
$this->message = "A name is required";
} else {
if (empty($a) && empty($aaaa) && empty($panelID)) {
if (empty($a) && empty($aaaa) && empty($panel)) {
$this->header = "400 Bad Request";
$this->status = "400 Bad Request";
$this->message = "At least one IP address or panel ID is required.";
@ -379,9 +379,14 @@ class RequestController
$this->message = "Domain: $name already exists.";
} else {
$domain = new Domain(name: $name, content: $content);
$result = $this->domainRepository->insert(domain: $domain);
$this->status = "201 Created";
$this->message = $result;
if ($result = $this->domainRepository->insert(domain: $domain)) {
$this->status = "201 Created";
$this->message = $result;
} else {
$this->header = "500 Server error";
$this->status = "500 Server error";
$this->message = $result;
}
}
}
}