Browse Source

Merge pull request #932 from JeffreyWay/feature/auth_attempt_extend

Extend Auth::Attempt()
Taylor Otwell 12 years ago
parent
commit
c937f98b49
2 changed files with 29 additions and 15 deletions
  1. 13 6
      laravel/auth/drivers/eloquent.php
  2. 16 9
      laravel/auth/drivers/fluent.php

+ 13 - 6
laravel/auth/drivers/eloquent.php

@@ -21,17 +21,24 @@ class Eloquent extends Driver {
 	/**
 	 * Attempt to log a user into the application.
 	 *
-	 * @param  array  $arguments
+	 * @param  array $arguments
 	 * @return void
 	 */
 	public function attempt($arguments = array())
 	{
-		$username = Config::get('auth.username');
+		$user = $this->model()->where(function($query) use($arguments)
+		{
+			$username = Config::get('auth.username');
+			
+			$query->where($username, '=', $arguments['username']);
 
-		$user = $this->model()->where($username, '=', $arguments['username'])->first();
+			foreach(array_except($arguments, array('username', 'password', 'remember')) as $column => $val)
+			{
+			    $query->where($column, '=', $val);
+			}
+		})->first();
 
-		// This driver uses a basic username and password authentication scheme
-		// so if the credentials match what is in the database we will just
+		// If the credentials match what is in the database we will just
 		// log the user into the application and remember them if asked.
 		$password = $arguments['password'];
 
@@ -57,4 +64,4 @@ class Eloquent extends Driver {
 		return new $model;
 	}
 
-}
+}

+ 16 - 9
laravel/auth/drivers/fluent.php

@@ -25,15 +25,14 @@ class Fluent extends Driver {
 	/**
 	 * Attempt to log a user into the application.
 	 *
-	 * @param  array  $arguments
+	 * @param  array $arguments
 	 * @return void
 	 */
 	public function attempt($arguments = array())
 	{
-		$user = $this->get_user($arguments['username']);
+		$user = $this->get_user($arguments);
 
-		// This driver uses a basic username and password authentication scheme
-		// so if the credentials match what is in the database we will just
+		// If the credentials match what is in the database we will just
 		// log the user into the application and remember them if asked.
 		$password = $arguments['password'];
 
@@ -48,18 +47,26 @@ class Fluent extends Driver {
 	}
 
 	/**
-	 * Get the user from the database table by username.
+	 * Get the user from the database table.
 	 *
-	 * @param  mixed  $value
+	 * @param  array  $arguments
 	 * @return mixed
 	 */
-	protected function get_user($value)
+	protected function get_user($arguments)
 	{
 		$table = Config::get('auth.table');
 
-		$username = Config::get('auth.username');
+		return DB::table($table)->where(function($query) use($arguments)
+		{
+			$username = Config::get('auth.username');
+			
+			$query->where($username, '=', $arguments['username']);
 
-		return DB::table($table)->where($username, '=', $value)->first();
+			foreach(array_except($arguments, array('username', 'password', 'remember')) as $column => $val)
+			{
+			    $query->where($column, '=', $val);
+			}
+		})->first();
 	}
 
 }