summaryrefslogtreecommitdiff
path: root/classes/Login_token.php
diff options
context:
space:
mode:
authorroot <root@ip-10-250-162-129.ec2.internal>2010-01-09 23:38:51 +0000
committerroot <root@ip-10-250-162-129.ec2.internal>2010-01-09 23:38:51 +0000
commit1b9fd1fe5311b3af9e22e64fac37e5b9fe93c4a3 (patch)
tree7ad837785d6c6ea5156092543857df6447812a58 /classes/Login_token.php
parentd59df6b27013fb534d6444d8e4790f2edcd9459a (diff)
parented5828f30ea0f7a30e01d407058990b06164c6f3 (diff)
Merge branch 'redironlogin' of http://git.gitorious.org/~evan/statusnet/evans-mainline into redironlogin
Diffstat (limited to 'classes/Login_token.php')
-rw-r--r--classes/Login_token.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/classes/Login_token.php b/classes/Login_token.php
index 746cd7f22..51dc61262 100644
--- a/classes/Login_token.php
+++ b/classes/Login_token.php
@@ -40,6 +40,8 @@ class Login_token extends Memcached_DataObject
/* 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,29 @@ 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__);
+ throw new Exception(sprintf(_('Could not create login token for %s'),
+ $user->nickname));
+ }
+
+ return $login_token;
+ }
}