20 include_once (
'Class.DbObj.php');
24 var
$Class =
'$Id: Class.UserToken.php,v 1.6 2009/01/16 13:33:00 jerome Exp $';
55 CREATE TABLE usertoken (
56 token text NOT NULL PRIMARY KEY,
58 cdate timestamp without time zone,
61 expire TIMESTAMP NOT NULL,
62 expendable BOOLEAN DEFAULT FALSE,
66 CREATE INDEX usertoken_idx ON usertoken(token);
75 if (is_array($this->context)) {
76 $this->context = serialize($this->context);
78 $this->cdate = date(
"Y-m-d H:i:s");
80 $this->authorid = ($currentUser !== null) ? $currentUser->id : null;
88 $this->expire = self::getExpirationDate(
$expiration);
94 if (preg_match(
'/^-?infinity$/', $delayInSeconds)) {
95 $expireDate = $delayInSeconds;
97 if (!is_numeric($delayInSeconds)) {
100 $expireDate = strftime(
"%Y-%m-%d %H:%M:%S", time() + $delayInSeconds);
108 $bytes = openssl_random_pseudo_bytes($this->tokenByteLength, $strong);
109 if ($bytes ===
false || $strong ===
false) {
110 throw new \Dcp\Exception(sprintf(
"Unable to get cryptographically strong random bytes from openssl: your system might be broken or too old."));
112 return bin2hex($bytes);
117 if ($this->token ==
"") {
118 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " .
"token is not defined.");
125 $sql = sprintf(
"DELETE FROM usertoken WHERE expire < now()");
131 if ($this->token ==
"") {
132 return "Error: token not set";
134 if ($this->userid ==
"") {
135 return "Error: userid not set";
137 if ($this->expire ==
"") {
138 return "Error: expire not set";
static getExpirationDate($delayInSeconds)
setExpiration($expiration="")
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)