From 9dd964c3169f58417c4ecd31e993854c5758dccb Mon Sep 17 00:00:00 2001 From: Jeffrey Way Date: Mon, 9 Jul 2012 21:34:17 -0400 Subject: [PATCH 1/3] Extend Auth::laravel to accept multiple params to verify Signed-off-by: Jeffrey Way --- laravel/auth/drivers/eloquent.php | 30 ++++++++++++++++++------------ laravel/auth/drivers/fluent.php | 22 ++++++++++++++-------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/laravel/auth/drivers/eloquent.php b/laravel/auth/drivers/eloquent.php index 8c1c6a80..26e143b9 100644 --- a/laravel/auth/drivers/eloquent.php +++ b/laravel/auth/drivers/eloquent.php @@ -26,21 +26,27 @@ public function retrieve($id) */ 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 @@ protected function model() return new $model; } -} \ No newline at end of file +} diff --git a/laravel/auth/drivers/fluent.php b/laravel/auth/drivers/fluent.php index 4c23468b..e5aaa506 100644 --- a/laravel/auth/drivers/fluent.php +++ b/laravel/auth/drivers/fluent.php @@ -30,10 +30,9 @@ public function retrieve($id) */ 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 @@ public function attempt($arguments = array()) } /** - * 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(); } } From ff525b995b21998aeba4d87ff97a54b0cb6c6df3 Mon Sep 17 00:00:00 2001 From: Jeffrey Way Date: Mon, 9 Jul 2012 22:18:32 -0400 Subject: [PATCH 2/3] Add "remember" to ignore list Signed-off-by: Jeffrey Way --- laravel/auth/drivers/eloquent.php | 23 ++++++++++++----------- laravel/auth/drivers/fluent.php | 5 +++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/laravel/auth/drivers/eloquent.php b/laravel/auth/drivers/eloquent.php index 26e143b9..4b365d1e 100644 --- a/laravel/auth/drivers/eloquent.php +++ b/laravel/auth/drivers/eloquent.php @@ -26,27 +26,28 @@ public function retrieve($id) */ public function attempt($arguments = array()) { - $user = $this->model()->where(function($query) use($arguments) { + $user = $this->model()->where(function($query) use($arguments) + { $username = Config::get('auth.username'); $query->where($username, '=', $arguments['username']); - foreach( array_except($arguments, array('username', 'password')) as $column => $val ) + foreach(array_except($arguments, array('username', 'password', 'remember')) as $column => $val) { $query->where($column, '=', $val); } - })->first(); + })->first(); - // 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; } diff --git a/laravel/auth/drivers/fluent.php b/laravel/auth/drivers/fluent.php index e5aaa506..ed660881 100644 --- a/laravel/auth/drivers/fluent.php +++ b/laravel/auth/drivers/fluent.php @@ -56,12 +56,13 @@ protected function get_user($arguments) { $table = Config::get('auth.table'); - return DB::table($table)->where(function($query) use($arguments) { + return DB::table($table)->where(function($query) use($arguments) + { $username = Config::get('auth.username'); $query->where($username, '=', $arguments['username']); - foreach( array_except($arguments, array('username', 'password')) as $column => $val ) + foreach(array_except($arguments, array('username', 'password', 'remember')) as $column => $val) { $query->where($column, '=', $val); } From c659a926034da8e724e2766b90aef48c8fbb3018 Mon Sep 17 00:00:00 2001 From: Jeffrey Way Date: Tue, 10 Jul 2012 11:03:55 -0400 Subject: [PATCH 3/3] Fix typo in comments --- laravel/auth/drivers/eloquent.php | 2 +- laravel/auth/drivers/fluent.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/laravel/auth/drivers/eloquent.php b/laravel/auth/drivers/eloquent.php index 4b365d1e..aaea515b 100644 --- a/laravel/auth/drivers/eloquent.php +++ b/laravel/auth/drivers/eloquent.php @@ -21,7 +21,7 @@ public function retrieve($id) /** * Attempt to log a user into the application. * - * @param array $arguments + * @param array $arguments * @return void */ public function attempt($arguments = array()) diff --git a/laravel/auth/drivers/fluent.php b/laravel/auth/drivers/fluent.php index ed660881..f8654e9a 100644 --- a/laravel/auth/drivers/fluent.php +++ b/laravel/auth/drivers/fluent.php @@ -25,7 +25,7 @@ public function retrieve($id) /** * Attempt to log a user into the application. * - * @param array $arguments + * @param array $arguments * @return void */ public function attempt($arguments = array()) @@ -49,7 +49,7 @@ public function attempt($arguments = array()) /** * Get the user from the database table. * - * @param mixed $array + * @param array $arguments * @return mixed */ protected function get_user($arguments)