diff --git a/src/apis/auth.php b/src/apis/auth.php index 581c326..1e206e5 100755 --- a/src/apis/auth.php +++ b/src/apis/auth.php @@ -4,26 +4,29 @@ $GLOBALS['conn']; $conn=@mysqli_connect($DATAhst,$DATAusr,$DATApwd,$DATAdtb)or die("CONNECTION ERROR"); $content = null; -$content->status = 404; +$content->status = array(); +$data = json_decode(file_get_contents("php://input")); -if(isset($_POST['act']) && $_POST['act'] == 'auth') { - if($_POST['usr'] == 'admin' && $_POST['pwd'] == 'JohnHolmes') { +if(isset($_GET['act']) && $_GET['act'] == 'login') { + if($data->usr == 'admin' && $data->pwd == 'JohnHolmes') { $content->status = 200; - $content->authToken = md5(date("Y-m-d")); + $content->authToken = base64_encode(date("Y-m-d")); } else { $content->status = 403; } -} else if(isset($_POST['act']) && $_POST['act'] == 'check') { - if($_POST['token'] == md5(date("Y-m-d"))) { +} else if(isset($_GET['act']) && $_GET['act'] == 'check') { + if($data->token == base64_encode(date("Y-m-d"))) { $content->status = 200; - $content->authToken = md5(date("Y-m-d")); + $content->authToken = base64_encode(date("Y-m-d")); } else { $content->status = 403; } } +header("Access-Control-Allow-Origin: *"); +header("Content-Type: application/json; charset=UTF-8"); +header("Access-Control-Allow-Methods: POST"); +header("Access-Control-Max-Age: 3600"); -header('Access-Control-Allow-Origin: *'); -header('Content-Type: application/json'); echo json_encode($content); ?> diff --git a/src/apis/index.php b/src/apis/index.php index 830ff2e..e8e2b18 100644 --- a/src/apis/index.php +++ b/src/apis/index.php @@ -4,92 +4,114 @@ $GLOBALS['conn']; $conn=@mysqli_connect($DATAhst,$DATAusr,$DATApwd,$DATAdtb)or die("CONNECTION ERROR"); $content = null; -$content->items = array(); -$filter = array("portfolio", "installations", "entertainment", "performances", "workshops"); +if(isset($_GET['query'])) { -switch($_GET['query']) { - case "portfolio": - case "installations": - case "entertainment": - case "performances": - case "workshops": - if($_GET['query'] == 'portfolio') {$filter = '';} else {$filter = "WHERE type='".$_GET['query']."'";} - $qe = mysqli_query($conn,"SELECT * FROM `works` $filter ORDER BY id DESC"); - if(mysqli_num_rows($qe) > 0) { - $content = null; - $content->items = array(); - while($re = mysqli_fetch_array($qe)) { - $item = null; - $item->id = $re['id']; - $item->title = $re['title']; - $item->type = $re['type']; - $item->tags = $re['tags']; - $item->image = $re['image']; - array_push($content->items, $item); + $content->items = array(); + switch($_GET['query']) { + case "portfolio": + case "installations": + case "entertainment": + case "performances": + case "workshops": + if($_GET['query'] == 'portfolio') {$filter = '';} else {$filter = "WHERE type='".$_GET['query']."'";} + $qe = mysqli_query($conn,"SELECT * FROM `works` $filter ORDER BY id DESC"); + if(mysqli_num_rows($qe) > 0) { + $content = null; + $content->items = array(); + while($re = mysqli_fetch_array($qe)) { + $item = null; + $item->id = $re['id']; + $item->title = $re['title']; + $item->type = $re['type']; + $item->tags = $re['tags']; + $item->image = $re['image']; + array_push($content->items, $item); + } + } + break; + case "exhibitions": + $qe = mysqli_query($conn,"SELECT * FROM `exhibitions` ORDER BY date_from DESC"); + if(mysqli_num_rows($qe) > 0) { + $content = null; + $content->items = array(); + while($re = mysqli_fetch_array($qe)) { + $item = null; + $item->id = $re['id']; + $item->title = $re['title']; + $item->date_from = $re['date_from']; + $item->date_to = $re['date_to']; + $item->tags = $re['tags']; + $item->image = $re['image']; + array_push($content->items, $item); + } } - } - break; - case "exhibitions": - $qe = mysqli_query($conn,"SELECT * FROM `exhibitions` ORDER BY date_from DESC"); - if(mysqli_num_rows($qe) > 0) { - $content = null; - $content->items = array(); - while($re = mysqli_fetch_array($qe)) { + break; + case "detail": + $qe = mysqli_query($conn,"SELECT * FROM `".$_GET['type']."` WHERE id=".$_GET['id']); + if(mysqli_num_rows($qe)>0) { + $content = null; + $re = mysqli_fetch_array($qe); $item = null; $item->id = $re['id']; $item->title = $re['title']; - $item->date_from = $re['date_from']; - $item->date_to = $re['date_to']; + $item->content = $re['content']; $item->tags = $re['tags']; $item->image = $re['image']; - array_push($content->items, $item); - } - } - break; - case "detail": - $qe = mysqli_query($conn,"SELECT * FROM `".$_GET['type']."` WHERE id=".$_GET['id']); - if(mysqli_num_rows($qe)>0) { - $content = null; - $re = mysqli_fetch_array($qe); - $item = null; - $item->id = $re['id']; - $item->title = $re['title']; - $item->content = $re['content']; - $item->tags = $re['tags']; - $item->image = $re['image']; - if($_GET['type'] == 'exhibitions') { - $item->date_from = $re['date_from']; - $item->date_to = $re['date_to']; - $item->works = array(); - $qx = mysqli_query($conn,"SELECT id,title FROM `works` WHERE id IN (".$re['works'].")"); - while($re = mysqli_fetch_array($qx)) { - $ex = null; - $ex->id = $re['id']; - $ex->title = $re['title']; - array_push($item->works, $ex); - } - } else if($_GET['type'] == 'works') { - $item->type = $re['type']; - $item->videos = $re['videos']; - $item->gallery = $re['gallery']; - $item->exhibitions = array(); - $qx = mysqli_query($conn,"SELECT id,title FROM `exhibitions` WHERE id IN (".$re['exhibitions'].")"); - while($re = mysqli_fetch_array($qx)) { - $ex = null; - $ex->id = $re['id']; - $ex->title = $re['title']; - array_push($item->exhibitions, $ex); + if($_GET['type'] == 'exhibitions') { + $item->date_from = $re['date_from']; + $item->date_to = $re['date_to']; + $item->works = array(); + $qx = mysqli_query($conn,"SELECT id,title FROM `works` WHERE id IN (".$re['works'].")"); + while($re = mysqli_fetch_array($qx)) { + $ex = null; + $ex->id = $re['id']; + $ex->title = $re['title']; + array_push($item->works, $ex); + } + } else if($_GET['type'] == 'works') { + $item->type = $re['type']; + $item->videos = $re['videos']; + $item->gallery = $re['gallery']; + $item->exhibitions = array(); + $qx = mysqli_query($conn,"SELECT id,title FROM `exhibitions` WHERE id IN (".$re['exhibitions'].")"); + while($re = mysqli_fetch_array($qx)) { + $ex = null; + $ex->id = $re['id']; + $ex->title = $re['title']; + array_push($item->exhibitions, $ex); + } } + $content->item = $item; } - $content->item = $item; - } - break; -} + break; + } +} else if(isset($_GET['auth'])) { + switch($_GET['auth']) { + case 'auth': + if($_POST['usr'] == 'admin' && $_POST['pwd'] == 'JohnHolmes') { + $content->status = 200; + $content->authToken = md5(date("Y-m-d")); + } else { + $content->status = 403; + } + break; + case 'check': + if($_POST['token'] == md5(date("Y-m-d"))) { + $content->status = 200; + $content->authToken = md5(date("Y-m-d")); + } else { + $content->status = 403; + } + break; + } +} -header('Access-Control-Allow-Origin: *'); -header('Content-Type: application/json'); +header("Access-Control-Allow-Origin: *"); +header("Content-Type: application/json; charset=UTF-8"); +header("Access-Control-Allow-Methods: GET"); +header("Access-Control-Max-Age: 3600"); echo json_encode($content); ?> diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 717bddf..618f8eb 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -1,19 +1,19 @@