RFID Master Working, Read the RFID and enter it into the database

This commit is contained in:
Carsten Graf
2025-06-08 14:44:41 +02:00
parent c35e857904
commit f2fe9ac13c
5 changed files with 308 additions and 124 deletions

View File

@@ -81,6 +81,43 @@ UserData checkUser(const String& uid) {
return userData;
}
//Function to enter user data into the database
bool enterUserData(const String& uid, const String& firstname, const String& lastname, int alter) {
if (!backendOnline()) {
Serial.println("No internet connection, cannot enter user data.");
return false;
}
HTTPClient http;
http.begin(String(BACKEND_SERVER) + "/api/users/insert");
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
// Create JSON payload
StaticJsonDocument<256> requestDoc;
requestDoc["uid"] = uid;
requestDoc["vorname"] = firstname;
requestDoc["nachname"] = lastname;
requestDoc["alter"] = alter;
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;
}
}
// Keep this for backward compatibility
bool userExists(const String& uid) {
return checkUser(uid).exists;