冗長な解説はしない。まず、プロジェクト毎のActionForm(ActionClassではない)の中で
function _validatePlus()
{
if ($this->use_csrf_plugin == true) {
if (!Ethna_Util::isCsrfSafe()) {
$this->ae->add(null, '外部からのリクエストは受け付けていません');
}
}
}
と書いておいて、さらに、プロジェクト毎のViewClassで、
function getFormBlock($content, $params)
{
// method
if (isset($params['method']) === false) {
$params['method'] = 'post';
}
if ($this->af->use_csrf_plugin == true) {
Ethna_Util::setCsrfID();
$csrf = smarty_function_csrfid(array(), &$renderer);
$content .= $csrf;
}
return $this->_getFormInput_Html('form', $params, $content, false);
}
としておくと、ActionFormで$use_csrf_plugin = true;した時だけ自動的にcsrf用のフォームが追加され、validateした時に一緒に検証されるようになる。はず。
Related posts:
ピンバック: スパムとか