diff --git a/cp/app/Controllers/ApplicationsController.php b/cp/app/Controllers/ApplicationsController.php index 142a68d..e8e11d5 100644 --- a/cp/app/Controllers/ApplicationsController.php +++ b/cp/app/Controllers/ApplicationsController.php @@ -68,12 +68,8 @@ class ApplicationsController extends Controller $invalid_domain = validate_label($domainName, $db); if ($invalid_domain) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid domain name in application', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Invalid domain name'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $valid_tld = false; @@ -88,12 +84,8 @@ class ApplicationsController extends Controller } if (!$valid_tld) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid domain extension in application', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Invalid domain extension'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $domain_already_exist = $db->selectValue( @@ -102,12 +94,8 @@ class ApplicationsController extends Controller ); if ($domain_already_exist) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Application already exists', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Application already exists'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $currentDateTime = new \DateTime(); @@ -125,25 +113,16 @@ class ApplicationsController extends Controller ); if ($phase_details !== 'Application') { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if ($phaseType === 'claims') { if (!isset($data['noticeid']) || $data['noticeid'] === '' || !isset($data['notafter']) || $data['notafter'] === '' || !isset($data['accepted']) || $data['accepted'] === '') { - // Trigger an error or handle the situation as needed - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => "Error: 'noticeid', 'notafter', or 'accepted' cannot be empty when phaseType is 'claims'", - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', "Error creating application: 'noticeid', 'notafter', or 'accepted' cannot be empty when phaseType is 'claims'"); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $noticeid = $data['noticeid']; @@ -187,24 +166,15 @@ class ApplicationsController extends Controller } if (!in_array($label, $labels)) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => "SMD file is not valid for the application being created.", - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: SMD file is not valid for the application being created'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } // Check if current date and time is between notBefore and notAfter $now = new \DateTime(); if (!($now >= $notBefore && $now <= $notAfter)) { - // Current time is outside the valid range, return an error view - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => "Current time is outside the valid range.", - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Current time is outside the valid range in the SMD file'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } // Verify the signature @@ -215,20 +185,12 @@ class ApplicationsController extends Controller $isValid = $xmlSignatureVerifier->verifyXml($xmlContent); if (!$isValid) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => "The XML signature of the SMD file is not valid.", - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: The XML signature of the SMD file is not valid'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } } else { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => "SMD upload is required in the 'sunrise' phase.", - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', "Error creating application: SMD upload is required in the 'sunrise' phase."); + return $response->withHeader('Location', '/application/create')->withStatus(302); } } @@ -238,12 +200,8 @@ class ApplicationsController extends Controller ); if ($domain_already_reserved) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Domain name in application is reserved or restricted', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Domain name in application is reserved or restricted'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $date_add = 12; @@ -257,21 +215,13 @@ class ApplicationsController extends Controller $price = $returnValue['price']; if (!$price) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'The price, period and currency for such TLD are not declared', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: The price, period and currency for such TLD are not declared'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if (($registrar_balance + $creditLimit) < $price) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Low credit: minimum threshold reached', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Low credit: minimum threshold reached'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $nameservers = array_filter($data['nameserver'] ?? [], function($value) { @@ -286,31 +236,19 @@ class ApplicationsController extends Controller if (!empty($nameservers)) { if (count($nameservers) !== count(array_unique($nameservers))) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Duplicate nameservers detected. Please provide unique nameservers.', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Duplicate nameservers detected. Please provide unique nameservers.'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } foreach ($nameservers as $index => $nameserver) { if (preg_match("/^-|^\.-|-\.$|^\.$/", $nameserver)) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid hostName', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Invalid hostName'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if (!preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $nameserver) && strlen($nameserver) < 254) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid hostName', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Invalid hostName'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } } } @@ -320,21 +258,13 @@ class ApplicationsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactRegistrant]); if (!$row) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Registrant does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Registrant does not exist'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } } @@ -343,21 +273,13 @@ class ApplicationsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactAdmin]); if (!$row) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Admin contact does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Admin contact does not exist'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } } @@ -366,21 +288,13 @@ class ApplicationsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactTech]); if (!$row) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Tech contact does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Tech contact does not exist'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } } @@ -389,49 +303,29 @@ class ApplicationsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactBilling]); if (!$row) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Billing contact does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Billing contact does not exist'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } } if (!$authInfo) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Missing application authinfo', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Missing application authinfo'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if (strlen($authInfo) < 6 || strlen($authInfo) > 16) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Password needs to be at least 6 and up to 16 characters long', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Password needs to be at least 6 and up to 16 characters long'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if (!preg_match('/[A-Z]/', $authInfo)) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Password should have both upper and lower case characters', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: Password should have both upper and lower case characters'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $registrant_id = $db->selectValue( @@ -615,12 +509,8 @@ class ApplicationsController extends Controller if ($internal_host) { if (empty($nameserver_ipv4[$index]) && empty($nameserver_ipv6[$index])) { - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Error: No IPv4 or IPv6 addresses provided for internal host', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating application: No IPv4 or IPv6 addresses provided for internal host'); + return $response->withHeader('Location', '/application/create')->withStatus(302); } if (isset($nameserver_ipv4[$index]) && !empty($nameserver_ipv4[$index])) { @@ -684,20 +574,12 @@ class ApplicationsController extends Controller $db->commit(); } catch (Exception $e) { $db->rollBack(); - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Database failure: ' . $e->getMessage(), - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/application/create')->withStatus(302); } catch (\Pinga\Db\Throwable\IntegrityConstraintViolationException $e) { $db->rollBack(); - return view($response, 'admin/domains/createApplication.twig', [ - 'domainName' => $domainName, - 'error' => 'Database failure: ' . $e->getMessage(), - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/application/create')->withStatus(302); } $crdate = $db->selectValue( diff --git a/cp/app/Controllers/ContactsController.php b/cp/app/Controllers/ContactsController.php index 1f4b535..73ba9e8 100644 --- a/cp/app/Controllers/ContactsController.php +++ b/cp/app/Controllers/ContactsController.php @@ -58,36 +58,21 @@ class ContactsController extends Controller $authInfo_pw = $data['authInfo'] ?? null; if (!$contactID) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Please provide a contact ID', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Please provide a contact ID'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } // Validation for contact ID $invalid_identifier = validate_identifier($contactID); if ($invalid_identifier) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => $invalid_identifier, - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: ' . $invalid_identifier); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } $contact = $db->select('SELECT * FROM contact WHERE identifier = ?', [$contactID]); if ($contact) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Contact ID already exists', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Contact ID already exists'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } $result = $db->selectRow('SELECT registrar_id FROM registrar_users WHERE user_id = ?', [$_SESSION['auth_user_id']]); @@ -100,104 +85,59 @@ class ContactsController extends Controller if ($postalInfoIntName) { if (!$postalInfoIntName) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Missing contact name', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Missing contact name'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntName) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntName)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact name', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact name'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if ($postalInfoIntOrg) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntOrg) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntOrg)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact org', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact org'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoIntStreet1) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntStreet1) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntStreet1)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact street', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact street'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoIntStreet2) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntStreet2) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntStreet2)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact street', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact street 2'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoIntStreet3) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntStreet3) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntStreet3)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact street', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact street 3'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoIntCity) || !preg_match('/^[a-z][a-z\-\.\s]{3,}$/i', $postalInfoIntCity)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact city', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact city'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if ($postalInfoIntSp) { if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoIntSp) || !preg_match('/^[A-Z][a-zA-Z\-\.\s]{1,}$/', $postalInfoIntSp)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact state/province', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact state/province'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoIntPc) { if (preg_match('/(^\-)|(\-\-)|(\-$)/', $postalInfoIntPc) || !preg_match('/^[A-Z0-9\-\s]{3,}$/', $postalInfoIntPc)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid contact postal code', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid contact postal code'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } @@ -205,167 +145,92 @@ class ContactsController extends Controller if ($postalInfoLocName) { if (!$postalInfoLocName) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Missing loc contact name', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Missing loc contact name'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocName) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocName)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact name', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact name'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if ($postalInfoLocOrg) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocOrg) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocOrg)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact org', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact org'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoLocStreet1) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocStreet1) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocStreet1)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact street', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact street'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoLocStreet2) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocStreet2) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocStreet2)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact street', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact street 2'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoLocStreet3) { if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocStreet3) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocStreet3)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact street', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact street 3'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoLocCity) || !preg_match('/^[a-z][a-z\-\.\s]{3,}$/i', $postalInfoLocCity)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact city', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact city'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if ($postalInfoLocSp) { if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoLocSp) || !preg_match('/^[A-Z][a-zA-Z\-\.\s]{1,}$/', $postalInfoLocSp)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact state/province', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact state/province'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } if ($postalInfoLocPc) { if (preg_match('/(^\-)|(\-\-)|(\-$)/', $postalInfoLocPc) || !preg_match('/^[A-Z0-9\-\s]{3,}$/', $postalInfoLocPc)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Invalid loc contact postal code', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Invalid loc contact postal code'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } } if ($voice && (!preg_match('/^\+\d{1,3}\.\d{1,14}$/', $voice) || strlen($voice) > 17)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Voice must be (\+[0-9]{1,3}\.[0-9]{1,14})', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Voice must be (\+[0-9]{1,3}\.[0-9]{1,14})'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if ($fax && (!preg_match('/^\+\d{1,3}\.\d{1,14}$/', $fax) || strlen($fax) > 17)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Fax must be (\+[0-9]{1,3}\.[0-9]{1,14})', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Fax must be (\+[0-9]{1,3}\.[0-9]{1,14})'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Email address failed check', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Email address failed check'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if (!$authInfo_pw) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Email contact authinfo', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Email contact authinfo missing'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if ((strlen($authInfo_pw) < 6) || (strlen($authInfo_pw) > 16)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Password needs to be at least 6 and up to 16 characters long', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Password needs to be at least 6 and up to 16 characters long'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } if (!preg_match('/[A-Z]/', $authInfo_pw)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'Password should have both upper and lower case characters', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: Password should have both upper and lower case characters'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } $disclose_voice = isset($data['disclose_voice']) ? 1 : 0; @@ -383,13 +248,8 @@ class ContactsController extends Controller $nin_type = (isset($data['isBusiness']) && $data['isBusiness'] === 'on') ? 'business' : 'personal'; if (!preg_match('/\d/', $nin)) { - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => 'NIN should contain one or more numbers', - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Unable to create contact: NIN should contain one or more numbers'); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } } @@ -480,13 +340,8 @@ class ContactsController extends Controller $db->commit(); } catch (Exception $e) { $db->rollBack(); - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'error' => $e->getMessage(), - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/contact/create')->withStatus(302); } $crdate = $db->selectValue( @@ -494,13 +349,8 @@ class ContactsController extends Controller [$contact_id] ); - return view($response, 'admin/contacts/createContact.twig', [ - 'contactID' => $contactID, - 'crdate' => $crdate, - 'registrars' => $registrars, - 'countries' => $countries, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('success', 'Contact ' . $contactID . ' has been created successfully on ' . $crdate); + return $response->withHeader('Location', '/contacts')->withStatus(302); } $iso3166 = new ISO3166(); diff --git a/cp/app/Controllers/DomainsController.php b/cp/app/Controllers/DomainsController.php index a119b7d..cb50d87 100644 --- a/cp/app/Controllers/DomainsController.php +++ b/cp/app/Controllers/DomainsController.php @@ -148,13 +148,8 @@ class DomainsController extends Controller $invalid_domain = validate_label($domainName, $db); if ($invalid_domain) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid domain name', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid domain name'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $valid_tld = false; @@ -169,13 +164,8 @@ class DomainsController extends Controller } if (!$valid_tld) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid domain extension', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid domain extension'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $domain_already_exist = $db->selectValue( @@ -184,13 +174,8 @@ class DomainsController extends Controller ); if ($domain_already_exist) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Domain name already exists', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Domain name already exists'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $currentDateTime = new \DateTime(); @@ -210,40 +195,20 @@ class DomainsController extends Controller if ($phase_details !== 'First-Come-First-Serve') { if ($phaseType !== 'none') { if ($phaseType == null && $phaseType == '') { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } else if ($phase_details == null) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The launch phase ' . $phaseType . ' is currently not active.', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is currently not active.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } } else if ($phaseType !== 'none') { if ($phaseType == null && $phaseType == '') { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } else if ($phase_details == null) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The launch phase ' . $phaseType . ' is currently not active.', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is currently not active.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } @@ -251,14 +216,8 @@ class DomainsController extends Controller if (!isset($data['noticeid']) || $data['noticeid'] === '' || !isset($data['notafter']) || $data['notafter'] === '' || !isset($data['accepted']) || $data['accepted'] === '') { - // Trigger an error - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => "Error: 'noticeid', 'notafter', or 'accepted' cannot be empty when phaseType is 'claims'", - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', "Error creating domain: 'noticeid', 'notafter', or 'accepted' cannot be empty when phaseType is 'claims'"); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $noticeid = $data['noticeid']; @@ -302,26 +261,15 @@ class DomainsController extends Controller } if (!in_array($label, $labels)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => "SMD file is not valid for the domain name being registered.", - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: SMD file is not valid for the domain name being registered.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } // Check if current date and time is between notBefore and notAfter $now = new \DateTime(); if (!($now >= $notBefore && $now <= $notAfter)) { - // Current time is outside the valid range, return an error view - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => "Current time is outside the valid range.", - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Current time is outside the valid range in the SMD.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } // Verify the signature @@ -332,22 +280,12 @@ class DomainsController extends Controller $isValid = $xmlSignatureVerifier->verifyXml($xmlContent); if (!$isValid) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => "The XML signature of the SMD file is not valid.", - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The XML signature of the SMD file is not valid.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } else { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => "SMD upload is required in the 'sunrise' phase.", - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', "Error creating domain: SMD upload is required in the 'sunrise' phase."); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } @@ -364,25 +302,15 @@ class DomainsController extends Controller $this->container->get('flash')->addMessage('error', 'Domain ' . $domainName . ' is not available: Allocation Token mismatch'); return $response->withHeader('Location', '/domain/create')->withStatus(302); } - } else { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Domain name is reserved or restricted', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + } else { + $this->container->get('flash')->addMessage('error', 'Error creating domain: Domain name is reserved or restricted'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } if ($registrationYears && (($registrationYears < 1) || ($registrationYears > 10))) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Domain period must be from 1 to 10', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Domain period must be from 1 to 10'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } elseif (!$registrationYears) { $registrationYears = 1; } @@ -407,23 +335,13 @@ class DomainsController extends Controller $price = $returnValue['price']; if (!$price) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The price, period and currency for such TLD are not declared', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The price, period and currency for such TLD are not declared'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if (($registrar_balance + $creditLimit) < $price) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Low credit: minimum threshold reached', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Low credit: minimum threshold reached'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $nameservers = array_filter($data['nameserver'] ?? [], function($value) { @@ -438,34 +356,19 @@ class DomainsController extends Controller if (!empty($nameservers)) { if (count($nameservers) !== count(array_unique($nameservers))) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Duplicate nameservers detected. Please provide unique nameservers.', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Duplicate nameservers detected. Please provide unique nameservers.'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } foreach ($nameservers as $index => $nameserver) { if (preg_match("/^-|^\.-|-\.$|^\.$/", $nameserver)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid hostName', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid hostName'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if (!preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $nameserver) && strlen($nameserver) < 254) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid hostName', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid hostName'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } } @@ -475,23 +378,13 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactRegistrant]); if (!$row) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Registrant does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Registrant does not exist'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } @@ -500,23 +393,13 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactAdmin]); if (!$row) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Admin contact does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Admin contact does not exist'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } @@ -525,23 +408,13 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactTech]); if (!$row) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Tech contact does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Tech contact does not exist'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } @@ -550,54 +423,29 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactBilling]); if (!$row) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Billing contact does not exist', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Billing contact does not exist'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if ($clid != $row['clid']) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'The contact requested in the command does NOT belong to the current registrar', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } if (!$authInfo) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Missing domain authinfo', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Missing domain authinfo'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if (strlen($authInfo) < 6 || strlen($authInfo) > 16) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Password needs to be at least 6 and up to 16 characters long', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Password needs to be at least 6 and up to 16 characters long'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if (!preg_match('/[A-Z]/', $authInfo)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Password should have both upper and lower case characters', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Password should have both upper and lower case characters'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $registrant_id = $db->selectValue( @@ -701,47 +549,27 @@ class DomainsController extends Controller // Validate keyTag if (!empty($dsKeyTag)) { if (!is_int($dsKeyTag)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Incomplete key tag provided', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete key tag provided'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if ($dsKeyTag < 0 || $dsKeyTag > 65535) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Incomplete key tag provided', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete key tag provided'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } // Validate alg $validAlgorithms = [8, 13, 14, 15, 16]; if (!empty($dsAlg) && !in_array($dsAlg, $validAlgorithms)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Incomplete algorithm provided', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete algorithm provided'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } // Validate digestType and digest if (!empty($dsDigestType) && !is_int($dsDigestType)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Incomplete digest type provided', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete digest type provided'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $validDigests = [ 2 => 64, // SHA-256 @@ -749,13 +577,8 @@ class DomainsController extends Controller ]; if (!empty($dsDigest)) { if (strlen($dsDigest) != $validDigests[$dsDigestType] || !ctype_xdigit($dsDigest)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid digest length or format', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid digest length or format'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } } @@ -763,46 +586,26 @@ class DomainsController extends Controller // Validate flags $validFlags = [256, 257]; if (!empty($dnskeyFlags) && !in_array($dnskeyFlags, $validFlags)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid flags provided', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid flags provided'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } // Validate protocol if (!empty($dnskeyProtocol) && $dnskeyProtocol != 3) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid protocol provided', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid protocol provided'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } // Validate algKeyData if (!empty($dnskeyAlg)) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid algorithm encoding', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid algorithm encoding'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } // Validate pubKey if (!empty($dnskeyPubKey) && base64_encode(base64_decode($dnskeyPubKey, true)) !== $dnskeyPubKey) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Invalid public key encoding', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid public key encoding'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if (!empty($dsKeyTag)) { @@ -958,13 +761,8 @@ class DomainsController extends Controller if ($internal_host) { if (empty($nameserver_ipv4[$index]) && empty($nameserver_ipv6[$index])) { - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Error: No IPv4 or IPv6 addresses provided for internal host', - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Error creating domain: No IPv4 or IPv6 addresses provided for internal host'); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } if (isset($nameserver_ipv4[$index]) && !empty($nameserver_ipv4[$index])) { @@ -1049,22 +847,12 @@ class DomainsController extends Controller $db->commit(); } catch (Exception $e) { $db->rollBack(); - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Database failure: ' . $e->getMessage(), - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } catch (\Pinga\Db\Throwable\IntegrityConstraintViolationException $e) { $db->rollBack(); - return view($response, 'admin/domains/createDomain.twig', [ - 'domainName' => $domainName, - 'error' => 'Database failure: ' . $e->getMessage(), - 'registrars' => $registrars, - 'registrar' => $registrar, - 'launch_phases' => $launch_phases - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/domain/create')->withStatus(302); } $crdate = $db->selectValue( diff --git a/cp/app/Controllers/FinancialsController.php b/cp/app/Controllers/FinancialsController.php index 144a641..fad6b7e 100644 --- a/cp/app/Controllers/FinancialsController.php +++ b/cp/app/Controllers/FinancialsController.php @@ -167,21 +167,15 @@ class FinancialsController extends Controller $db->commit(); } catch (Exception $e) { $db->rollBack(); - return view($response, 'admin/financials/deposit.twig', [ - 'error' => $e->getMessage(), - 'registrars' => $registrars - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: '.$e->getMessage()); + return $response->withHeader('Location', '/deposit')->withStatus(302); } - return view($response, 'admin/financials/deposit.twig', [ - 'deposit' => $amount, - 'registrars' => $registrars - ]); + $this->container->get('flash')->addMessage('success', 'Deposit successfully added. The registrar\'s account balance has been updated.'); + return $response->withHeader('Location', '/deposit')->withStatus(302); } else { - return view($response, 'admin/financials/deposit.twig', [ - 'error' => 'Invalid entry: Deposit amount must be positive. Please enter a valid amount.', - 'registrars' => $registrars - ]); + $this->container->get('flash')->addMessage('error', 'Invalid entry: Deposit amount must be positive. Please enter a valid amount.'); + return $response->withHeader('Location', '/deposit')->withStatus(302); } } diff --git a/cp/app/Controllers/HostsController.php b/cp/app/Controllers/HostsController.php index 4ababfc..8c54cc7 100644 --- a/cp/app/Controllers/HostsController.php +++ b/cp/app/Controllers/HostsController.php @@ -37,20 +37,12 @@ class HostsController extends Controller if (preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $hostName) && strlen($hostName) < 254) { $host_id_already_exist = $hostModel->getHostByNom($hostName); if ($host_id_already_exist) { - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => 'host name already exists', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating host: host name ' . $hostName . ' already exists'); + return $response->withHeader('Location', '/host/create')->withStatus(302); } } else { - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => 'Invalid host name', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating host: Invalid host name'); + return $response->withHeader('Location', '/host/create')->withStatus(302); } $result = $db->selectRow('SELECT registrar_id FROM registrar_users WHERE user_id = ?', [$_SESSION['auth_user_id']]); @@ -64,24 +56,16 @@ class HostsController extends Controller if ($ipv4) { $ipv4 = normalize_v4_address($ipv4); if (!filter_var($ipv4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => 'Invalid host addr v4', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating host: Invalid host addr v4'); + return $response->withHeader('Location', '/host/create')->withStatus(302); } } if ($ipv6) { $ipv6 = normalize_v6_address($ipv6); if (!filter_var($ipv6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => 'Invalid host addr v6', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating host: Invalid host addr v6'); + return $response->withHeader('Location', '/host/create')->withStatus(302); } } @@ -114,22 +98,14 @@ class HostsController extends Controller } if (!$domain_exist) { - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => 'A host name object can NOT be created in a repository for which no superordinate domain name object exists', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating host: A host name object can NOT be created in a repository for which no superordinate domain name object exists'); + return $response->withHeader('Location', '/host/create')->withStatus(302); } if ($_SESSION['auth_roles'] !== 0) { if ($clid != $clid_domain) { - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => 'The domain name belongs to another registrar, you are not allowed to create hosts for it', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating host: The domain name belongs to another registrar, you are not allowed to create hosts for it'); + return $response->withHeader('Location', '/host/create')->withStatus(302); } } @@ -151,12 +127,8 @@ class HostsController extends Controller $host_id = $db->getLastInsertId(); if (!$ipv4 && !$ipv6) { - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => 'At least one of IPv4 or IPv6 must be provided', - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating host: At least one of IPv4 or IPv6 must be provided'); + return $response->withHeader('Location', '/host/create')->withStatus(302); } if ($ipv4) { @@ -195,12 +167,8 @@ class HostsController extends Controller $db->commit(); } catch (Exception $e) { $db->rollBack(); - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'error' => $e->getMessage(), - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/host/create')->withStatus(302); } $crdate = $db->selectValue( @@ -208,12 +176,8 @@ class HostsController extends Controller [$hostName] ); - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'crdate' => $crdate, - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('success', 'Host ' . $hostName . ' has been created successfully on ' . $crdate); + return $response->withHeader('Location', '/hosts')->withStatus(302); } else { $currentDateTime = new \DateTime(); $crdate = $currentDateTime->format('Y-m-d H:i:s.v'); @@ -242,12 +206,8 @@ class HostsController extends Controller [$hostName] ); - return view($response, 'admin/hosts/createHost.twig', [ - 'hostName' => $hostName, - 'crdate' => $crdate, - 'registrars' => $registrars, - 'registrar' => $registrar, - ]); + $this->container->get('flash')->addMessage('success', 'Host ' . $hostName . ' has been created successfully on ' . $crdate); + return $response->withHeader('Location', '/hosts')->withStatus(302); } } } diff --git a/cp/app/Controllers/RegistrarsController.php b/cp/app/Controllers/RegistrarsController.php index dae12d3..e918820 100644 --- a/cp/app/Controllers/RegistrarsController.php +++ b/cp/app/Controllers/RegistrarsController.php @@ -98,10 +98,8 @@ class RegistrarsController extends Controller // Trim the final semicolon and space $errorText = rtrim($errorText, '; '); - return view($response, 'admin/registrars/create.twig', [ - 'countries' => $countries, - 'error' => $errorText, - ]); + $this->container->get('flash')->addMessage('error', 'Error creating registrar: ' . $errorText); + return $response->withHeader('Location', '/registrar/create')->withStatus(302); } $db->beginTransaction(); @@ -270,16 +268,12 @@ class RegistrarsController extends Controller $db->commit(); } catch (Exception $e) { $db->rollBack(); - return view($response, 'admin/registrars/create.twig', [ - 'error' => $e->getMessage(), - 'countries' => $countries, - ]); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/registrar/create')->withStatus(302); } - return view($response,'admin/registrars/create.twig', [ - 'registrar' => $data['name'], - 'countries' => $countries, - ]); + $this->container->get('flash')->addMessage('success', 'Registrar ' . $data['name'] . ' successfully created and is now active.'); + return $response->withHeader('Location', '/registrars')->withStatus(302); } $iso3166 = new ISO3166(); diff --git a/cp/app/Controllers/SupportController.php b/cp/app/Controllers/SupportController.php index c3bb86f..89f846f 100644 --- a/cp/app/Controllers/SupportController.php +++ b/cp/app/Controllers/SupportController.php @@ -72,12 +72,9 @@ class SupportController extends Controller 'categories' => $categories ]); } - - return view($response, 'admin/support/view.twig', [ - 'categories' => $categories, - 'subject' => $subject, - ]); - + + $this->container->get('flash')->addMessage('success', 'Support ticket ' . $subject . ' has been created successfully!'); + return $response->withHeader('Location', '/support')->withStatus(302); } $db = $this->container->get('db'); diff --git a/cp/resources/views/admin/contacts/createContact.twig b/cp/resources/views/admin/contacts/createContact.twig index 9d86647..e148332 100644 --- a/cp/resources/views/admin/contacts/createContact.twig +++ b/cp/resources/views/admin/contacts/createContact.twig @@ -24,31 +24,7 @@