3 * Table Definition for login_token
5 * StatusNet - the distributed open-source microblogging tool
6 * Copyright (C) 2009, StatusNet, Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
24 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
26 class Login_token extends Memcached_DataObject
29 /* the code below is auto generated do not remove the above tag */
31 public $__table = 'login_token'; // table name
32 public $user_id; // int(4) primary_key not_null
33 public $token; // char(32) not_null
34 public $created; // datetime() not_null
35 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
38 function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Login_token',$k,$v); }
40 /* the code above is auto generated do not remove the tag below */
43 const TIMEOUT = 120; // seconds after which to timeout the token
46 DB_DataObject calculates the sequence key(s) by taking the first key returned by the keys() function.
47 In this case, the keys() function returns user_id as the first key. user_id is not a sequence, but
48 DB_DataObject's sequenceKey() will incorrectly think it is. Then, since the sequenceKey() is a numeric
49 type, but is not set to autoincrement in the database, DB_DataObject will create a _seq table and
50 manage the sequence itself. This is not the correct behavior for the user_id in this class.
51 So we override that incorrect behavior, and simply say there is no sequence key.
53 function sequenceKey()
55 return array(false,false);
58 function makeNew($user)
60 $login_token = Login_token::staticGet('user_id', $user->id);
62 if (!empty($login_token)) {
63 $login_token->delete();
66 $login_token = new Login_token();
68 $login_token->user_id = $user->id;
69 $login_token->token = common_good_rand(16);
70 $login_token->created = common_sql_now();
72 $result = $login_token->insert();
75 common_log_db_error($login_token, 'INSERT', __FILE__);
76 // TRANS: Exception thrown when trying creating a login token failed.
77 // TRANS: %s is the user nickname for which token creation failed.
78 throw new Exception(sprintf(_('Could not create login token for %s'),