Skip to content

Commit 4db3730

Browse files
committed
docs: split customization.md
1 parent 0c60b99 commit 4db3730

10 files changed

Lines changed: 311 additions & 313 deletions

docs/customization.md

Lines changed: 0 additions & 312 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Extending the Controllers
2+
3+
Shield has the following controllers that can be extended to handle
4+
various parts of the authentication process:
5+
6+
- **ActionController** handles the after-login and after-registration actions, like Two Factor Authentication and Email Verification.
7+
- **LoginController** handles the login process.
8+
- **RegisterController** handles the registration process. Overriding this class allows you to customize the User Provider, the User Entity, and the validation rules.
9+
- **MagicLinkController** handles the "lost password" process that allows a user to login with a link sent to their email. This allows you to
10+
override the message that is displayed to a user to describe what is happening, if you'd like to provide more information than simply swapping out the view used.
11+
12+
It is not recommended to copy the entire controller into **app/Controllers** and change its namespace. Instead, you should create a new controller that extends
13+
the existing controller and then only override the methods needed. This allows the other methods to stay up to date with any security
14+
updates that might happen in the controllers.
15+
16+
```php
17+
<?php
18+
19+
namespace App\Controllers;
20+
21+
use CodeIgniter\Shield\Controllers\LoginController as ShieldLogin;
22+
use CodeIgniter\HTTP\RedirectResponse;
23+
24+
class LoginController extends ShieldLogin
25+
{
26+
public function logoutAction(): RedirectResponse
27+
{
28+
// new functionality
29+
}
30+
}
31+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Integrating Custom View Libraries
2+
3+
If your application uses a different method to convert view files to HTML than CodeIgniter's built-in `view()` helper you can easily integrate your system anywhere that a view is rendered within Shield. All controllers and actions use the `CodeIgniter\Shield\Traits\Viewable` trait which provides a simple `view()` method that takes the same arguments as the `view()` helper. This allows you to extend the Action or Controller and only change the single method of rendering the view, leaving all of the logic untouched so your app will not need to maintain Shield logic when it doesn't need to change it.
4+
5+
```php
6+
use Acme\Themes\Traits\Themeable;
7+
use CodeIgniter\Shield\Controllers\LoginController;
8+
9+
class MyLoginController extends LoginController
10+
{
11+
use Themable;
12+
13+
protected function view(string $view, array $data = [], array $options = []): string
14+
{
15+
return $this->themedView($view, $data, $options);
16+
}
17+
}
18+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Customizing Login Identifier
2+
3+
If your application has a need to use something other than `email` or `username`, you may specify any valid column within the `users` table that you may have added. This allows you to easily use phone numbers, employee or school IDs, etc as the user identifier. You must implement the following steps to set this up:
4+
5+
This only works with the Session authenticator.
6+
7+
1. Create a [migration](http://codeigniter.com/user_guide/dbmgmt/migration.html) that adds a new column to the `users` table.
8+
2. Edit `app/Config/Auth.php` so that the new column you just created is within the `$validFields` array.
9+
10+
```php
11+
public array $validFields = [
12+
'employee_id'
13+
];
14+
```
15+
16+
If you have multiple login forms on your site that use different credentials, you must have all of the valid identifying fields in the array.
17+
18+
```php
19+
public array $validFields = [
20+
'email',
21+
'employee_id'
22+
];
23+
```
24+
> **Warning**
25+
> It is very important for security that if you add a new column for identifier you must write a new **Validation Rules** and then set it using the [custom-validation-rules](https://github.com/codeigniter4/shield/blob/develop/docs/customization.md#custom-validation-rules) description.
26+
27+
3. Edit the login form to change the name of the default `email` input to the new field name.
28+
29+
```php
30+
<!-- Email -->
31+
<div class="mb-2">
32+
<input type="text" class="form-control" name="employee_id" autocomplete="new-employee-id" placeholder="12345" value="<?= old('employee_id') ?>" required />
33+
</div>
34+
```

0 commit comments

Comments
 (0)