我是Symfony2的新手,但非常了解它.首先,我使用的是symfony 2.1.7.和FOSUserBundle用于用户设置.我已经使用用户名和密码覆盖了fos_user-login模板.但我想为登录添加验证码.我见过GregwarCaptchaBundle,根据文档,应该在FormType中添加新字段.我的问题是:symfony或FOSUserBundle登录表单类型在哪里,我可以添加这个新字段,还是覆盖它?存在ChangePasswordFormType,ProfileFormType ...等但没有LoginFOrmType.可能它是如此明显,但我没有得到重点,欢迎任何帮助请问
问题是解决方案的一些解决方案
看看下面的评论,帕特帮助了我.我用_username,_password和captcha字段创建了一个新的表单类型.当用户名和密码命名以下划线开头时,足以进行"login_check"路由和Symfony身份验证.但是,Symfony使用侦听器进行登录过程.哪个是UsernamePasswordFormAuthenticationListener班级.虽然我在Form类型中添加了captcha字段,但在登录过程中总是会被忽略.(它在页面上呈现,但该字段永远不会被验证,只会被忽略.)
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('_username', 'email', array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle')) // TODO: user can login with email by inhibit the user to enter username
->add('_password', 'password', array(
'label' => 'form.current_password',
'translation_domain' => 'FOSUserBundle',
'mapped' => false,
'constraints' => new UserPassword()))
->add('captcha', 'captcha');
}
Run Code Online (Sandbox Code Playgroud)
正如我上面提到的,UsernamePasswordFormAuthenticationListener类获取表单输入值,然后重定向到您:
public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, …Run Code Online (Sandbox Code Playgroud)