onokazu
onoka****@users*****
2005年 6月 1日 (水) 19:30:04 JST
Index: xoops2jp/html/class/xoopssecurity.php diff -u xoops2jp/html/class/xoopssecurity.php:1.1.2.7 xoops2jp/html/class/xoopssecurity.php:1.1.2.8 --- xoops2jp/html/class/xoopssecurity.php:1.1.2.7 Tue May 17 15:10:16 2005 +++ xoops2jp/html/class/xoopssecurity.php Wed Jun 1 19:30:04 2005 @@ -1,9 +1,5 @@ <?php -// $Id: xoopssecurity.php,v 1.1.2.7 2005/05/17 06:10:16 onokazu Exp $ - -if (!defined('XOOPS_TOKEN_XOOPSORG')) { - define('XOOPS_TOKEN_XOOPSORG', 'XOOPS_TOKEN_XOOPSORG'); -} +// $Id: xoopssecurity.php,v 1.1.2.8 2005/06/01 10:30:04 onokazu Exp $ /** * Class for xoops.org 2.0.10 compatibility @@ -12,6 +8,7 @@ */ class XoopsSecurity { + var $errors; function check($clearIfValid = true, $tokenValue = false) { return $this->validateToken($tokenValue, $clearIfValid); @@ -19,7 +16,7 @@ function createToken($timeout = XOOPS_TOKEN_TIMEOUT) { - $token =& XoopsMultiTokenHandler::quickCreate(XOOPS_TOKEN_XOOPSORG, $timeout); + $token =& XoopsMultiTokenHandler::quickCreate(XOOPS_TOKEN_DEFAULT, $timeout); return $token->getTokenValue(); } @@ -27,22 +24,52 @@ { if (false !== $tokenValue) { $handler = new XoopsSingleTokenHandler(); - $token =& $handler->fetch(XOOPS_TOKEN_XOOPSORG); + $token =& $handler->fetch(XOOPS_TOKEN_DEFAULT); if($token->validate($tokenValue)) { if ($clearIfValid) { $handler->unregister($token); } return true; } else { + $this->setErrors('No token found'); return false; } } - return XoopsMultiTokenHandler::quickValidate(XOOPS_TOKEN_XOOPSORG, $clearIfValid); + return XoopsMultiTokenHandler::quickValidate(XOOPS_TOKEN_DEFAULT, $clearIfValid); } function getTokenHTML() { - $token =& XoopsMultiTokenHandler::quickCreate(XOOPS_TOKEN_XOOPSORG); + $token =& XoopsMultiTokenHandler::quickCreate(XOOPS_TOKEN_DEFAULT); return $token->getHtml(); } + + /** + * Add an error + * @param string $error + **/ + function setErrors($error) + { + $this->errors[] = trim($error); + } + + /** + * Get generated errors + * @param bool $ashtml Format using HTML? + * @return array|string Array of array messages OR HTML string + */ + function &getErrors($ashtml = false) + { + if (!$ashtml) { + return $this->errors; + } else { + $ret = ''; + if (count($this->errors) > 0) { + foreach ($this->errors as $error) { + $ret .= $error.'<br />'; + } + } + return $ret; + } + } } ?> \ No newline at end of file