2012-04-12 14 views
3

sfアプリケーション用FOSUserBundleのプロファイル編集フォームからパスワードチェックを削除します。パスワードチェックインを削除します。編集プロファイル

プロファイルフォームを上書きして「現在の」フィールドを削除するだけで、引き続き「パスワードが無効です」検証メッセージが表示されます。これは、次のコードでFOSUSerBundleからProfileFormHandlerクラスによって引き起こされる:

$this->form->setData(new CheckPassword($user)); 

は、だから私は、同様のフォームハンドラをオーバーライドし、

$this->form->setData($user); 

で上記のコードを置き換え今のところ、これは動作し、私のフォームタイプフォームハンドラーがフォームを処理しますが、次のエラーが発生します。

The CSRF token is invalid. Please try to resubmit the form 

確かにcsrfトークンはフォームに追加されません。 -

<?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); 
    } 
} 

<?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', 
     ); 
    } 
} 

:;率直に言って私は私が間違っていたかわからない(

THXを、ベン

ここでは、フォームの完全なコード、ハンドラやテンプレートであります

-

{% 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 %} 

答えて

1

これを修正するには、パスワード保護を必要としないフィールドを編集するために別のフォームを作成して編集することをお勧めします。最も簡単でハックがありません:)

+0

良い解決策のようです。問題は非常に古く、問題はもう存在しません...あなたの答えを完全性のために正しいものとしてマークします;) – room13

関連する問題