Created
August 26, 2009 20:20
-
-
Save biakaveron/175800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/classes/kohana/auth/orm.php b/classes/kohana/auth/orm.php | |
index dfca403..ed3a78c 100644 | |
--- a/classes/kohana/auth/orm.php | |
+++ b/classes/kohana/auth/orm.php | |
@@ -143,11 +143,11 @@ class Kohana_Auth_ORM extends Auth { | |
if ($token = cookie::get('authautologin')) | |
{ | |
// Load the token and user | |
- $token = ORM::factory('user_token', $token); | |
+ $token = ORM::factory('user_token', array('token' => $token)); | |
if ($token->loaded() AND $token->user->loaded()) | |
{ | |
- if ($token->user_agent === sha1(Kohana::$user_agent)) | |
+ if ($token->user_agent === sha1(Request::$user_agent)) | |
{ | |
// Save the token to create a new unique token | |
$token->save(); | |
@@ -187,11 +187,11 @@ class Kohana_Auth_ORM extends Auth { | |
// Clear the autologin token from the database | |
$token = ORM::factory('user_token', $token); | |
- if ($token->loaded AND $logout_all) | |
+ if ($token->loaded() AND $logout_all) | |
{ | |
ORM::factory('user_token')->where('user_id', $token->user_id)->delete_all(); | |
} | |
- elseif ($token->loaded) | |
+ elseif ($token->loaded()) | |
{ | |
$token->delete(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/classes/model/auth/user/token.php b/classes/model/auth/user/token.php | |
index c6543bb..e3730d6 100644 | |
--- a/classes/model/auth/user/token.php | |
+++ b/classes/model/auth/user/token.php | |
@@ -3,10 +3,10 @@ | |
class Model_Auth_User_Token extends ORM { | |
// Relationships | |
- protected $belongs_to = array('user'); | |
+ protected $_belongs_to = array('user' => array()); | |
// Current timestamp | |
- protected $now; | |
+ protected $_now; | |
/** | |
* Handles garbage collection and deleting of expired objects. | |
@@ -16,7 +16,7 @@ class Model_Auth_User_Token extends ORM { | |
parent::__construct($id); | |
// Set the now, we use this a lot | |
- $this->now = time(); | |
+ $this->_now = time(); | |
if (mt_rand(1, 100) === 1) | |
{ | |
@@ -24,7 +24,7 @@ class Model_Auth_User_Token extends ORM { | |
$this->delete_expired(); | |
} | |
- if ($this->expires < $this->now) | |
+ if ($this->expires < $this->_now) | |
{ | |
// This object has expired | |
$this->delete(); | |
@@ -37,11 +37,11 @@ class Model_Auth_User_Token extends ORM { | |
*/ | |
public function save() | |
{ | |
- if ($this->loaded === FALSE) | |
+ if ($this->loaded() === FALSE) | |
{ | |
// Set the created time, token, and hash of the user agent | |
- $this->created = $this->now; | |
- $this->user_agent = sha1(Kohana::$user_agent); | |
+ $this->created = $this->_now; | |
+ $this->user_agent = sha1(Request::$user_agent); | |
} | |
// Create a new token each time the token is saved | |
@@ -58,7 +58,9 @@ class Model_Auth_User_Token extends ORM { | |
public function delete_expired() | |
{ | |
// Delete all expired tokens | |
- $this->db->where('expires <', $this->now)->delete($this->table_name); | |
+ DB::delete($this->_table_name) | |
+ ->where('expires', '<', $this->_now) | |
+ ->execute($this->_db); | |
return $this; | |
} | |
@@ -78,7 +80,11 @@ class Model_Auth_User_Token extends ORM { | |
$token = text::random('alnum', 32); | |
// Make sure the token does not already exist | |
- if ($this->db->select('id')->where('token', $token)->get($this->table_name)->count() === 0) | |
+ if (DB::select('id') | |
+ ->where('token','=', $token) | |
+ ->from($this->_table_name) | |
+ ->execute($this->_db) | |
+ ->count() === 0) | |
{ | |
// A unique token has been found | |
return $token; | |
@@ -86,17 +92,4 @@ class Model_Auth_User_Token extends ORM { | |
} | |
} | |
- /** | |
- * Allows loading by token string. | |
- */ | |
- public function unique_key($id) | |
- { | |
- if ( ! empty($id) AND is_string($id) AND ! ctype_digit($id)) | |
- { | |
- return 'token'; | |
- } | |
- | |
- return parent::unique_key($id); | |
- } | |
- | |
} // End Auth User Token Model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment