浏览代码

Docs for MultiColumn

dereuromark 8 年之前
父节点
当前提交
4682879edc
共有 4 个文件被更改,包括 46 次插入3 次删除
  1. 1 0
      README.md
  2. 41 0
      docs/Auth/MultiColumn.md
  3. 3 0
      docs/README.md
  4. 1 3
      src/Auth/MultiColumnAuthenticate.php

+ 1 - 0
README.md

@@ -26,6 +26,7 @@ This master branch only works for **CakePHP3.x** - please use the 2.x branch for
  
 ### Additional features
 - Passwordable behavior allows easy to use password functionality for frontend and backend.
+- MultiColumnAuthenticate for log-in with e.g. "email or username".
 - Slugged, Reset and other behaviors
 - Text, Time, Number libs and helpers etc provide extended functionality if desired.
 - QrCode, Gravatar and other useful small helpers

+ 41 - 0
docs/Auth/MultiColumn.md

@@ -0,0 +1,41 @@
+# MultiColumnAuthenticate
+
+By default the FormAuthenticate class only allows a single field to be used.
+But often times you want to provide a login input field as combined one, so the user can log in with either email or username.
+
+For this make sure your login form contains:
+```php
+echo $this->Form->input('login');
+echo $this->Form->input('password', ['autocomplete' => 'off']);
+```
+
+Then set up the Auth component:
+```php
+    //in $components
+    public $components = [
+        'Auth' => [
+            'authenticate' => [
+                'Tools.MultiColumn' => [
+                    'fields' => [
+                        'username' => 'login',
+                        'password' => 'password'
+                    ],
+                    'columns' => ['username', 'email'],
+                ]
+            ]
+        ]
+    ];
+
+    // Or in beforeFilter()
+    $this->Auth->config('authenticate', [
+        'Tools.MultiColumn' => [
+            'fields' => [
+                'username' => 'login',
+                'password' => 'password'
+            ],
+            'columns' => ['username', 'email'],
+        ]
+    ]);
+```
+
+Of course you can still combine it with custom finders to add a scope or contain relations just as the core Form one.

+ 3 - 0
docs/README.md

@@ -19,6 +19,9 @@ I18n:
 ErrorHandler
 * [ErrorHandler](Error/ErrorHandler.md)
 
+Auth
+* [MultiColumnAuthenticate](Auth/MultiColumn) for log-in with e.g. "email or username"
+
 Testing
 * [Testing](TestSuite/Testing.md)
 

+ 1 - 3
src/Auth/MultiColumnAuthenticate.php

@@ -15,12 +15,10 @@ use Cake\ORM\TableRegistry;
  *    $this->Auth->config('authenticate', [
  *        'Tools.MultiColumn' => [
  *            'fields' => [
- *                'username' => 'username',
+ *                'username' => 'login',
  *                'password' => 'password'
  *             ],
  *            'columns' => ['username', 'email'],
- *            'userModel' => 'Users',
- *            'scope' => ['User.active' => 1]
  *        ]
  *    ]);
  * ```