Move the consent creation process to when the appointment gets created and not earlier

This commit is contained in:
Alex Tselegidis 2022-03-25 12:44:05 +01:00
parent afe21e3960
commit e4e285931f
4 changed files with 54 additions and 69 deletions

View file

@ -37,6 +37,7 @@ class Booking extends EA_Controller {
$this->load->model('services_model');
$this->load->model('customers_model');
$this->load->model('settings_model');
$this->load->model('consents_model');
$this->load->library('timezones');
$this->load->library('synchronization');
@ -474,6 +475,30 @@ class Booking extends EA_Controller {
$appointment['color'] = $service['color'];
}
$customer_ip = $this->input->ip_address();
// Create the consents (if needed).
$consent = [
'first_name' => $customer['first_name'] ?? '-',
'last_name' => $customer['last_name'] ?? '-',
'email' => $customer['email'] ?? '-',
'ip' => $customer_ip,
];
if (setting('display_terms_and_conditions'))
{
$consent['type'] = 'terms-and-conditions';
$this->consents_model->save($consent);
}
if (setting('display_privacy_policy'))
{
$consent['type'] = 'privacy-policy';
$this->consents_model->save($consent);
}
// Save customer language (the language which is used to render the booking page).
$customer['language'] = session('language') ?? config('language');
@ -495,6 +520,7 @@ class Booking extends EA_Controller {
$customer = $this->customers_model->find($customer_id);
$appointment['id_users_customer'] = $customer_id;
$appointment['is_unavailability'] = FALSE;
$this->appointments_model->only($appointment, [
'start_datetime',

View file

@ -32,7 +32,7 @@ class Consents extends EA_Controller {
/**
* Save (insert or update) the consent
*/
public function save_consent()
public function save()
{
try
{
@ -40,6 +40,28 @@ class Consents extends EA_Controller {
$consent['ip'] = $this->input->ip_address();
$occurrences = $this->consents_model->get(['ip' => $consent['ip']], 1, 0, 'create_datetime DESC');
if ( ! empty($occurrences))
{
$last_consent = $occurrences[0];
$last_consent_create_datetime_instance = new DateTime($last_consent['create_datetime']);
$threshold_datetime_instance = new DateTime('-24 hours');
if ($last_consent_create_datetime_instance > $threshold_datetime_instance)
{
// Do not create a new consent.
json_response([
'success' => TRUE,
]);
return;
}
}
$consent['id'] = $this->consents_model->save($consent);
json_response([

View file

@ -302,22 +302,6 @@ App.Http.Booking = (function () {
processingUnavailabilities = false;
}
/**
* Save the user's consent.
*
* @param {Object} consent Contains user's consents.
*/
function saveConsent(consent) {
const url = App.Utils.Url.siteUrl('consents/save_consent');
const data = {
csrf_token: vars('csrf_token'),
consent: consent
};
$.post(url, data);
}
/**
* Delete personal information.
*
@ -341,7 +325,6 @@ App.Http.Booking = (function () {
getAvailableHours,
getUnavailabilityDates,
applyPreviousUnavailabilityDates,
saveConsent,
deletePersonalInformation
};
})();

View file

@ -35,20 +35,6 @@ App.Pages.Booking = (function () {
const $bookAppointmentSubmit = $('#book-appointment-submit');
const $deletePersonalInformation = $('#delete-personal-information');
/**
* Contains terms and conditions consent.
*
* @type {Object}
*/
let termsAndConditionsConsent;
/**
* Contains privacy policy consent.
*
* @type {Object}
*/
let privacyPolicyConsent;
/**
* Determines the functionality of the page.
*
@ -365,38 +351,6 @@ App.Pages.Booking = (function () {
return; // Validation failed, do not continue.
} else {
updateConfirmFrame();
const $acceptToTermsAndConditions = $('#accept-to-terms-and-conditions');
if ($acceptToTermsAndConditions.length && $acceptToTermsAndConditions.prop('checked') === true) {
const newTermsAndConditionsConsent = {
first_name: $firstName.val(),
last_name: $lastName.val(),
email: $email.val(),
type: 'terms-and-conditions'
};
if (
JSON.stringify(newTermsAndConditionsConsent) !== JSON.stringify(termsAndConditionsConsent)
) {
termsAndConditionsConsent = newTermsAndConditionsConsent;
App.Http.Booking.saveConsent(termsAndConditionsConsent);
}
}
const $acceptToPrivacyPolicy = $('#accept-to-privacy-policy');
if ($acceptToPrivacyPolicy.length && $acceptToPrivacyPolicy.prop('checked') === true) {
const newPrivacyPolicyConsent = {
first_name: $firstName.val(),
last_name: $lastName.val(),
email: $email.val(),
type: 'privacy-policy'
};
if (JSON.stringify(newPrivacyPolicyConsent) !== JSON.stringify(privacyPolicyConsent)) {
privacyPolicyConsent = newPrivacyPolicyConsent;
App.Http.Booking.saveConsent(privacyPolicyConsent);
}
}
}
}