/** * Generates the hash. * * @author Daniel Seemaier * @version * Version 0.1, 06.11.2010 */ public function onParseTime() { $class = $this->getAttribute('class'); $salt = $this->getAttribute('salt'); if ($salt === null) { throw new FormException('[CsrfProtectionHashTag::onParseTime()] The salt attribute is ' . 'not present. Please refer to the documentation concerning the setup of the ' . '<form:csrfhash /> tag!'); } /* @var $provider CSRFHashProvider */ $provider = $this->getServiceObject($class); $this->hash = $provider->generateHash($salt); // preset the value to make it available for the validator parent::onParseTime(); // add the csrfhash validator for every button $form = $this->getForm(); $buttons = $form->getFormElementsByTagName('form:button'); foreach ($buttons as $offset => $DUMMY) { $this->addValidator(new CSRFHashValidator($this, $buttons[$offset])); } }
/** * Implements the onAfterAppend method from the ui_element class. * * @author Christian Achatz, Stephan Spiess * @version * Version 0.1, 20.06.2008<br /> * Version 0.2, 10.11.2008 (Added the "clearonerror" attribute. If set to "true", the field is cleared on error.)<br /> * Version 0.3, 04.01.2010 (Added the text_id attribute)<br /> * Version 0.4, 29.10.2012 (Bug-fix: attribute valmarkerclass is now applied to the inner form field to allow css field validation on error)<br /> */ public function onParseTime() { // create text field $this->textField = new TextFieldTag(); $this->textField->setObjectId(XmlParser::generateUniqID()); // prepare the text field $textClass = $this->getAttribute('text_class'); if ($textClass !== null) { $this->textField->setAttribute('class', $textClass); } $textStyle = $this->getAttribute('text_style'); if ($textStyle !== null) { $this->textField->setAttribute('style', $textStyle); } $textId = $this->getAttribute('text_id'); if ($textId !== null) { $this->textField->setAttribute('id', $textId); } // apply validation marker css class to provide validation markup capabilities $errorClass = $this->getAttribute(AbstractFormValidator::$CUSTOM_MARKER_CLASS_ATTRIBUTE); if ($errorClass !== null) { $this->textField->setAttribute(AbstractFormValidator::$CUSTOM_MARKER_CLASS_ATTRIBUTE, $errorClass); } $this->textFieldName = md5($this->getParentObject()->getAttribute('name') . '_captcha'); $this->textField->setAttribute('name', $this->textFieldName); $this->textField->setAttribute('maxlength', '5'); // apply the onParseTime method to guarantee native APF environment $this->textField->setLanguage($this->language); $this->textField->setContext($this->context); $this->textField->onParseTime(); // apply the onAfterAppend method to guarantee native APF environment $this->textField->setParentObject($this->getParentObject()); $this->textField->onAfterAppend(); // get the captcha string from session $session = $this->getRequest()->getSession(ShowCaptchaImageAction::SESSION_NAMESPACE); $this->captchaString = $session->load($this->textFieldName); $session->save($this->textFieldName, StringAssistant::generateCaptchaString(5)); }