From 485f804b16cbb0a8d6cf2bb58842715414ecb1bb Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Wed, 12 Feb 2020 13:47:45 +0100
Subject: [PATCH] deleting works again

---
 .env.example                               |  2 ++
 app/Http/Controllers/HumanVerification.php | 12 ++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/.env.example b/.env.example
index 49f4b2692..155d08ba3 100644
--- a/.env.example
+++ b/.env.example
@@ -4,6 +4,8 @@ APP_LOG_LEVEL=debug
 APP_KEY=
 APP_URL=http://localhost
 
+BOT_PROTECTION=true
+
 DB_CONNECTION=mysql
 DB_HOST=mgdb
 DB_PORT=3306
diff --git a/app/Http/Controllers/HumanVerification.php b/app/Http/Controllers/HumanVerification.php
index 9e9cada8a..97f148c24 100644
--- a/app/Http/Controllers/HumanVerification.php
+++ b/app/Http/Controllers/HumanVerification.php
@@ -92,9 +92,9 @@ class HumanVerification extends Controller
     public static function removeGet(Request $request, $mm, $password, $url)
     {
         $url = base64_decode(str_replace("<<SLASH>>", "/", $url));
-
         # If the user is correct and the password is we will delete any entry in the database
         $requiredPass = md5($mm . Carbon::NOW()->day . $url . env("PROXY_PASSWORD"));
+
         if (HumanVerification::checkId($request, $mm) && $requiredPass === $password) {
             HumanVerification::removeUser($request, $mm);
         }
@@ -126,8 +126,13 @@ class HumanVerification extends Controller
                 $changed = true;
             }
         }
+
         if ($changed) {
-            Cache::put(HumanVerification::PREFIX . "." . $user["id"], $userList, now()->addWeeks(2));
+            if (sizeof($newUserList) > 0) {
+                Cache::put(HumanVerification::PREFIX . "." . $user["id"], $newUserList, now()->addWeeks(2));
+            } else {
+                Cache::forget(HumanVerification::PREFIX . "." . $user["id"], $newUserList);
+            }
         }
     }
 
@@ -152,11 +157,10 @@ class HumanVerification extends Controller
 
         $sum = 0;
         foreach ($userlist as $uidTmp => $userTmp) {
-            if (!empty($userTmp) && !empty($userTmp["whitelist"]) && !$userTmp["whitelist"]) {
+            if (!empty($userTmp) && gettype($userTmp["whitelist"]) === "boolean" && !$userTmp["whitelist"]) {
                 $sum += intval($userTmp["unusedResultPages"]);
             }
         }
-
         # Check if we have to whitelist the user or if we can simply delete the data
         if ($user["unusedResultPages"] < $sum && !$user["whitelist"]) {
             # Whitelist
-- 
GitLab