mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
complains.php + confirm_resend.php add lock
This commit is contained in:
20
app/Exceptions/LockFailException.php
Normal file
20
app/Exceptions/LockFailException.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require "../include/bittorrent.php";
|
||||
\Nexus\Database\NexusLock::lockOrFail("confirm_resend:lock:" . getip(), 10);
|
||||
dbconn();
|
||||
failedloginscheck ("Re-send",true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user