symfony关闭CSRFProtection

来源:互联网 发布:软件找不到数据库文件 编辑:程序博客网 时间:2024/06/16 08:46
当我们使用symfony自带的sfGuardPlugin的时候。会自动生成登录验证页面。
默认情况下,页面中会有一个默认的参数叫_csrf_token的提交。
现在我们这边需要做个页面,但是不需要_csrf_token这个参数。
我们需要更改form,关闭CSRFProtection.
我们打开BasesfGuardFormSignin.class.php页面。

class BasesfGuardFormSignin extends BaseForm
{
 

  public function setup()
  {
  //在页面中加入这一行,就能关闭CSRFProtection了。这样登录页面就没有_csrf_token了。
   $this->disableCSRFProtection();
   $this->setWidgets(array(
     'username' => new sfWidgetFormInputText(),
     'password' => newsfWidgetFormInputPassword(array('type' =>'password')),
     'remember' => new sfWidgetFormInputCheckbox(),
    ));

   $this->setValidators(array(
     'username' => new sfValidatorString(),
     'password' => new sfValidatorString(),
     'remember' => new sfValidatorBoolean(),
    ));

    if(sfConfig::get('app_sf_guard_plugin_allow_login_with_email',true))
    {
    // 从配置文件中读取sf_guart_plugin_allow_login_with_email参数
     $this->widgetSchema['username']->setLabel('用户名');
     $this->widgetSchema['password']->setLabel('密码');
     $this->widgetSchema['remember']->setLabel('记住我');
    }

   $this->validatorSchema->setPostValidator(newsfGuardValidatorUser());

   $this->widgetSchema->setNameFormat('signin[%s]');
  }
}