public function canPostWithoutCaptcha(PermissionUser $user) { if ($user->canPostWithoutCaptcha($this)) { return true; } $lastCaptcha = Captcha::select('created_at', 'cracked_at')->where('client_ip', inet_pton(Request::ip()))->where('created_at', '>=', \Carbon\Carbon::now()->subHour())->whereNotNull('cracked_at')->orderBy('cracked_at', 'desc')->first(); if ($lastCaptcha instanceof Captcha) { $postsWithCaptcha = Post::select('created_at')->where('author_ip', inet_pton(Request::ip()))->where('created_at', '>=', $lastCaptcha->created_at)->count(); return $postsWithCaptcha <= 10; } return false; }
public function canPostWithoutCaptcha(PermissionUser $user) { // Check if site requires captchas. if (!site_setting('captchaEnabled')) { return true; } // Check if this user can bypass captchas. if ($user->canPostWithoutCaptcha($this)) { return true; } // Begin to check captchas for last answers. $ip = new IP(); $lastCaptcha = Captcha::select('created_at', 'cracked_at')->where(function ($query) use($ip) { // Find captchas answered by this user. $query->where('client_ip', $ip); // Pull the lifespan of a captcha. // This is the number of minutes between successful entries. $captchaLifespan = (int) site_setting('captchaLifespanTime', 0); if ($captchaLifespan > 0) { $query->whereNotNull('cracked_at'); $query->where('cracked_at', '>=', \Carbon\Carbon::now()->subMinutes($captchaLifespan)); } })->orderBy('cracked_at', 'desc')->first(); $requireCaptcha = !$lastCaptcha instanceof Captcha; if (!$requireCaptcha) { $captchaLifespan = (int) site_setting('captchaLifespanPosts'); if ($captchaLifespan > 0) { $postsWithCaptcha = Post::select('created_at')->where('author_ip', $ip)->where('created_at', '>=', $lastCaptcha->created_at)->count(); $requireCaptcha = $postsWithCaptcha >= $captchaLifespan; } } return !$requireCaptcha; }
public function canPostWithoutCaptcha(PermissionUser $user) { if ($user->canPostWithoutCaptcha($this)) { return true; } $lastCaptcha = Captcha::where('client_ip', inet_pton(Request::ip()))->where('created_at', '>=', \Carbon\Carbon::now()->subHour()->timestamp)->whereNotNull('cracked_at')->first(); if ($lastCaptcha instanceof Captcha && $lastCaptcha->cracked_at) { return true; } return false; }