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
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/signup
|
||||
POST 127.0.0.1/DirektiveDesDons/user
|
||||
|
||||
BODY
|
||||
{
|
||||
@ -119,7 +119,7 @@ DELETE 127.0.0.1/DirektiveDesDons/ingredient/1
|
||||
|
||||
### Zutat ändern
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/ingredient/3
|
||||
PUT 127.0.0.1/DirektiveDesDons/ingredient/3
|
||||
|
||||
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
|
||||
```shell
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
$userObject = $query[0];
|
||||
|
||||
$this->id = $userObject["id"];
|
||||
$this->username = $userObject["nomeUtente"];
|
||||
$this->email = $userObject["email"];
|
||||
@ -38,10 +40,12 @@ class User {
|
||||
return $this->token;
|
||||
}
|
||||
public function loginWithToken(string $token){
|
||||
$userObject = $this->db->select("utente", ["gettone" => $token])[0];
|
||||
if(!$userObject){
|
||||
$query = $this->db->select("utente", ["gettone" => $token]);
|
||||
if(!$query){
|
||||
return false;
|
||||
}
|
||||
$userObject = $query[0];
|
||||
|
||||
$this->id = $userObject["id"];
|
||||
$this->username = $userObject["nomeUtente"];
|
||||
$this->email = $userObject["email"];
|
||||
|
30
index.php
30
index.php
@ -48,22 +48,22 @@ $app->get("/", function (array $req, Response $res) use ($db) {
|
||||
/*
|
||||
* User
|
||||
*/
|
||||
$app->get("/user", function (array $req, Response $res) {
|
||||
if (isset($req["user"])) {
|
||||
$res->json(["id" => $req["user"]->id, "username" => $req["user"]->username, "email" => $req["user"]->email]);
|
||||
} else {
|
||||
$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) {
|
||||
$newUsername = $req["body"]["username"];
|
||||
$newPassword = $req["body"]["password"];
|
||||
$newEmail = $req["body"]["email"];
|
||||
$db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]);
|
||||
|
||||
$res->send("Account Created", HTTP_STATUS_CODE::CREATED);
|
||||
});
|
||||
$app->route("/user")
|
||||
->get(function (array $req, Response $res) {
|
||||
if (isset($req["user"])) {
|
||||
$res->json(["id" => $req["user"]->id, "username" => $req["user"]->username, "email" => $req["user"]->email]);
|
||||
} else {
|
||||
$res->json(["status" => HTTP_STATUS_CODE::FORBIDDEN, "message" => "You are not logged in. Goto '/login' to login"]);
|
||||
}
|
||||
})
|
||||
->post(function (array $req, Response $res) use ($db) {
|
||||
$newUsername = $req["body"]["username"];
|
||||
$newPassword = $req["body"]["password"];
|
||||
$newEmail = $req["body"]["email"];
|
||||
$db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]);
|
||||
|
||||
$res->send("Account Created", HTTP_STATUS_CODE::CREATED);
|
||||
});
|
||||
$app->post("/login", function (array $req, Response $res) use ($db) {
|
||||
$username = $req["body"]["username"];
|
||||
$password = $req["body"]["password"];
|
||||
|
Loading…
Reference in New Issue
Block a user