Skip to content

Commit

Permalink
Checking token on adding and deleting favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
myvesta committed Aug 29, 2021
1 parent 5262b3f commit 475fe47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 3 additions & 4 deletions web/add/favorite/index.php
Expand Up @@ -7,10 +7,9 @@
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");

// Check token
// if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
// header('location: /login/');
// exit();
// }
if ((!isset($_REQUEST['token'])) || ($_SESSION['token'] != $_REQUEST['token'])) {
die("Wrong token");
}

// Protect input
$v_section = escapeshellarg($_REQUEST['v_section']);
Expand Down
5 changes: 5 additions & 0 deletions web/delete/favorite/index.php
Expand Up @@ -5,6 +5,11 @@

include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");

// Check token
if ((!isset($_REQUEST['token'])) || ($_SESSION['token'] != $_REQUEST['token'])) {
die("Wrong token");
}

unset($_SESSION['favourites'][strtoupper($_REQUEST['v_section'])][$_REQUEST['v_unit_id']]);

$v_section = escapeshellarg($_REQUEST['v_section']);
Expand Down
5 changes: 3 additions & 2 deletions web/js/init.js
Expand Up @@ -128,14 +128,15 @@ $(document).ready(function(){

$('.l-unit .l-icon-star').click(function(){
var l_unit = $(this).parents('.l-unit');
var token = $('#token').attr('token');

if(l_unit.hasClass('l-unit--starred')){
// removing star

$.ajax({
method: "POST",
url: "/delete/favorite/index.php",
data: { v_section: l_unit.attr('v_section'), v_unit_id: l_unit.attr('v_unit_id') }
data: { v_section: l_unit.attr('v_section'), v_unit_id: l_unit.attr('v_unit_id'), token: token }
});

l_unit.attr({'sort-star': 0});
Expand All @@ -145,7 +146,7 @@ $(document).ready(function(){
$.ajax({
method: "POST",
url: "/add/favorite/index.php",
data: { v_unit_id: l_unit.attr('v_unit_id'), v_section: l_unit.attr('v_section') }
data: { v_unit_id: l_unit.attr('v_unit_id'), v_section: l_unit.attr('v_section'), token: token }
});

l_unit.attr({'sort-star': 1});
Expand Down

0 comments on commit 475fe47

Please sign in to comment.