Browse Source

added eloquent model detection to eloquent auth driver

Shawn McCool 12 years ago
parent
commit
11c67a56cc
2 changed files with 24 additions and 5 deletions
  1. 0 4
      laravel/auth/drivers/driver.php
  2. 24 1
      laravel/auth/drivers/eloquent.php

+ 0 - 4
laravel/auth/drivers/driver.php

@@ -107,10 +107,6 @@ abstract class Driver {
 	 */
 	 */
 	public function login($token, $remember = false)
 	public function login($token, $remember = false)
 	{
 	{
-		// if the token is an Eloquent model
-		// set the token from the id field
-		if ($token instanceof Eloquent) $token = $token->get_key();
-
 		$this->token = $token;
 		$this->token = $token;
 
 
 		$this->store($token);
 		$this->store($token);

+ 24 - 1
laravel/auth/drivers/eloquent.php

@@ -15,7 +15,30 @@ class Eloquent extends Driver {
 		if (filter_var($id, FILTER_VALIDATE_INT) !== false)
 		if (filter_var($id, FILTER_VALIDATE_INT) !== false)
 		{
 		{
 			return $this->model()->find($id);
 			return $this->model()->find($id);
-		} 
+		}
+	}
+
+	/**
+	 * Login the user assigned to the given token.
+	 *
+	 * The token is typically a numeric ID for the user.
+	 *
+	 * @param  mixed   $token
+	 * @param  bool    $remember
+	 * @return bool
+	 */
+	public function login($token, $remember = false)
+	{
+		// if the token is an Eloquent model get the primary key
+		if ($token instanceof \Eloquent) $token = $token->get_key();
+
+		$this->token = $token;
+
+		$this->store($token);
+
+		if ($remember) $this->remember($token);
+
+		return true;
 	}
 	}
 
 
 	/**
 	/**