Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
92d9ddb8f7 | |||
bb626538c4 | |||
|
46dbcca254 | ||
|
34aa9e10f9 | ||
|
b84c4fd8e3 | ||
|
20a26ebd66 | ||
abc1be3885 | |||
9822a9f738 |
@ -13,7 +13,7 @@ Eine auflistung von allen Funktionen und API-Endpunkten mit Erklärung.
|
|||||||
|
|
||||||
### User erstellen
|
### User erstellen
|
||||||
```shell
|
```shell
|
||||||
POST 127.0.0.1/DirektiveDesDons/signup
|
POST 127.0.0.1/DirektiveDesDons/user
|
||||||
|
|
||||||
BODY
|
BODY
|
||||||
{
|
{
|
||||||
@ -119,7 +119,7 @@ DELETE 127.0.0.1/DirektiveDesDons/ingredient/1
|
|||||||
|
|
||||||
### Zutat ändern
|
### Zutat ändern
|
||||||
```shell
|
```shell
|
||||||
POST 127.0.0.1/DirektiveDesDons/ingredient/3
|
PUT 127.0.0.1/DirektiveDesDons/ingredient/3
|
||||||
|
|
||||||
BODY
|
BODY
|
||||||
{
|
{
|
||||||
@ -150,6 +150,21 @@ BODY
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Einheit ausgeben
|
||||||
|
```shell
|
||||||
|
GET 127.0.0.1/DirektiveDesDons/unit/4
|
||||||
|
```
|
||||||
|
|
||||||
|
###Einheit ändern
|
||||||
|
```shell
|
||||||
|
PUT 127.0.0.1/DirektiveDesDons/unit/4
|
||||||
|
|
||||||
|
BODY
|
||||||
|
{
|
||||||
|
"name":"Tonne"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Einheit löschen
|
### Einheit löschen
|
||||||
```shell
|
```shell
|
||||||
DELETE 127.0.0.1/DirektiveDesDons/unit/4
|
DELETE 127.0.0.1/DirektiveDesDons/unit/4
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 56 KiB |
12
User.php
12
User.php
@ -18,11 +18,13 @@ class User {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public function loginWithUsername(string $username, string $password) : string {
|
public function loginWithUsername(string $username, string $password) : string {
|
||||||
$userObject = $this->db->select("utente", ["nomeUtente" => $username])[0];
|
$query = $this->db->select("utente", ["nomeUtente" => $username]);
|
||||||
|
|
||||||
if(!$userObject){
|
if(!$query){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$userObject = $query[0];
|
||||||
|
|
||||||
$this->id = $userObject["id"];
|
$this->id = $userObject["id"];
|
||||||
$this->username = $userObject["nomeUtente"];
|
$this->username = $userObject["nomeUtente"];
|
||||||
$this->email = $userObject["email"];
|
$this->email = $userObject["email"];
|
||||||
@ -38,10 +40,12 @@ class User {
|
|||||||
return $this->token;
|
return $this->token;
|
||||||
}
|
}
|
||||||
public function loginWithToken(string $token){
|
public function loginWithToken(string $token){
|
||||||
$userObject = $this->db->select("utente", ["gettone" => $token])[0];
|
$query = $this->db->select("utente", ["gettone" => $token]);
|
||||||
if(!$userObject){
|
if(!$query){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$userObject = $query[0];
|
||||||
|
|
||||||
$this->id = $userObject["id"];
|
$this->id = $userObject["id"];
|
||||||
$this->username = $userObject["nomeUtente"];
|
$this->username = $userObject["nomeUtente"];
|
||||||
$this->email = $userObject["email"];
|
$this->email = $userObject["email"];
|
||||||
|
10
index.php
10
index.php
@ -48,22 +48,22 @@ $app->get("/", function (array $req, Response $res) use ($db) {
|
|||||||
/*
|
/*
|
||||||
* User
|
* User
|
||||||
*/
|
*/
|
||||||
$app->get("/user", function (array $req, Response $res) {
|
$app->route("/user")
|
||||||
|
->get(function (array $req, Response $res) {
|
||||||
if (isset($req["user"])) {
|
if (isset($req["user"])) {
|
||||||
$res->json(["id" => $req["user"]->id, "username" => $req["user"]->username, "email" => $req["user"]->email]);
|
$res->json(["id" => $req["user"]->id, "username" => $req["user"]->username, "email" => $req["user"]->email]);
|
||||||
} else {
|
} else {
|
||||||
$res->json(["status" => HTTP_STATUS_CODE::FORBIDDEN, "message" => "You are not logged in. Goto '/login' to login"]);
|
$res->json(["status" => HTTP_STATUS_CODE::FORBIDDEN, "message" => "You are not logged in. Goto '/login' to login"]);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
$app->post("/signup", function (array $req, Response $res) use ($db) {
|
->post(function (array $req, Response $res) use ($db) {
|
||||||
$newUsername = $req["body"]["username"];
|
$newUsername = $req["body"]["username"];
|
||||||
$newPassword = $req["body"]["password"];
|
$newPassword = $req["body"]["password"];
|
||||||
$newEmail = $req["body"]["email"];
|
$newEmail = $req["body"]["email"];
|
||||||
$db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]);
|
$db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]);
|
||||||
|
|
||||||
$res->send("Account Created", HTTP_STATUS_CODE::CREATED);
|
$res->send("Account Created", HTTP_STATUS_CODE::CREATED);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->post("/login", function (array $req, Response $res) use ($db) {
|
$app->post("/login", function (array $req, Response $res) use ($db) {
|
||||||
$username = $req["body"]["username"];
|
$username = $req["body"]["username"];
|
||||||
$password = $req["body"]["password"];
|
$password = $req["body"]["password"];
|
||||||
|
Loading…
Reference in New Issue
Block a user