Fixed: Ensure all required parameters are passed before processing request

Co-authored-by: Name <sumit201@webkul.in>
This commit is contained in:
azhar bhat
2026-06-26 17:57:08 +05:30
parent a000f7e711
commit f4b8705a89
4 changed files with 15 additions and 3 deletions

View File

@@ -61,6 +61,12 @@ class QloHotelReviewDefaultModuleFrontController extends ModuleFrontController
$errors['general'][] = $objModule->l('Invalid order ID.', 'default');
}
$submittedSecureKey = Tools::getValue('order_secure_key', '');
if (!Validate::isLoadedObject($objOrder) || !$submittedSecureKey || $submittedSecureKey !== $objOrder->secure_key ) {
$errors['general'][] = $objModule->l('You are not authorized to submit a review.', 'default');
$this->ajaxDie(json_encode(array('status' => false, 'errors' => $errors)));
}
if (!$subject) {
$errors['by_key']['subject'] = $objModule->l('This field can not be empty.', 'default');
} elseif(!Validate::isGenericName($subject)) {

View File

@@ -198,10 +198,12 @@ class QloHotelReview extends Module
&& !QhrHotelReview::getByIdOrder($idOrder)
) {
if ($hotel = QhrHotelReviewHelper::getHotelByOrder($idOrder)) {
$objOrder = new Order((int) $idOrder);
$this->smarty->assign(array(
'id_order' => (int) $idOrder,
'id_hotel' => $hotel['id_hotel'],
'hotel_name' => $hotel['hotel_name'],
'order_secure_key' => $objOrder->secure_key,
));
return $this->display(__FILE__, 'booking-action.tpl');
}

View File

@@ -21,10 +21,12 @@
*/
var QhrReviewForm = {
init: function(idOrder, idHotel, hotelName) {
orderSecureKey: '',
init: function(idOrder, idHotel, hotelName, secureKey) {
$('#add-review-form').find('[name="id_order"]').val(idOrder);
$('#add-review-form').find('[name="id_hotel"]').val(idHotel);
$('#add-review-popup').find('.hotel-name').html(hotelName);
QhrReviewForm.orderSecureKey = secureKey || '';
QhrReviewImages.init();
},
show: function() {
@@ -47,6 +49,7 @@ var QhrReviewForm = {
formData.append('ajax', true);
formData.append('token', qlo_hotel_review_js_vars.review_ajax_token);
formData.append('action', 'AddReview');
formData.append('order_secure_key', QhrReviewForm.orderSecureKey);
$.ajax({
url: qlo_hotel_review_js_vars.review_ajax_link,
data: formData,
@@ -202,7 +205,8 @@ $(document).on('click', '#add-review-btn', function(e) {
var idOrder = parseInt($(this).data('id-order'));
var idHotel = parseInt($(this).data('id-hotel'));
var hotelName = $(this).data('hotel-name');
QhrReviewForm.init(idOrder, idHotel, hotelName);
var secureKey = $(this).data('secure-key') || '';
QhrReviewForm.init(idOrder, idHotel, hotelName, secureKey);
QhrReviewForm.show();
});

View File

@@ -20,6 +20,6 @@
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*}
<a class="btn btn-default btn-review pull-right" id="add-review-btn" data-id-order="{$id_order}" data-id-hotel="{$id_hotel}" data-hotel-name="{$hotel_name}">
<a class="btn btn-default btn-review pull-right" id="add-review-btn" data-id-order="{$id_order}" data-id-hotel="{$id_hotel}" data-hotel-name="{$hotel_name}" data-secure-key="{$order_secure_key}">
{l s='Write a Review' mod='qlohotelreview'}
</a>