diff --git a/cp/app/Controllers/ContactsController.php b/cp/app/Controllers/ContactsController.php index 59f0055..7533da2 100644 --- a/cp/app/Controllers/ContactsController.php +++ b/cp/app/Controllers/ContactsController.php @@ -11,6 +11,7 @@ use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Validation\DNSCheckValidation; use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; use Egulias\EmailValidator\Validation\RFCValidation; +use Brick\Postcode\PostcodeFormatter; class ContactsController extends Controller { @@ -609,6 +610,21 @@ class ContactsController extends Controller $isValid = $validator->isValid($contact['email'], $multipleValidations); $responseData['emailDetails'] = $isValid; } + + if ($verifyPostal == 'on') { + $formatter = new PostcodeFormatter(); + try { + $isValid = $formatter->format($contactPostal[0]['cc'], $contactPostal[0]['pc']); + $responseData['postalDetails'] = $isValid; + } catch (\Brick\Postcode\UnknownCountryException $e) { + $responseData['postalDetails'] = null; + $responseData['postalDetailsI'] = $e; + } catch (\Brick\Postcode\InvalidPostcodeException $e) { + $responseData['postalDetails'] = null; + $responseData['postalDetailsI'] = $e; + } + + } return view($response, 'admin/contacts/validateContact.twig', $responseData); } else { @@ -623,6 +639,72 @@ class ContactsController extends Controller } + public function approveContact(Request $request, Response $response) + { + if ($request->getMethod() === 'POST') { + // Retrieve POST data + $data = $request->getParsedBody(); + $db = $this->container->get('db'); + // Get the current URI + $uri = $request->getUri()->getPath(); + + $identifier = trim($data['identifier']); + + if (!preg_match('/^[a-zA-Z0-9\-]+$/', $identifier)) { + $this->container->get('flash')->addMessage('error', 'Invalid contact ID format'); + return $response->withHeader('Location', '/contacts')->withStatus(302); + } + + $contact = $db->selectRow('SELECT id, identifier, voice, fax, email, nin, nin_type, crdate, clid, disclose_voice, disclose_fax, disclose_email FROM contact WHERE identifier = ?', + [ $identifier ]); + + if ($_SESSION["auth_roles"] != 0) { + $clid = $db->selectValue('SELECT registrar_id FROM registrar_users WHERE user_id = ?', [$_SESSION['auth_user_id']]); + $contact_clid = $contact['clid']; + if ($contact_clid != $clid) { + return $response->withHeader('Location', '/contacts')->withStatus(302); + } + } else { + $clid = $contact['clid']; + } + + if ($contact) { + try { + $db->beginTransaction(); + $currentDateTime = new \DateTime(); + $stamp = $currentDateTime->format('Y-m-d H:i:s.v'); + $db->update( + 'contact', + [ + 'validation' => $data['verify'], + 'validation_stamp' => $stamp, + 'validation_log' => json_encode($data['v_log']), + 'upid' => $clid, + 'lastupdate' => $stamp + ], + [ + 'identifier' => $identifier + ] + ); + $db->commit(); + } catch (Exception $e) { + $db->rollBack(); + $this->container->get('flash')->addMessage('error', 'Database failure during update: ' . $e->getMessage()); + return $response->withHeader('Location', '/contact/update/'.$identifier)->withStatus(302); + } + + $this->container->get('flash')->addMessage('success', 'Contact ' . $identifier . ' has been validated successfully on ' . $stamp); + return $response->withHeader('Location', '/contact/update/'.$identifier)->withStatus(302); + + } else { + // Contact does not exist, redirect to the contacts view + return $response->withHeader('Location', '/contacts')->withStatus(302); + } + + } + + } + public function updateContactProcess(Request $request, Response $response) { if ($request->getMethod() === 'POST') { diff --git a/cp/composer.json b/cp/composer.json index 6e91ba6..42d3c47 100644 --- a/cp/composer.json +++ b/cp/composer.json @@ -17,7 +17,7 @@ "slim/slim": "4.12.0", "slim/twig-view": "^3.3.0", "monolog/monolog": "^3.5.0", - "respect/validation": "^2.2.4", + "respect/validation": "^2.3", "slim/csrf": "^1.3", "slim/flash": "^0.4", "vlucas/phpdotenv": "^5.6", @@ -31,7 +31,7 @@ "gettext/gettext": "^5.7", "punic/punic": "^3.8", "league/iso3166": "^4.3", - "stripe/stripe-php": "^13.3", + "stripe/stripe-php": "^13.11", "robthree/twofactorauth": "^2.1", "lbuchs/webauthn": "^2.1", "bacon/bacon-qr-code": "^2.0", @@ -44,7 +44,9 @@ "selective/xmldsig": "^3.1", "adyen/php-api-library": "^17.1", "giggsey/libphonenumber-for-php-lite": "^8.13", - "egulias/email-validator": "^4.0" + "egulias/email-validator": "^4.0", + "utopia-php/messaging": "^0.9.1", + "brick/postcode": "^0.3.1" }, "autoload": { "psr-4": { diff --git a/cp/resources/views/admin/contacts/updateContact.twig b/cp/resources/views/admin/contacts/updateContact.twig index 91fe3af..7fc4458 100644 --- a/cp/resources/views/admin/contacts/updateContact.twig +++ b/cp/resources/views/admin/contacts/updateContact.twig @@ -165,7 +165,7 @@
{{ phoneDetails ? 'Number valid' : 'Number invalid' }}
+ {{ phoneDetails ? 'Phone format is valid' : 'Phone format is not valid' }}
{{ emailDetails == 1 ? 'Email valid' : 'Email invalid' }}
+ {{ emailDetails == 1 ? 'Email format is valid' : 'Email format is not valid' }}
Validation TBD.
+ {{ postalDetails is empty ? 'Postal code format is not valid' : 'Postal code format is valid' }}