*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
/**
/**
* Creates an instance of this captcha class
*
- * @param $templateInstance An instance of a template engine
+ * @param $helperInstance An instance of a helper class
* @param $extraInstance An extra instance, just for better hash data
* @return $captchaInstance An instance of this captcha class
*/
- public final static function createGraphicalCodeCaptcha (CompileableTemplate $templateInstance, FrameworkInterface $extraInstance = null) {
+ public final static function createGraphicalCodeCaptcha (HelpableTemplate $helperInstance, FrameworkInterface $extraInstance = null) {
// Get a new instance
$captchaInstance = new GraphicalCodeCaptcha();
// Set template instance
- $captchaInstance->setTemplateInstance($templateInstance);
+ $captchaInstance->setHelperInstance($helperInstance);
// Initialize the RNG
$captchaInstance->initializeRandomNumberGenerator($extraInstance);
$searchChars = $this->getConfigInstance()->readConfig('captcha_search_chars');
// Get fixed salt and use it as "replacement characters"
- $replaceChars = $this->getRngInstance()->getFixedSalt();
+ $replaceChars = $this->getRngInstance()->getExtraSalt();
// Remove any plus, equals or slashes
for ($searchIdx = 0; $searchIdx < strlen($searchChars); $searchIdx++) {
// Get crypto instance
$cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+ // Hash the CAPTCHA code for later comparison
+ $this->hashedString = $cryptoInstance->hashString($captchaString);
+
// Encrypt the string for later usage
$this->encryptedString = $cryptoInstance->encryptString($captchaString);
-
- // Hash the encrypted string for later comparison
- $this->hashedString = $cryptoInstance->hashString($this->encryptedString);
}
/**
* @return void
*/
public function renderCode () {
- $this->partialStub("Please implement this method.");
+ // Get helper instance
+ $helperInstance = $this->getHelperInstance();
+
+ // Get template instance
+ $templateInstance = $helperInstance->getTemplateInstance();
+
+ // Load a template for this CAPTCHA
+ $templateInstance->loadCodeTemplate('captch_graphic_code');
+
+ // Rename variable
+ $templateInstance->renameVariable('captcha_code', $helperInstance->getFormName().'_captcha');
+ $templateInstance->renameVariable('captcha_hash', $helperInstance->getFormName().'_hash');
+ $templateInstance->renameVariable('encrypted_code', $helperInstance->getFormName().'_encrypt');
+
+ // Assign variables
+ $templateInstance->assignVariable($helperInstance->getFormName().'_encrypt', urlencode(base64_encode($this->encryptedString)));
+ $templateInstance->assignVariable($helperInstance->getFormName().'_hash', $this->hashedString);
+
+ // Compile the template
+ $templateInstance->compileTemplate();
+
+ // Get the content back
+ $this->addContent($templateInstance->getRawTemplateData());
}
}