src/AppBundle/Handler/AuthenticationFailureHandler.php

(开头部分) 2KB

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

<?php

namespace AppBundle\Handler;

use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Topxia\Service\Common\ServiceKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;

class AuthenticationFailureHandler extends DefaultAuthenticationFailureHandler
{
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
    {
        $request->getSession()->set('_target_path', $request->request->get('_target_path'));

        if (!$exception instanceof BadCredentialsException) {
            goto end;
        }

        $default = array(
            'temporary_lock_enabled' => 0,
            'temporary_lock_allowed_times' => 5,
            'ip_temporary_lock_allowed_times' => 20,
            'temporary_lock_minutes' => 20,
        );
        $setting = $this->getSettingService()->get('login_bind', array());
        $setting = array_merge($default, $setting);

        if (empty($setting['temporary_lock_enabled'])) {
            goto end;
        }

        $forbidden = AuthenticationHelper::checkLoginForbidden($request);

        if ($forbidden['status'] == 'error') {
            $message = $forbidden['message'];
            $exception = new AuthenticationException($message);
        } else {
            $failed = $this->getUserService()->markLoginFailed($forbidden['user'] ? $forbidden['user']['id'] : 0, $request->getClientIp());

            if ($forbidden['user']) {
                if ($failed['ipFaildCount'] >= $setting['ip_temporary_lock_allowed_times']) {
                    $message = $this->getServiceKernel()->trans('您当前IP下帐号或密码输入错误过多,请在%settingTemporaryLockMinutes%分钟后再试。', array('%settingTemporaryLockMinutes%' => $setting['temporary_lock_minutes']));
                } elseif ($failed['leftFailedCount']) {
                    $message = $this->getServiceKernel()->trans('帐号或密码错误,您还有%failedLeftFailedCount%次输入机会', array('%failedLeftFailedCount%' => $failed['leftFailedCount']));
                } else {
                    $message = $this->getServiceKernel()->trans('帐号或密码输入错误过多,请在%settingTemporaryLockMinutes%分钟后再试,您可以通过找回并重置密码来解除封禁。', array('%settingTemporaryLockMinutes%' => $setting['temporary_lock_minutes']));
                }

                $exception = new AuthenticationException($message);
            }
        }

        end:

        if ($request->isXmlHttpRequest()) {
            $content = array(
                'success' => false,

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

AI 解读 AI

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

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