Compare commits

..

8 Commits
done ... don

Author SHA1 Message Date
92d9ddb8f7 „Documentation/Dokumentation.md“ ändern 2023-01-25 08:51:08 +01:00
bb626538c4 Dateien hochladen nach „ERD“
Accurat ERD
2023-01-25 08:45:47 +01:00
Johannes Kantz
46dbcca254 fix: typo 2023-01-25 08:45:16 +01:00
Johannes Kantz
34aa9e10f9 fix: user token error 2023-01-25 08:32:42 +01:00
Johannes Kantz
b84c4fd8e3 fix: user post and get 2023-01-25 08:27:03 +01:00
Johannes Kantz
20a26ebd66 fix login error 2023-01-25 08:16:44 +01:00
abc1be3885 Merge pull request 'late fix' (#6) from done into don
Reviewed-on: #6
2023-01-25 08:04:51 +01:00
9822a9f738 Merge pull request 'done' (#3) from done into don
Reviewed-on: #3
2023-01-24 20:11:19 +01:00
4 changed files with 40 additions and 21 deletions

View File

@ -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

View File

@ -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"];

View File

@ -48,22 +48,22 @@ $app->get("/", function (array $req, Response $res) use ($db) {
/*
* User
*/
$app->get("/user", function (array $req, Response $res) {
$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"]);
}
});
$app->post("/signup", function (array $req, Response $res) use ($db) {
})
->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"];