src/AppBundle/Component/RateLimit/RegisterRateLimiter.php

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace AppBundle\Component\RateLimit;

use AppBundle\Common\TimeMachine;
use Codeages\RateLimiter\RateLimiter;
use AppBundle\Controller\OAuth2\OAuthUser;
use Symfony\Component\HttpFoundation\Request;

class RegisterRateLimiter extends AbstractRateLimiter implements RateLimiterInterface
{
    const MID_IP_MAX_ALLOW_ATTEMPT_ONE_DAY = 30;

    const HIGH_IP_MAX_ALLOW_ATTEMPT_ONE_DAY = 10;

    const HIGH_IP_MAX_ALLOW_ATTEMPT_ONE_HOUR = 1;

    public function handle(Request $request)
    {
        switch ($this->getRegisterProtective()) {
            case 'none':
                return;
            case 'low':
                $oauthUser = $this->getOauthUser($request);
                if ($oauthUser->captchaEnabled) {
                    $this->validateCaptcha($request);
                }
                break;
            case 'middle':
                $oauthUser = $this->getOauthUser($request);
                if ($oauthUser->captchaEnabled) {
                    $this->validateCaptcha($request);
                }
                $factory = $this->biz['ratelimiter.factory'];
                /** @var RateLimiter $limiter */
                $limiter = $factory('register.ip.mid_one_day', self::MID_IP_MAX_ALLOW_ATTEMPT_ONE_DAY, TimeMachine::ONE_DAY);

                $remain = $limiter->check($request->getClientIp());

                if (0 == $remain) {
                    throw $this->createMaxRequestOccurException();
                }

                break;
            case 'high':
                //手机不需要校验验证码,只需要短信校验码
                $oauthUser = $this->getOauthUser($request);
                if ($oauthUser->captchaEnabled) {
                    $this->validateCaptcha($request);
                }

                $factory = $this->biz['ratelimiter.factory'];
                /** @var RateLimiter $dayLimiter */
                $dayLimiter = $factory('register.ip.high_one_day', self::HIGH_IP_MAX_ALLOW_ATTEMPT_ONE_DAY, TimeMachine::ONE_DAY);
                $remain = $dayLimiter->check($request->getClientIp());
                if (0 == $remain) {
                    throw $this->createMaxRequestOccurException();
                }

                /** @var RateLimiter $hourLimiter */

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。