From 655f068a8d08159414dfd7bdf39aae61ead5c55a Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Wed, 30 Dec 2015 12:54:33 +0100 Subject: [PATCH] Integrated CAPTCHA setting within the booking wizard. --- src/application/controllers/appointments.php | 17 +++++++++-------- src/application/views/appointments/book.php | 4 +++- src/assets/js/frontend_book.js | 20 +++++++++++++------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php index 5d1a765a..c5b3f805 100755 --- a/src/application/controllers/appointments.php +++ b/src/application/controllers/appointments.php @@ -319,8 +319,15 @@ class Appointments extends CI_Controller { try { $post_data = $_POST['post_data']; // alias + $this->load->model('appointments_model'); + $this->load->model('providers_model'); + $this->load->model('services_model'); + $this->load->model('customers_model'); + $this->load->model('settings_model'); + // Validate the CAPTCHA string. - if ($this->session->userdata('captcha_phrase') !== $_POST['captcha']) { + if ($this->settings_model->get_setting('require_captcha') === '1' + && $this->session->userdata('captcha_phrase') !== $_POST['captcha']) { throw new Exception($this->lang->line('captcha_is_wrong')); } @@ -332,12 +339,6 @@ class Appointments extends CI_Controller { $appointment = $_POST['post_data']['appointment']; $customer = $_POST['post_data']['customer']; - $this->load->model('appointments_model'); - $this->load->model('providers_model'); - $this->load->model('services_model'); - $this->load->model('customers_model'); - $this->load->model('settings_model'); - if ($this->customers_model->exists($customer)) { $customer['id'] = $this->customers_model->find_record_id($customer); } @@ -703,7 +704,7 @@ class Appointments extends CI_Controller { private function calculate_available_hours(array $empty_periods, $selected_date, $service_duration, $manage_mode = FALSE) { $this->load->model('settings_model'); - + $available_hours = array(); foreach ($empty_periods as $period) { diff --git a/src/application/views/appointments/book.php b/src/application/views/appointments/book.php index 827acfcf..c85902ca 100644 --- a/src/application/views/appointments/book.php +++ b/src/application/views/appointments/book.php @@ -364,16 +364,18 @@
+ settings_model->get_setting('require_captcha') === '1'): ?>

- Captcha + CAPTCHA

+
diff --git a/src/assets/js/frontend_book.js b/src/assets/js/frontend_book.js index 84fa02d3..b02abf20 100644 --- a/src/assets/js/frontend_book.js +++ b/src/assets/js/frontend_book.js @@ -615,21 +615,27 @@ var FrontendBook = { * the appointment to the database. */ registerAppointment: function() { - if ($('.captcha-text').val() === '') { - $('.captcha-text').css('border', '1px solid red'); - return; - } else { - $('.captcha-text').css('border', ''); + var $captchaText = $('.captcha-text'); + + if ($captchaText.length > 0) { + $captchaText.css('border', ''); + if ($captchaText.val() === '') { + $captchaText.css('border', '1px solid red'); + return; + } } var formData = jQuery.parseJSON($('input[name="post_data"]').val()); var postData = { 'csrfToken': GlobalVariables.csrfToken, - 'post_data': formData, - 'captcha': $('.captcha-text').val() + 'post_data': formData }; + if ($captchaText.length > 0) { + postData.captcha = $captchaText.val(); + } + if (GlobalVariables.manageMode) { postData.exclude_appointment_id = GlobalVariables.appointmentData.id; }