Skip to content

Commit 5b4f165

Browse files
committed
docs: improve instructions
1 parent f9bf1cf commit 5b4f165

1 file changed

Lines changed: 43 additions & 17 deletions

File tree

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,61 @@
11
# Customizing Login Identifier
22

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:
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:
44

55
This only works with the Session authenticator.
66

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.
7+
## Create Migration File
98

10-
```php
11-
public array $validFields = [
12-
'employee_id'
13-
];
14-
```
9+
Create a [migration](http://codeigniter.com/user_guide/dbmgmt/migration.html) that
10+
adds a new column to the `users` table.
11+
12+
## Change $validFields
13+
14+
Edit `app/Config/Auth.php` so that the new column you just created is within the
15+
`$validFields` array.
16+
17+
```php
18+
public array $validFields = [
19+
'employee_id'
20+
];
21+
```
22+
23+
If you have multiple login forms on your site that use different credentials, you
24+
must have all of the valid identifying fields in the array.
1525

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.
26+
```php
27+
public array $validFields = [
28+
'email',
29+
'employee_id'
30+
];
31+
```
32+
33+
## Update Validation Rules
34+
35+
!!! warning
36+
37+
This is very important for security.
38+
39+
You must write new **Validation Rules** and then set them using the
40+
[Customizing Validation Rules](./validation_rules.md#login) description.
41+
42+
## Customize Login View
43+
44+
1. Change the `login` view file in the `app/Config/Auth.php` file.
1745

1846
```php
19-
public array $validFields = [
20-
'email',
21-
'employee_id'
47+
public array $views = [
48+
'login' => '\App\Views\Shield\login',
49+
// ...
2250
];
2351
```
24-
!!! warning
25-
26-
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 [Customizing Validation Rules](./validation_rules.md) description.
2752

28-
3. Edit the login form to change the name of the default `email` input to the new field name.
53+
2. Copy file `vendor\codeigniter4\shield\src\Views\login.php` to `app\Views\Shield\login.php`.
54+
3. Customize the login form to change the name of the default `email` input to the new field name.
2955

3056
```php
3157
<!-- Email -->
3258
<div class="mb-2">
33-
<input type="text" class="form-control" name="employee_id" autocomplete="new-employee-id" placeholder="12345" value="<?= old('employee_id') ?>" required />
59+
<input type="text" class="form-control" name="employee_id" autocomplete="new-employee-id" placeholder="12345" value="<?= old('employee_id') ?>" required>
3460
</div>
3561
```

0 commit comments

Comments
 (0)