More work on contact validation

This commit is contained in:
Pinga 2024-02-18 16:40:30 +02:00
parent 504bb1b1eb
commit 159228e303
5 changed files with 169 additions and 6 deletions

View file

@ -523,6 +523,81 @@ class ContactsController extends Controller
} }
public function validateContact(Request $request, Response $response, $args)
{
$db = $this->container->get('db');
// Get the current URI
$uri = $request->getUri()->getPath();
if ($args) {
$args = trim($args);
if (!preg_match('/^[a-zA-Z0-9\-]+$/', $args)) {
$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 = ?',
[ $args ]);
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) {
$registrars = $db->selectRow('SELECT id, clid, name FROM registrar WHERE id = ?', [$contact['clid']]);
$iso3166 = new ISO3166();
$countries = $iso3166->all();
$contactStatus = $db->selectRow('SELECT status FROM contact_status WHERE contact_id = ?',
[ $contact['id'] ]);
$contactAuth = $db->selectRow('SELECT authinfo FROM contact_authInfo WHERE contact_id = ?',
[ $contact['id'] ]);
$contactPostal = $db->select('SELECT * FROM contact_postalInfo WHERE contact_id = ?',
[ $contact['id'] ]);
$responseData = [
'contact' => $contact,
'contactStatus' => $contactStatus,
'contactAuth' => $contactAuth,
'contactPostal' => $contactPostal,
'registrars' => $registrars,
'countries' => $countries,
'currentUri' => $uri
];
$verifyPhone = $db->selectValue("SELECT value FROM settings WHERE name = 'verifyPhone'");
$verifyEmail = $db->selectValue("SELECT value FROM settings WHERE name = 'verifyEmail'");
$verifyPostal = $db->selectValue("SELECT value FROM settings WHERE name = 'verifyPostal'");
if ($verifyPhone == 'on' || $verifyEmail == 'on' || $verifyPostal == 'on') {
$contact_validation = $db->selectRow('SELECT validation, validation_stamp, validation_log FROM contact WHERE identifier = ?', [ $args ]);
$responseData['contact_valid'] = $contact_validation['validation'];
$responseData['validation_enabled'] = true;
$responseData['verifyPhone'] = $verifyPhone;
$responseData['verifyEmail'] = $verifyEmail;
$responseData['verifyPostal'] = $verifyPostal;
}
return view($response, 'admin/contacts/validateContact.twig', $responseData);
} else {
// Contact does not exist, redirect to the contacts view
return $response->withHeader('Location', '/contacts')->withStatus(302);
}
} else {
// 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

@ -163,7 +163,7 @@
{% if validation_enabled is not null %} {% if validation_enabled is not null %}
<div class="mb-3"> <div class="mb-3">
<button 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 Trigger Validation
{% elseif contact_valid == 1 %} {% elseif contact_valid == 1 %}
@ -173,7 +173,7 @@
{% elseif contact_valid == 3 %} {% elseif contact_valid == 3 %}
Validated by Postal Mail Validated by Postal Mail
{% endif %} {% endif %}
</button> </a>
</div> </div>
{% endif %} {% endif %}

View file

@ -0,0 +1,87 @@
{% extends "layouts/app.twig" %}
{% block title %}{{ __('Contact Validation') }}{% endblock %}
{% block content %}
<div class="page-wrapper">
<!-- Page header -->
<div class="page-header d-print-none">
<div class="container-xl">
<div class="row g-2 align-items-center">
<div class="col">
<!-- Page pre-title -->
<div class="page-pretitle">
{{ __('Overview') }}
</div>
<h2 class="page-title">
{{ __('Contact Validation') }}
</h2>
</div>
</div>
</div>
</div>
<!-- Page body -->
<div class="page-body">
<div class="container-xl">
<div class="col-12">
<div class="card mb-3">
<div class="card-header">
<h3 class="card-title">{{ __('Contact') }} {{ contact.identifier }}&nbsp;<span class="status status-green">{{ contactStatus.status }}</span>{% if contactLinked is not null %}&nbsp;<span class="status status-info">{{ __('linked') }}</span>{% endif %}
{% if validation_enabled is not null %}
<span class="status {% if contact_valid == 0 %}status-warning{% elseif contact_valid == 1 %}status-success{% elseif contact_valid == 2 %}status-success{% elseif contact_valid == 3 %}status-info{% endif %}" title="{% if contact_valid == 0 %}Pending Validation{% elseif contact_valid == 1 %}Validated by Phone{% elseif contact_valid == 2 %}Validated by Email{% elseif contact_valid == 3 %}Validated by Postal Mail{% endif %}">
{% if contact_valid == 0 %}
Pending Validation
{% elseif contact_valid == 1 %}
Validated by Phone
{% elseif contact_valid == 2 %}
Validated by Email
{% elseif contact_valid == 3 %}
Validated by Postal Mail
{% endif %}
</span>
{% endif %}</h3>
<div class="card-actions">
<a href="/contact/update/{{ contact.identifier }}" 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 11l-4 4l4 4m-4 -4h11a4 4 0 0 0 0 -8h-1" /></svg>
{{ __('Back to Contact Update') }}
</a>
</div>
</div>
<div class="card-body">
{% if verifyPhone == 'on' %}
{# The content you want to echo if verifyPhone is 'on' #}
<h4>
Phone verification is enabled.
</h4>
<div>
<pre><code>Validation TBD.</code></pre>
</div>
{% endif %}
{% if verifyEmail == 'on' %}
{# The content you want to echo if verifyEmail is 'on' #}
<h4>
Email verification is enabled.
</h4>
<div>
<pre><code>Validation TBD.</code></pre>
</div>
{% endif %}
{% if verifyPostal == 'on' %}
{# The content you want to echo if verifyPostal is 'on' #}
<h4>
Postal Mail verification is enabled.
</h4>
<div>
<pre><code>Validation TBD.</code></pre>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% include 'partials/footer.twig' %}
</div>
{% endblock %}

View file

@ -83,11 +83,11 @@
</div> </div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label">{{ __('Contact Verification') }}</label> <label class="form-label">{{ __('Contact Validation') }}</label>
<div class="divide-y"> <div class="divide-y">
<div> <div>
<label class="row"> <label class="row">
<span class="col">{{ __('Verify by Phone') }}</span> <span class="col">{{ __('Validate by Phone') }}</span>
<span class="col-auto"> <span class="col-auto">
<label class="form-check form-check-single form-switch"> <label class="form-check form-check-single form-switch">
<input class="form-check-input" type="checkbox" name="verifyPhone" {% if verifyPhone == 'on' %}checked{% endif %}> <input class="form-check-input" type="checkbox" name="verifyPhone" {% if verifyPhone == 'on' %}checked{% endif %}>
@ -97,7 +97,7 @@
</div> </div>
<div> <div>
<label class="row"> <label class="row">
<span class="col">{{ __('Verify by Email') }}</span> <span class="col">{{ __('Validate by Email') }}</span>
<span class="col-auto"> <span class="col-auto">
<label class="form-check form-check-single form-switch"> <label class="form-check form-check-single form-switch">
<input class="form-check-input" type="checkbox" name="verifyEmail" {% if verifyEmail == 'on' %}checked{% endif %}> <input class="form-check-input" type="checkbox" name="verifyEmail" {% if verifyEmail == 'on' %}checked{% endif %}>
@ -107,7 +107,7 @@
</div> </div>
<div> <div>
<label class="row"> <label class="row">
<span class="col">{{ __('Verify by Postal Mail') }}</span> <span class="col">{{ __('Validate by Postal Mail') }}</span>
<span class="col-auto"> <span class="col-auto">
<label class="form-check form-check-single form-switch"> <label class="form-check form-check-single form-switch">
<input class="form-check-input" type="checkbox" name="verifyPostal" {% if verifyPostal == 'on' %}checked{% endif %}> <input class="form-check-input" type="checkbox" name="verifyPostal" {% if verifyPostal == 'on' %}checked{% endif %}>

View file

@ -73,6 +73,7 @@ $app->group('', function ($route) {
$route->map(['GET', 'POST'], '/contact/create', ContactsController::class . ':createContact')->setName('createContact'); $route->map(['GET', 'POST'], '/contact/create', ContactsController::class . ':createContact')->setName('createContact');
$route->get('/contact/view/{contact}', ContactsController::class . ':viewContact')->setName('viewContact'); $route->get('/contact/view/{contact}', ContactsController::class . ':viewContact')->setName('viewContact');
$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->post('/contact/update', ContactsController::class . ':updateContactProcess')->setName('updateContactProcess'); $route->post('/contact/update', ContactsController::class . ':updateContactProcess')->setName('updateContactProcess');
$route->map(['GET', 'POST'], '/contact/delete/{contact}', ContactsController::class . ':deleteContact')->setName('deleteContact'); $route->map(['GET', 'POST'], '/contact/delete/{contact}', ContactsController::class . ':deleteContact')->setName('deleteContact');