Big improvement in CP flows

This commit is contained in:
Pinga 2024-01-09 11:47:18 +02:00
parent 7c2e6d4388
commit f3fa1f1855
15 changed files with 244 additions and 961 deletions

View file

@ -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(