Finished the basic contact validation

This commit is contained in:
Pinga 2024-02-19 12:52:25 +02:00
parent 19a4dc4048
commit c43155eb89
6 changed files with 107 additions and 17 deletions

View file

@ -11,6 +11,7 @@ use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\DNSCheckValidation; use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\RFCValidation; use Egulias\EmailValidator\Validation\RFCValidation;
use Brick\Postcode\PostcodeFormatter;
class ContactsController extends Controller class ContactsController extends Controller
{ {
@ -609,6 +610,21 @@ class ContactsController extends Controller
$isValid = $validator->isValid($contact['email'], $multipleValidations); $isValid = $validator->isValid($contact['email'], $multipleValidations);
$responseData['emailDetails'] = $isValid; $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); return view($response, 'admin/contacts/validateContact.twig', $responseData);
} else { } 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) public function updateContactProcess(Request $request, Response $response)
{ {
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {

View file

@ -17,7 +17,7 @@
"slim/slim": "4.12.0", "slim/slim": "4.12.0",
"slim/twig-view": "^3.3.0", "slim/twig-view": "^3.3.0",
"monolog/monolog": "^3.5.0", "monolog/monolog": "^3.5.0",
"respect/validation": "^2.2.4", "respect/validation": "^2.3",
"slim/csrf": "^1.3", "slim/csrf": "^1.3",
"slim/flash": "^0.4", "slim/flash": "^0.4",
"vlucas/phpdotenv": "^5.6", "vlucas/phpdotenv": "^5.6",
@ -31,7 +31,7 @@
"gettext/gettext": "^5.7", "gettext/gettext": "^5.7",
"punic/punic": "^3.8", "punic/punic": "^3.8",
"league/iso3166": "^4.3", "league/iso3166": "^4.3",
"stripe/stripe-php": "^13.3", "stripe/stripe-php": "^13.11",
"robthree/twofactorauth": "^2.1", "robthree/twofactorauth": "^2.1",
"lbuchs/webauthn": "^2.1", "lbuchs/webauthn": "^2.1",
"bacon/bacon-qr-code": "^2.0", "bacon/bacon-qr-code": "^2.0",
@ -44,7 +44,9 @@
"selective/xmldsig": "^3.1", "selective/xmldsig": "^3.1",
"adyen/php-api-library": "^17.1", "adyen/php-api-library": "^17.1",
"giggsey/libphonenumber-for-php-lite": "^8.13", "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": { "autoload": {
"psr-4": { "psr-4": {

View file

@ -165,7 +165,7 @@
<div class="mb-3"> <div class="mb-3">
<a href="/contact/validate/{{ contact.identifier }}" class="btn btn-outline-{% if contact_valid == 0 %}secondary{% elseif contact_valid == 1 %}success{% elseif contact_valid == 2 %}success{% elseif contact_valid == 3 %}info{% endif %} w-100" {% if contact_valid == 1 %}disabled{% elseif contact_valid == 2 %}disabled{% elseif contact_valid == 3 %}disabled{% endif %}> <a href="/contact/validate/{{ contact.identifier }}" class="btn btn-outline-{% if contact_valid == 0 %}secondary{% elseif contact_valid == 1 %}success{% elseif contact_valid == 2 %}success{% elseif contact_valid == 3 %}info{% endif %} w-100" {% if contact_valid == 1 %}disabled{% elseif contact_valid == 2 %}disabled{% elseif contact_valid == 3 %}disabled{% endif %}>
{% if contact_valid == 0 %} {% if contact_valid == 0 %}
Trigger Validation Contact Validation
{% elseif contact_valid == 1 %} {% elseif contact_valid == 1 %}
Validated by Phone Validated by Phone
{% elseif contact_valid == 2 %} {% elseif contact_valid == 2 %}

View file

@ -41,10 +41,16 @@
</span> </span>
{% endif %}</h3> {% endif %}</h3>
<div class="card-actions"> <div class="card-actions">
<a href="/contact/update/{{ contact.identifier }}" class="btn btn-outline-primary"> <form action="/contact/approve" method="post">
{{ csrf.field | raw }}<input type="hidden" name="identifier" value="{{ contact.identifier }}">
<a href="/contact/update/{{ contact.identifier }}" class="btn btn-outline-secondary">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 11l-4 4l4 4m-4 -4h11a4 4 0 0 0 0 -8h-1" /></svg> <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 11l-4 4l4 4m-4 -4h11a4 4 0 0 0 0 -8h-1" /></svg>
{{ __('Back to Contact Update') }} {{ __('Back to Contact Update') }}
</a> </a>
<button type="submit" class="btn btn-outline-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9.615 20h-2.615a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8" /><path d="M14 19l2 2l4 -4" /><path d="M9 8h4" /><path d="M9 12h2" /></svg>
{{ __('Validate Contact') }}
</button>
</div> </div>
</div> </div>
<div class="card-body"> <div class="card-body">
@ -54,8 +60,10 @@
Phone Validation Phone Validation
</h4> </h4>
<div> <div>
<pre><code>{{ phoneDetails ? 'Number valid' : 'Number invalid' }}</code></pre> <pre><code>{{ phoneDetails ? 'Phone format is valid' : 'Phone format is not valid' }}</code></pre>
</div> </div>
<input type="hidden" name="verify" value="1">
<input type="hidden" name="v_log[]" value="{{ phoneDetails ? 'Phone format is valid' : 'Phone format is not valid' }}">
{% endif %} {% endif %}
{% if verifyEmail == 'on' %} {% if verifyEmail == 'on' %}
@ -64,8 +72,10 @@
Email Validation Email Validation
</h4> </h4>
<div> <div>
<pre><code>{{ emailDetails == 1 ? 'Email valid' : 'Email invalid' }}</code></pre> <pre><code>{{ emailDetails == 1 ? 'Email format is valid' : 'Email format is not valid' }}</code></pre>
</div> </div>
<input type="hidden" name="verify" value="2">
<input type="hidden" name="v_log[]" value="{{ emailDetails == 1 ? 'Email format is valid' : 'Email format is not valid' }}">
{% endif %} {% endif %}
{% if verifyPostal == 'on' %} {% if verifyPostal == 'on' %}
@ -74,9 +84,12 @@
Postal Mail Validation Postal Mail Validation
</h4> </h4>
<div> <div>
<pre><code>Validation TBD.</code></pre> <pre><code>{{ postalDetails is empty ? 'Postal code format is not valid' : 'Postal code format is valid' }}</code></pre>
</div> </div>
<input type="hidden" name="verify" value="3">
<input type="hidden" name="v_log[]" value="{{ postalDetails is empty ? 'Postal code format is not valid' : 'Postal code format is valid' }}">
{% endif %} {% endif %}
</form>
</div> </div>
</div> </div>
</div> </div>

View file

@ -75,6 +75,7 @@ $app->group('', function ($route) {
$route->get('/contact/update/{contact}', ContactsController::class . ':updateContact')->setName('updateContact'); $route->get('/contact/update/{contact}', ContactsController::class . ':updateContact')->setName('updateContact');
$route->get('/contact/validate/{contact}', ContactsController::class . ':validateContact')->setName('validateContact'); $route->get('/contact/validate/{contact}', ContactsController::class . ':validateContact')->setName('validateContact');
$route->post('/contact/update', ContactsController::class . ':updateContactProcess')->setName('updateContactProcess'); $route->post('/contact/update', ContactsController::class . ':updateContactProcess')->setName('updateContactProcess');
$route->post('/contact/approve', ContactsController::class . ':approveContact')->setName('approveContact');
$route->map(['GET', 'POST'], '/contact/delete/{contact}', ContactsController::class . ':deleteContact')->setName('deleteContact'); $route->map(['GET', 'POST'], '/contact/delete/{contact}', ContactsController::class . ':deleteContact')->setName('deleteContact');
$route->get('/hosts', HostsController::class .':listHosts')->setName('listHosts'); $route->get('/hosts', HostsController::class .':listHosts')->setName('listHosts');

View file

@ -399,20 +399,12 @@ This command will install the dependencies defined in your ```composer.json``` f
### Install Optional Dependencies: ### Install Optional Dependencies:
Execute one of the following commands to install the optional dependencies: Execute the following command to install the optional dependencies:
```bash
composer require utopia-php/messaging
```
or
```bash ```bash
composer require phpmailer/phpmailer composer require phpmailer/phpmailer
``` ```
This command will install one of the packages which are essential for the mailing system of the control panel to function correctly.
### Creating an Admin User: ### Creating an Admin User:
1. Navigate to the 'bin' Directory: Change to the 'bin' subdirectory where the admin user creation script is located. (```create_admin_user.php```) 1. Navigate to the 'bin' Directory: Change to the 'bin' subdirectory where the admin user creation script is located. (```create_admin_user.php```)