complains.php + confirm_resend.php add lock

This commit is contained in:
xiaomlove
2025-09-21 14:43:00 +07:00
parent d16a864841
commit c74c36d434
5 changed files with 39 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Exceptions;
class LockFailException extends NexusException
{
public function __construct(protected string $lockName, protected string $lockOwner)
{
parent::__construct();
}
public function getLockName(): string
{
return $this->lockName;
}
public function getLockOwner(): string
{
return $this->lockOwner;
}
}

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.7');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-09-20');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-09-21');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -2,6 +2,7 @@
namespace Nexus\Database;
use App\Exceptions\LockFailException;
use Illuminate\Cache\LuaScripts;
use Illuminate\Cache\RedisLock;
@@ -47,4 +48,17 @@ class NexusLock extends RedisLock
return (bool) $this->redis->eval(LuaScripts::releaseLock(), [$this->name, $this->owner], 1);
}
/**
* @throws LockFailException
*/
public static function lockOrFail($name, $seconds, $owner = null): NexusLock
{
$lock = new self($name, $seconds, $owner);
if (!$lock->acquire()) {
do_log("$name failed to acquire lock", 'error');
throw new LockFailException($name, $lock->owner());
}
return $lock;
}
}

View File

@@ -19,10 +19,12 @@ if($_SERVER['REQUEST_METHOD'] === 'POST'){
case 'new':
cur_user_check();
check_code ($_POST['imagehash'], $_POST['imagestring'],'complains.php');
\Nexus\Database\NexusLock::lockOrFail("complains:lock:" . getip(), 10);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
\Nexus\Database\NexusLock::lockOrFail("complains:lock:" . $email, 600);
$body = filter_input(INPUT_POST, 'body', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if(empty($email) || empty($body)) stderr($lang_functions['std_error'], $lang_complains['text_new_failure']);
$user = \App\Models\User::query()->where('email', $email)->first();
$user = \App\Models\User::query()->where('email', $email)->where('enabled', 'no')->first();
if (!$user) {
stderr($lang_functions['std_error'], $lang_complains['text_new_failure']);
}

View File

@@ -1,5 +1,6 @@
<?php
require "../include/bittorrent.php";
\Nexus\Database\NexusLock::lockOrFail("confirm_resend:lock:" . getip(), 10);
dbconn();
failedloginscheck ("Re-send",true);