3
对于sf应用程序,我想从FOSUserBundle中的编辑配置文件表单中删除密码检查。删除编辑中的密码检查配置文件
只需通过覆盖配置文件表单来删除“当前”字段仍会导致“密码无效”验证消息。这是通过从FOSUSerBundle的ProfileFormHandler类引起的下列代码:
$this->form->setData(new CheckPassword($user));
所以我overrided表单处理程序以及和替换
$this->form->setData($user);
到目前为止,这个作品和我的表单类型上面的代码显示和我的表单处理程序处理窗体,但我得到以下错误
The CSRF token is invalid. Please try to resubmit the form
确实csrf令牌不再添加到窗体了。坦白说,我不知道我做错了什么;(
THX,本
这里是形式的完整代码,处理程序和模板:
<?php
namespace Application\Sonata\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
class ProfileFormType extends \FOS\UserBundle\Form\Type\ProfileFormType
{
private $class;
/**
* @param string $class The User class name
*/
public function __construct($class)
{
$this->class = $class;
}
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('first_name')
->add('last_name')
->add('phone')
->add('location','room13_geo_location')
->add('birthday','birthday')
->add('smoker')
->add('newsletter')
;
}
public function getName()
{
return 'balkanride_user_profile';
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => $this->class,
'intention' => 'profile',
);
}
}
-
<?php
namespace Application\Sonata\UserBundle\Form\Handler;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Form\Model\CheckPassword;
class ProfileFormHandler
{
protected $request;
protected $userManager;
protected $form;
public function __construct(Form $form, Request $request, UserManagerInterface $userManager)
{
$this->form = $form;
$this->request = $request;
$this->userManager = $userManager;
}
public function process(UserInterface $user)
{
$this->form->setData($user);
if ('POST' === $this->request->getMethod())
{
$this->form->bindRequest($this->request);
//var_dump($this->form->getErrors());
//die();
if ($this->form->isValid())
{
$this->onSuccess($user);
return true;
}
// Reloads the user to reset its username. This is needed when the
// username or password have been changed to avoid issues with the
// security layer.
$this->userManager->reloadUser($user);
}
return false;
}
protected function onSuccess(UserInterface $user)
{
$this->userManager->updateUser($user);
}
}
-
{% extends "ApplicationSonataUserBundle::layout.html.twig" %}
{% block page_body %}
<section>
<form id="ProfileForm" action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit">
{{ form_widget(form) }}
<div>
<div class="form-actions">
<input type="submit" value="{{ 'profile.edit.submit'|trans }}" class="btn btn-primary" />
<a href="{{path('fos_user_profile_show')}}" class="btn">{{ 'profile.edit.cancel'|trans }}</a>
</div>
</div>
</form>
</section>
{% endblock page_body %}
听起来像一个很好的解决方案。这个问题非常古老,问题不再存在......我仍然会将你的答案标记为完整性的正确答案;) – room13 2014-01-16 14:01:37