X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2FLogin_token.php;h=7a9388c947511b2bbb4b9d42cfad324d0198e377;hb=96d735baf41c5db04778fc2d2a59a5f8641458bd;hp=746cd7f2295aa1b968b53deabde1dbf1e9edc17e;hpb=f6bf9529805cd58fdd1671dd9b133bde05e8ae87;p=quix0rs-gnu-social.git diff --git a/classes/Login_token.php b/classes/Login_token.php index 746cd7f229..7a9388c947 100644 --- a/classes/Login_token.php +++ b/classes/Login_token.php @@ -35,11 +35,13 @@ class Login_token extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Login_token',$k,$v); } + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Login_token',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + const TIMEOUT = 120; // seconds after which to timeout the token + /* DB_DataObject calculates the sequence key(s) by taking the first key returned by the keys() function. In this case, the keys() function returns user_id as the first key. user_id is not a sequence, but @@ -52,4 +54,31 @@ class Login_token extends Memcached_DataObject { return array(false,false); } + + function makeNew($user) + { + $login_token = Login_token::staticGet('user_id', $user->id); + + if (!empty($login_token)) { + $login_token->delete(); + } + + $login_token = new Login_token(); + + $login_token->user_id = $user->id; + $login_token->token = common_good_rand(16); + $login_token->created = common_sql_now(); + + $result = $login_token->insert(); + + if (!$result) { + common_log_db_error($login_token, 'INSERT', __FILE__); + // TRANS: Exception thrown when trying creating a login token failed. + // TRANS: %s is the user nickname for which token creation failed. + throw new Exception(sprintf(_('Could not create login token for %s'), + $user->nickname)); + } + + return $login_token; + } }