symfony关闭CSRFProtection

当我们使用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' => newsfWidgetFormInputPasswor d(array('type' =>'password')),
          'remember' => new sfWidgetFormInputCheckbo x(),
      ));

      $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]');
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值