Update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "master.h"
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <preferencemanager.h>
|
||||
|
||||
@@ -78,7 +79,7 @@ UserData checkUser(const String &uid) {
|
||||
userData.firstname = responseDoc["firstname"].as<String>();
|
||||
userData.lastname = responseDoc["lastname"].as<String>();
|
||||
userData.alter = responseDoc["alter"] | 0;
|
||||
userData.exists = responseDoc["exists"] | true;
|
||||
userData.exists = responseDoc["exists"] | false;
|
||||
}
|
||||
} else {
|
||||
Serial.printf("User check failed, HTTP code: %d\n", httpCode);
|
||||
@@ -88,43 +89,6 @@ UserData checkUser(const String &uid) {
|
||||
return userData;
|
||||
}
|
||||
|
||||
// Fügt einen neuen Benutzer mit den angegebenen Daten in die Datenbank ein.
|
||||
bool enterUserData(const String &uid, const String &firstname,
|
||||
const String &lastname, const String &geburtsdatum,
|
||||
int alter) {
|
||||
if (!backendOnline()) {
|
||||
Serial.println("No internet connection, cannot enter user data.");
|
||||
return false;
|
||||
}
|
||||
|
||||
HTTPClient http;
|
||||
http.begin(String(BACKEND_SERVER) + "/v1/private/create-player");
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
|
||||
|
||||
// Create JSON payload
|
||||
StaticJsonDocument<256> requestDoc;
|
||||
requestDoc["rfiduid"] = uid;
|
||||
requestDoc["firstname"] = firstname;
|
||||
requestDoc["lastname"] = lastname;
|
||||
requestDoc["birthdate"] = geburtsdatum;
|
||||
|
||||
String requestBody;
|
||||
serializeJson(requestDoc, requestBody);
|
||||
|
||||
int httpCode = http.POST(requestBody);
|
||||
|
||||
if (httpCode == HTTP_CODE_CREATED) {
|
||||
Serial.println("User data entered successfully.");
|
||||
http.end();
|
||||
return true;
|
||||
} else {
|
||||
Serial.printf("Failed to enter user data, HTTP code: %d\n", httpCode);
|
||||
http.end();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Holt alle Standorte aus der Datenbank und gibt sie als JSON-Dokument zurück.
|
||||
JsonDocument getAllLocations() {
|
||||
JsonDocument locations; // Allocate memory for the JSON document
|
||||
@@ -159,6 +123,45 @@ JsonDocument getAllLocations() {
|
||||
// (Kompatibilitätsfunktion).
|
||||
bool userExists(const String &uid) { return checkUser(uid).exists; }
|
||||
|
||||
// Fügt einen neuen Benutzer in die Datenbank ein
|
||||
bool enterUserData(const String &uid, const String &vorname,
|
||||
const String &nachname, const String &geburtsdatum,
|
||||
int alter) {
|
||||
if (!backendOnline()) {
|
||||
Serial.println("No internet connection, cannot enter user data.");
|
||||
return false;
|
||||
}
|
||||
|
||||
HTTPClient http;
|
||||
http.begin(String(BACKEND_SERVER) + "/v1/private/users/insert");
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
|
||||
|
||||
// Create JSON payload
|
||||
StaticJsonDocument<512> requestDoc;
|
||||
requestDoc["uid"] = uid;
|
||||
requestDoc["firstname"] = vorname;
|
||||
requestDoc["lastname"] = nachname;
|
||||
requestDoc["geburtsdatum"] = geburtsdatum;
|
||||
requestDoc["alter"] = alter;
|
||||
|
||||
String requestBody;
|
||||
serializeJson(requestDoc, requestBody);
|
||||
|
||||
int httpCode = http.POST(requestBody);
|
||||
|
||||
bool success = (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_CREATED);
|
||||
|
||||
if (success) {
|
||||
Serial.println("User data successfully entered into database");
|
||||
} else {
|
||||
Serial.printf("Failed to enter user data, HTTP code: %d\n", httpCode);
|
||||
}
|
||||
|
||||
http.end();
|
||||
return success;
|
||||
}
|
||||
|
||||
// Richtet die HTTP-Routen für die Backend-API ein (z.B. Health-Check, User- und
|
||||
// Location-Abfragen).
|
||||
void setupBackendRoutes(AsyncWebServer &server) {
|
||||
|
||||
Reference in New Issue
Block a user