Browse Source

Allow passing custom finder options to AuthComponent config.

Closes #8295
ADmad 10 years ago
parent
commit
5f2f98f7e5

+ 7 - 1
src/Auth/BaseAuthenticate.php

@@ -144,7 +144,13 @@ abstract class BaseAuthenticate implements EventListenerInterface
             $options['contain'] = $config['contain'];
         }
 
-        $query = $table->find($config['finder'], $options);
+        $finder = $config['finder'];
+        if (is_array($finder)) {
+            $options += current($finder);
+            $finder = key($finder);
+        }
+
+        $query = $table->find($finder, $options);
 
         return $query;
     }

+ 12 - 0
tests/TestCase/Auth/FormAuthenticateTest.php

@@ -307,6 +307,18 @@ class FormAuthenticateTest extends TestCase
             'username' => 'mariano',
         ];
         $this->assertEquals($expected, $result, 'Result should not contain "created" and "modified" fields');
+
+        $this->auth->config([
+            'finder' => ['auth' => ['return_created' => true]]
+        ]);
+
+        $result = $this->auth->authenticate($request, $this->response);
+        $expected = [
+            'id' => 1,
+            'username' => 'mariano',
+            'created' => new Time('2007-03-17 01:16:23'),
+        ];
+        $this->assertEquals($expected, $result);
     }
 
     /**

+ 3 - 0
tests/test_app/TestApp/Model/Table/AuthUsersTable.php

@@ -32,6 +32,9 @@ class AuthUsersTable extends Table
     public function findAuth(Query $query, array $options)
     {
         $query->select(['id', 'username', 'password']);
+        if (!empty($options['return_created'])) {
+            $query->select(['created']);
+        }
 
         return $query;
     }