diff --git a/app/Exceptions/LockFailException.php b/app/Exceptions/LockFailException.php new file mode 100644 index 00000000..86b72820 --- /dev/null +++ b/app/Exceptions/LockFailException.php @@ -0,0 +1,20 @@ +lockName; + } + public function getLockOwner(): string + { + return $this->lockOwner; + } +} diff --git a/include/constants.php b/include/constants.php index 7a29c5e8..124f384f 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ 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; + } + } diff --git a/public/complains.php b/public/complains.php index db72dd26..8f8c8b1f 100644 --- a/public/complains.php +++ b/public/complains.php @@ -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']); } diff --git a/public/confirm_resend.php b/public/confirm_resend.php index c658a43f..ce9b6115 100644 --- a/public/confirm_resend.php +++ b/public/confirm_resend.php @@ -1,5 +1,6 @@