gpt4 book ai didi

php - 如何覆盖验证码控制的 Symfony2 登录?

转载 作者:搜寻专家 更新时间:2023-10-31 21:08:45 24 4
gpt4 key购买 nike

首先;

Adding Captcha to Symfony2 Login Page

我看到了上面的对话,但这并不是我想要的。我只想在身份验证之前检查验证码是否为假。

不,我不想为此使用 bundle 。

我需要知道,symfony2 什么时候做安全登录事件?

图表:

登录表单提交 -> 检查验证码 -> 检查参数 -> 进行身份验证。

有什么想法吗?

最佳答案

我在下面使用它。

<?php

namespace CS\UserBundle\Listener;

use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;

class LoginListener
{
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
{
$request = $event->getRequest();
$captcha = $request->request->get('captcha');

if(!empty($captcha) && $captcha !== $request->getSession()->get('captcha')) {
throw new BadCredentialsException('Doğrulama Kodu Yanlış!');
}
}
}

服务(yml)

services:
cs_user.login_listener:
class: CS\UserBundle\Listener\LoginListener
tags:
- { name: kernel.event_listener, event: security.interactive_login }

关于php - 如何覆盖验证码控制的 Symfony2 登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26906236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com