Commit fe10112f authored by Dominik Hebeler's avatar Dominik Hebeler

Reduced the amount of times users have to face captchas

parent b61ff337
...@@ -40,42 +40,43 @@ class HumanVerification ...@@ -40,42 +40,43 @@ class HumanVerification
return $next($request); return $next($request);
} }
$users = DB::select('select * from humanverification where id = ?', [$id]); $users = DB::select('select * from humanverification where id = ?', [$id]);
# Lock out everyone in a Bot network # Lock out everyone in a Bot network
# Find out how many requests this IP has made # Find out how many requests this IP has made
$sum = 0; $sum = 0;
foreach($users as $userTmp){ foreach ($users as $userTmp) {
if($uid == $userTmp->uid){ if ($uid == $userTmp->uid) {
$user = ['uid' => $userTmp->uid, $user = ['uid' => $userTmp->uid,
'id' => $userTmp->id, 'id' => $userTmp->id,
'unusedResultPages' => intval($userTmp->unusedResultPages), 'unusedResultPages' => intval($userTmp->unusedResultPages),
'whitelist' => filter_var($userTmp->whitelist, FILTER_VALIDATE_BOOLEAN), 'whitelist' => filter_var($userTmp->whitelist, FILTER_VALIDATE_BOOLEAN),
'whitelistCounter' => $userTmp->whitelistCounter, 'whitelistCounter' => $userTmp->whitelistCounter,
'locked' => filter_var($userTmp->locked, FILTER_VALIDATE_BOOLEAN), 'locked' => filter_var($userTmp->locked, FILTER_VALIDATE_BOOLEAN),
"lockedKey" => $userTmp->lockedKey, "lockedKey" => $userTmp->lockedKey,
'updated_at' => Carbon::now(), 'updated_at' => Carbon::now(),
]; ];
$newUser = false; $newUser = false;
} }
if($userTmp->whitelist === 0) if ($userTmp->whitelist === 0) {
$sum += $userTmp->unusedResultPages; $sum += $userTmp->unusedResultPages;
}
} }
# If this user doesn't have an entry we will create one # If this user doesn't have an entry we will create one
if ($user === null) { if ($user === null) {
$user = $user =
[ [
'uid' => $uid, 'uid' => $uid,
'id' => $id, 'id' => $id,
'unusedResultPages' => 0, 'unusedResultPages' => 0,
'whitelist' => false, 'whitelist' => false,
'whitelistCounter' => 0, 'whitelistCounter' => 0,
'locked' => false, 'locked' => false,
"lockedKey" => "", "lockedKey" => "",
'updated_at' => Carbon::now(), 'updated_at' => Carbon::now(),
]; ];
} }
# A lot of automated requests are from websites that redirect users to our result page. # A lot of automated requests are from websites that redirect users to our result page.
...@@ -94,9 +95,11 @@ class HumanVerification ...@@ -94,9 +95,11 @@ class HumanVerification
// Defines if this is the only user using that IP Adress // Defines if this is the only user using that IP Adress
$alone = true; $alone = true;
foreach($users as $userTmp){ foreach ($users as $userTmp) {
if($userTmp->uid != $uid && !$userTmp->whitelist) if ($userTmp->uid != $uid && !$userTmp->whitelist) {
$alone = false; $alone = false;
}
} }
if ((!$alone && $sum >= 50 && !$user["whitelist"]) || $refererLock) { if ((!$alone && $sum >= 50 && !$user["whitelist"]) || $refererLock) {
$user["locked"] = true; $user["locked"] = true;
...@@ -127,7 +130,7 @@ class HumanVerification ...@@ -127,7 +130,7 @@ class HumanVerification
# If the user shows activity on our result page the counter will be deleted # If the user shows activity on our result page the counter will be deleted
# Maybe I'll add a ban if the user reaches 100 # Maybe I'll add a ban if the user reaches 100
if ($user["unusedResultPages"] === 50 || $user["unusedResultPages"] === 75 || $user["unusedResultPages"] === 85 || $user["unusedResultPages"] >= 90) { if ($user["unusedResultPages"] === 50 || ($user["unusedResultPages"] > 50 && $user["unusedResultPages"] % 25 === 0)) {
$user["locked"] = true; $user["locked"] = true;
} }
...@@ -136,8 +139,8 @@ class HumanVerification ...@@ -136,8 +139,8 @@ class HumanVerification
// Failure in contacting metager3.de // Failure in contacting metager3.de
} finally { } finally {
// Update the user in the database // Update the user in the database
if($update){ if ($update) {
if($newUser){ if ($newUser) {
DB::table('humanverification')->insert( DB::table('humanverification')->insert(
[ [
'uid' => $user["uid"], 'uid' => $user["uid"],
...@@ -150,7 +153,7 @@ class HumanVerification ...@@ -150,7 +153,7 @@ class HumanVerification
'updated_at' => $user["updated_at"], 'updated_at' => $user["updated_at"],
] ]
); );
}else{ } else {
DB::table('humanverification')->where('uid', $uid)->update( DB::table('humanverification')->where('uid', $uid)->update(
[ [
'uid' => $user["uid"], 'uid' => $user["uid"],
...@@ -162,7 +165,7 @@ class HumanVerification ...@@ -162,7 +165,7 @@ class HumanVerification
"lockedKey" => $user["lockedKey"], "lockedKey" => $user["lockedKey"],
'updated_at' => $user["updated_at"], 'updated_at' => $user["updated_at"],
] ]
); );
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment