当然也可以使用配置里面完全把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' => new sfWidgetFormInputPassword(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))
- {
- $this->widgetSchema['username']->setLabel('用户名');
- $this->widgetSchema['password']->setLabel('密码');
- $this->widgetSchema['remember']->setLabel('记住我');
- }
- $this->validatorSchema->setPostValidator(new sfGuardValidatorUser());
- $this->widgetSchema->setNameFormat('signin[%s]');
- }
- }
转载于:https://blog.51cto.com/leexiaobo/928731