Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk

INSTALL.php
config.php
4 changes: 2 additions & 2 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Options All -Indexes
DirectoryIndex api.php
Options ALL -Indexes
DirectoryIndex api.php
25 changes: 20 additions & 5 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ function hash_equals($a, $b) {
}
}

$itemName = $_POST['item'];
$itemCount = $_POST['count'];
$jsonData = $_POST['jsonArray'];
$function = $_POST['function'];
if(isset($_POST['item']))
$itemName = $_POST['item'];

if(isset($_POST['count']))
$itemCount = $_POST['count'];

if(isset($_POST['jsonArray']))
$jsonData = $_POST['jsonArray'];

if(!isset($_POST['function']))
die("No function");

if(!isset($_POST['auth']))
die("No auth");

$auth = $_POST['auth'];
$function = $_POST['function'];

include('config.php');

Expand Down Expand Up @@ -44,10 +56,13 @@ function hash_equals($a, $b) {


include $dbConnector;

/* WHAT?
if (!hash_equals($authKey, crypt($auth, $authKey))){
die (json_encode(array('type' => API_ERROR_403, 'content' => 'Authentication failed.')));
}
*/
if($auth!==$authKey)
die (json_encode(array('type' => API_ERROR_403, 'content' => 'Authentication failed.')));

$db = NEW DataBase($dbConfig);

Expand Down
28 changes: 0 additions & 28 deletions config.php

This file was deleted.

25 changes: 13 additions & 12 deletions mysql_connector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include('CONSTANTS.php');
include_once('CONSTANTS.php');
class DataBase
{
var $server, $username, $password, $database;
Expand Down Expand Up @@ -78,26 +78,27 @@ function saveMultiple($jsonData)
return $result;
}

function deleteMultiple($jsonData)
{
if(empty($jsonData)) {
die(json_encode(array('type' => API_ERROR_MISSING_PARAMETER, 'content' => 'parameter missing for deleteMultiple')));
}
function deleteMultiple($jsonData) {
if(empty($jsonData))
die(json_encode(array('type' => API_ERROR_MISSING_PARAMETER, 'content' => 'parameter missing for deleteMultiple')));
//iterate over all items in json array
$array = json_decode( $jsonData, true );
if(count($array) ==0)
die(json_encode(array('type' => API_ERROR_MISSING_PARAMETER, 'content' => 'parameter missing for deleteMultiple')));

//connect to db
$handler = new mysqli($this->server, $this->username, $this->password, $this->database);

//check if connection successful
if ($handler->connect_error) {
die(json_encode(array('type' => API_ERROR_DATABASE_CONNECT, 'content' => $handler->connect_error)));
}
//iterate over all items in json array
$array = json_decode( $jsonData, true );

//prepare query
$stmt = $handler->prepare("DELETE from ShoppingList WHERE item = ?");
$stmt->bind_param('s', $item['itemTitle']);
foreach($array as $item)
{
//prepare query
$stmt = $handler->prepare("DELETE from ShoppingList WHERE item = ?");
$stmt->bind_param('s', $item['itemTitle']);

//execute query and check if successful
if (!$stmt->execute()){
$result = json_encode(array('type' => API_SUCCESS_DELETE, 'content' => ' Multiple items deleted'));
Expand Down