Browse Source

Extend Auth::laravel to accept multiple params to verify

Signed-off-by: Jeffrey Way <jeffrey@envato.com>
Jeffrey Way 12 years ago
parent
commit
9dd964c316
2 changed files with 32 additions and 20 deletions
  1. 18 12
      laravel/auth/drivers/eloquent.php
  2. 14 8
      laravel/auth/drivers/fluent.php

+ 18 - 12
laravel/auth/drivers/eloquent.php

@@ -26,21 +26,27 @@ class Eloquent extends Driver {
 	 */
 	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')) 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
-		// log the user into the application and remember them if asked.
-		$password = $arguments['password'];
+			// 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'];
 
-		$password_field = Config::get('auth.password', 'password');
+			$password_field = Config::get('auth.password', 'password');
 
-		if ( ! is_null($user) and Hash::check($password, $user->get_attribute($password_field)))
-		{
-			return $this->login($user->id, array_get($arguments, 'remember'));
-		}
+			if ( ! is_null($user) and Hash::check($password, $user->get_attribute($password_field)))
+			{
+				return $this->login($user->id, array_get($arguments, 'remember'));
+			}
 
 		return false;
 	}
@@ -57,4 +63,4 @@ class Eloquent extends Driver {
 		return new $model;
 	}
 
-}
+}

+ 14 - 8
laravel/auth/drivers/fluent.php

@@ -30,10 +30,9 @@ class Fluent extends Driver {
 	 */
 	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,25 @@ class Fluent extends Driver {
 	}
 
 	/**
-	 * Get the user from the database table by username.
+	 * Get the user from the database table.
 	 *
-	 * @param  mixed  $value
+	 * @param  mixed  $array
 	 * @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')) as $column => $val )
+			{
+			    $query->where($column, '=', $val);
+			}
+		})->first();
 	}
 
 }