Integrated CAPTCHA setting within the booking wizard.

This commit is contained in:
Alex Tselegidis 2015-12-30 12:54:33 +01:00
parent c16a06a273
commit 655f068a8d
3 changed files with 25 additions and 16 deletions

View file

@ -319,8 +319,15 @@ class Appointments extends CI_Controller {
try { try {
$post_data = $_POST['post_data']; // alias $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. // 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')); throw new Exception($this->lang->line('captcha_is_wrong'));
} }
@ -332,12 +339,6 @@ class Appointments extends CI_Controller {
$appointment = $_POST['post_data']['appointment']; $appointment = $_POST['post_data']['appointment'];
$customer = $_POST['post_data']['customer']; $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)) { if ($this->customers_model->exists($customer)) {
$customer['id'] = $this->customers_model->find_record_id($customer); $customer['id'] = $this->customers_model->find_record_id($customer);
} }

View file

@ -364,16 +364,18 @@
<div id="appointment-details" class="col-md-6"></div> <div id="appointment-details" class="col-md-6"></div>
<div id="customer-details" class="col-md-6"></div> <div id="customer-details" class="col-md-6"></div>
</div> </div>
<?php if ($this->settings_model->get_setting('require_captcha') === '1'): ?>
<div class="frame-content row"> <div class="frame-content row">
<div class="col-md-6 col-sm-12"> <div class="col-md-6 col-sm-12">
<h4 class="captcha-title"> <h4 class="captcha-title">
Captcha CAPTCHA
<small class="glyphicon glyphicon-refresh"></small> <small class="glyphicon glyphicon-refresh"></small>
</h4> </h4>
<img class="captcha-image" src="<?php echo $this->config->item('base_url'); ?>/index.php/captcha"> <img class="captcha-image" src="<?php echo $this->config->item('base_url'); ?>/index.php/captcha">
<input class="captcha-text" type="text" value="" /> <input class="captcha-text" type="text" value="" />
</div> </div>
</div> </div>
<?php endif; ?>
</div> </div>
<div class="command-buttons"> <div class="command-buttons">

View file

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