mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-23 22:30:41 +01:00
Merge branch 'add-api-url' into 'develop'
Add api url See merge request bluekay/shopping-list!6
This commit is contained in:
commit
4124c4b8a7
19 changed files with 83 additions and 72 deletions
37
.htaccess
37
.htaccess
|
@ -15,6 +15,41 @@
|
||||||
RewriteRule ^edit-recipe/([0-9]+)$ ?site=edit-recipe&number=$1
|
RewriteRule ^edit-recipe/([0-9]+)$ ?site=edit-recipe&number=$1
|
||||||
|
|
||||||
#Loginseite
|
#Loginseite
|
||||||
RewriteRule ^login/url=(.+)$ ?site=login&refurl=$1 [L]
|
RewriteRule ^login/url=(.+)$ ?site=login&refurl=$1
|
||||||
|
|
||||||
|
#API Calls
|
||||||
|
RewriteRule ^api/([\w-]+)/([\w-]+)$ php/api.php?site=api&call=$1&function=$2 [L]
|
||||||
</IfModule>
|
</IfModule>
|
||||||
|
|
||||||
|
#Deny every *.php file
|
||||||
|
<Files *.php>
|
||||||
|
Order Deny,Allow
|
||||||
|
Deny from all
|
||||||
|
Allow from 127.0.0.1
|
||||||
|
</Files>
|
||||||
|
|
||||||
|
#allow following files
|
||||||
|
<Files index.php>
|
||||||
|
Order Allow,Deny
|
||||||
|
Allow from all
|
||||||
|
</Files>
|
||||||
|
|
||||||
|
<Files api.php>
|
||||||
|
Order Allow,Deny
|
||||||
|
Allow from all
|
||||||
|
</Files>
|
||||||
|
|
||||||
|
<Files login.php>
|
||||||
|
Order Allow,Deny
|
||||||
|
Allow from all
|
||||||
|
</Files>
|
||||||
|
|
||||||
|
<Files logout.php>
|
||||||
|
Order Allow,Deny
|
||||||
|
Allow from all
|
||||||
|
</Files>
|
||||||
|
|
||||||
|
<Files install*.php>
|
||||||
|
Order Allow,Deny
|
||||||
|
Allow from all
|
||||||
|
</Files>
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$("#button_newuser").click(function(){
|
$("#button_newuser").click(function(){
|
||||||
$.post("/php/edit-user.php",
|
$.post("/api/user/new",
|
||||||
{
|
{
|
||||||
function: "new-user",
|
|
||||||
username: $("#text_user").val(),
|
username: $("#text_user").val(),
|
||||||
passwd: $("#text_passwd").val()
|
passwd: $("#text_passwd").val()
|
||||||
},
|
},
|
||||||
function(data){
|
function(data){
|
||||||
if(data==0){
|
if(data=="0"){
|
||||||
infoPopUp("Benutzer erfolgreich erstellt!", 100);
|
infoPopUp("Benutzer erfolgreich erstellt!", 100);
|
||||||
$("#text_user").val("");
|
$("#text_user").val("");
|
||||||
$("#text_passwd").val("");
|
$("#text_passwd").val("");
|
||||||
|
|
|
@ -71,10 +71,8 @@ var values = [];
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/php/edit-recipes.php",
|
url: "/api/recipes/auto",
|
||||||
data: {
|
data: {},
|
||||||
function: "auto",
|
|
||||||
},
|
|
||||||
success: function(data){
|
success: function(data){
|
||||||
values = data.split("||");
|
values = data.split("||");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var recipeID = window.location.href.split("/")[(window.location.href.split("/").length-1)];
|
var recipeID = window.location.href.split("/")[(window.location.href.split("/").length-1)];
|
||||||
$("#FormSubmitfunction").prop("value", "update");
|
$("#newRecipeForm").prop("action", "/api/recipes/update");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/php/edit-recipes.php",
|
url: "/api/recipes/edit",
|
||||||
data: {
|
data: {
|
||||||
function: "edit",
|
|
||||||
id: recipeID
|
id: recipeID
|
||||||
},
|
},
|
||||||
success: function(data){
|
success: function(data){
|
||||||
var recipe = JSON.parse(data);
|
var recipe = JSON.parse(data);
|
||||||
$("#FormSubmitfunction").after("<input type='hidden' name='id' value='"+recipe.ID+"'>");
|
$("#safeRecipe").before("<input type='hidden' name='id' value='"+recipe.ID+"'>");
|
||||||
$("#RecipeFormName").val(recipe.Name);
|
$("#RecipeFormName").val(recipe.Name);
|
||||||
$("#recipeDurationInput").val(recipe.Dauer);
|
$("#recipeDurationInput").val(recipe.Dauer);
|
||||||
$("#recipeDescription").val(recipe.Beschreibung);
|
$("#recipeDescription").val(recipe.Beschreibung);
|
||||||
|
|
|
@ -3,9 +3,8 @@ $(document).ready(function(){
|
||||||
var dataId = $(this).parent().data("id");
|
var dataId = $(this).parent().data("id");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "php/edit-list.php",
|
url: "api/list/check",
|
||||||
data: {
|
data: {
|
||||||
function: "check",
|
|
||||||
id: dataId,
|
id: dataId,
|
||||||
status: $(this).prop("checked")
|
status: $(this).prop("checked")
|
||||||
},
|
},
|
||||||
|
@ -18,10 +17,7 @@ $(document).ready(function(){
|
||||||
$("#remove").click(function(){
|
$("#remove").click(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "php/edit-list.php",
|
url: "api/list/del",
|
||||||
data: {
|
|
||||||
function: "del"
|
|
||||||
},
|
|
||||||
success: function(){
|
success: function(){
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,8 @@ $(document).ready(function(){
|
||||||
if(!(confirm("Wirklich löschen?"))){return;}
|
if(!(confirm("Wirklich löschen?"))){return;}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/php/edit-recipes.php",
|
url: "/api/recipes/del",
|
||||||
data: {
|
data: {
|
||||||
function: "del",
|
|
||||||
id: $("#recipeHeader").data("recipeid")
|
id: $("#recipeHeader").data("recipeid")
|
||||||
},
|
},
|
||||||
success: function(data){
|
success: function(data){
|
||||||
|
|
|
@ -14,9 +14,8 @@ $(document).ready(function(){
|
||||||
if(!(confirm("Wirklich löschen?"))){return;}
|
if(!(confirm("Wirklich löschen?"))){return;}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/php/edit-recipes.php",
|
url: "/api/recipes/del",
|
||||||
data: {
|
data: {
|
||||||
function: "del",
|
|
||||||
id: $("#recipeHeader").data("recipeid")
|
id: $("#recipeHeader").data("recipeid")
|
||||||
},
|
},
|
||||||
success: function(data){
|
success: function(data){
|
||||||
|
@ -45,10 +44,9 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/php/edit-list.php",
|
url: "/api/list/multiple",
|
||||||
data: {
|
data: {
|
||||||
list: list,
|
list: list
|
||||||
function: "multiple"
|
|
||||||
},
|
},
|
||||||
success: function(data){
|
success: function(data){
|
||||||
window.location = "/";
|
window.location = "/";
|
||||||
|
|
|
@ -31,9 +31,8 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#passwordSaveButton").click(function(){
|
$("#passwordSaveButton").click(function(){
|
||||||
$.post("/php/edit-user.php",
|
$.post("/api/user/change-pw",
|
||||||
{
|
{
|
||||||
function: "change-pw",
|
|
||||||
current: $("#old-password-input").val(),
|
current: $("#old-password-input").val(),
|
||||||
new: $("#new-password-input").val()
|
new: $("#new-password-input").val()
|
||||||
},
|
},
|
||||||
|
@ -52,13 +51,13 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#export-recipe-button").click(function(){
|
$("#export-recipe-button").click(function(){
|
||||||
$.post("/php/edit-recipes.php", {function:"export"}, function(data){
|
$.post("/api/recipes/export", {}, function(data){
|
||||||
downloadObjectAsJson(JSON.parse(data), "recipes");
|
downloadObjectAsJson(JSON.parse(data), "recipes");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#export-list-button").click(function(){
|
$("#export-list-button").click(function(){
|
||||||
$.post("/php/edit-list.php", {function:"export"}, function(data){
|
$.post("/api/list/export", {}, function(data){
|
||||||
downloadObjectAsJson(JSON.parse(data), "list");
|
downloadObjectAsJson(JSON.parse(data), "list");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -70,9 +69,8 @@ $(document).ready(function(){
|
||||||
reader.onload = function(){
|
reader.onload = function(){
|
||||||
var content = JSON.parse(reader.result);
|
var content = JSON.parse(reader.result);
|
||||||
if(content.sites!=null){
|
if(content.sites!=null){
|
||||||
$.post("/php/edit-recipes.php",
|
$.post("/api/recipes/import",
|
||||||
{
|
{
|
||||||
function: "import",
|
|
||||||
content: reader.result
|
content: reader.result
|
||||||
},
|
},
|
||||||
function(data){
|
function(data){
|
||||||
|
@ -87,9 +85,8 @@ $(document).ready(function(){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if(content.list!=null){
|
else if(content.list!=null){
|
||||||
$.post("/php/edit-list.php",
|
$.post("/api/list/import",
|
||||||
{
|
{
|
||||||
function: "import",
|
|
||||||
content: reader.result
|
content: reader.result
|
||||||
},
|
},
|
||||||
function(data){
|
function(data){
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
# prevent access to these files while not logged in
|
|
||||||
<files "*.php">
|
|
||||||
Require all denied
|
|
||||||
</files>
|
|
|
@ -1,4 +0,0 @@
|
||||||
# prevent access to these files while not logged in
|
|
||||||
<files "*.php">
|
|
||||||
Require all denied
|
|
||||||
</files>
|
|
|
@ -2,7 +2,7 @@
|
||||||
<link rel="stylesheet" href="/style/list.css">
|
<link rel="stylesheet" href="/style/list.css">
|
||||||
<h1>Liste</h1>
|
<h1>Liste</h1>
|
||||||
<button type="button" id="remove" class="button">Auswahl entfernen</button>
|
<button type="button" id="remove" class="button">Auswahl entfernen</button>
|
||||||
<form id="neu" action="php/edit-list.php" method="post">
|
<form id="neu" action="api/list/new" method="post">
|
||||||
<input type="hidden" name="function" value="new">
|
<input type="hidden" name="function" value="new">
|
||||||
<div id="list">
|
<div id="list">
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
else{
|
else{
|
||||||
echo "<h1 id=\"header\">Neu</h1>";
|
echo "<h1 id=\"header\">Neu</h1>";
|
||||||
} ?>
|
} ?>
|
||||||
<form id="newRecipeForm" autocomplete="off" action="/php/edit-recipes.php" method="post">
|
<form id="newRecipeForm" autocomplete="off" action="/api/recipes/new" method="post">
|
||||||
<input id="FormSubmitfunction" type="hidden" name="function" value="new">
|
|
||||||
<div><input id="safeRecipe" type="submit" name="" value="Speichern" class="button"> </div>
|
<div><input id="safeRecipe" type="submit" name="" value="Speichern" class="button"> </div>
|
||||||
<div><font>Name:</font><br /><input id="RecipeFormName" type="text" name="recipeName" placeholder="Name" required="required"></div>
|
<div><font>Name:</font><br /><input id="RecipeFormName" type="text" name="recipeName" placeholder="Name" required="required"></div>
|
||||||
<div><font>Dauer (Minuten):</font><br /><input type="number" name="recipeDuration" id="recipeDurationInput" value="30"></div>
|
<div><font>Dauer (Minuten):</font><br /><input type="number" name="recipeDuration" id="recipeDurationInput" value="30"></div>
|
||||||
|
|
|
@ -209,5 +209,5 @@ foreach($SQLStatements as $statement){
|
||||||
$result = $connection->query($statement);
|
$result = $connection->query($statement);
|
||||||
}
|
}
|
||||||
$connection->close();
|
$connection->close();
|
||||||
header ("Location: adduser.php");
|
header ("Location: install_adduser.php");
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -13,6 +13,4 @@
|
||||||
<input id="button_newuser" class="button" type="submit" name="" value="Neuer Benutzer">
|
<input id="button_newuser" class="button" type="submit" name="" value="Neuer Benutzer">
|
||||||
</div>
|
</div>
|
||||||
<button class="button button-disabled" id="adduser-button-done">Fertig</button>
|
<button class="button button-disabled" id="adduser-button-done">Fertig</button>
|
||||||
|
|
||||||
<!-- Only here in install/adduser -->
|
|
||||||
<div id="info-popup"><font id="info-popup-text"></font></div>
|
<div id="info-popup"><font id="info-popup-text"></font></div>
|
|
@ -1,16 +0,0 @@
|
||||||
# prevent access to these files while not logged in
|
|
||||||
<files "classes.*.php">
|
|
||||||
Require all denied
|
|
||||||
</files>
|
|
||||||
|
|
||||||
<files "auth.php">
|
|
||||||
Require all denied
|
|
||||||
</files>
|
|
||||||
|
|
||||||
<files "connect.php">
|
|
||||||
Require all denied
|
|
||||||
</files>
|
|
||||||
|
|
||||||
<files "hash.php">
|
|
||||||
Require all denied
|
|
||||||
</files>
|
|
20
php/api.php
Normal file
20
php/api.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
switch($_GET["call"]) {
|
||||||
|
case 'list':
|
||||||
|
include $_SESSION["docroot"].'/php/edit-list.php';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'recipes':
|
||||||
|
include $_SESSION["docroot"].'/php/edit-recipes.php';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'user':
|
||||||
|
include $_SESSION["docroot"].'/php/edit-user.php';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
echo "API call not defined";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
?>
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
session_start();
|
|
||||||
include $_SESSION["docroot"].'/php/classes.list.php';
|
include $_SESSION["docroot"].'/php/classes.list.php';
|
||||||
$shopping = new shopping;
|
$shopping = new shopping;
|
||||||
|
|
||||||
switch ($_POST["function"]) {
|
switch ($_GET["function"]) {
|
||||||
case 'new':
|
case 'new':
|
||||||
$shopping->newItem($_POST["anzahl"], $_POST["einheit"], $_POST["name"]);
|
$shopping->newItem($_POST["anzahl"], $_POST["einheit"], $_POST["name"]);
|
||||||
header("Location: /list");
|
header("Location: /list");
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
session_start();
|
|
||||||
include $_SESSION["docroot"].'/php/classes.recipe.php';
|
include $_SESSION["docroot"].'/php/classes.recipe.php';
|
||||||
$book = new cookbook;
|
$book = new cookbook;
|
||||||
|
|
||||||
switch ($_POST["function"]) {
|
switch ($_GET["function"]) {
|
||||||
case 'del':
|
case 'del':
|
||||||
$book->removeRecipe($_POST["id"]);
|
$book->removeRecipe($_POST["id"]);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
session_start();
|
|
||||||
include $_SESSION["docroot"].'/php/classes.user.php';
|
include $_SESSION["docroot"].'/php/classes.user.php';
|
||||||
$user = new user;
|
$user = new user;
|
||||||
if($_POST["function"]!="new-user"){
|
if($_GET["function"]!="new"){
|
||||||
$user->get_info($_COOKIE["token"]);
|
$user->get_info($_COOKIE["token"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($_POST["function"]) {
|
switch ($_GET["function"]) {
|
||||||
case 'change-pw':
|
case 'change-pw':
|
||||||
$user->change_password($_POST["current"], $_POST["new"]);
|
$user->change_password($_POST["current"], $_POST["new"]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'new-user':
|
case 'new':
|
||||||
$user->new($_POST["username"], $_POST["passwd"]);
|
$user->new($_POST["username"], $_POST["passwd"]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue