Skip to content

Commit 343cfc1

Browse files
committed
docs: update Registration Validation Rules
1 parent 1bdd37c commit 343cfc1

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

docs/customization.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,40 @@ Shield has the following rules for registration:
149149
```php
150150
[
151151
'username' => [
152-
'label' => 'Auth.username',
153-
'rules' => 'required|max_length[30]|min_length[3]|regex_match[/\A[a-zA-Z0-9\.]+\z/]|is_unique[' . SHIELD_TABLES['users'] . '.username]',
152+
'label' => 'Auth.username',
153+
'rules' => [
154+
'required',
155+
'max_length[30]',
156+
'min_length[3]',
157+
'regex_match[/\A[a-zA-Z0-9\.]+\z/]',
158+
'is_unique[users.username]',
159+
],
154160
],
155161
'email' => [
156-
'label' => 'Auth.email',
157-
'rules' => 'required|max_length[254]|valid_email|is_unique[' . SHIELD_TABLES['identities'] . '.secret]',
162+
'label' => 'Auth.email',
163+
'rules' => [
164+
'required',
165+
'max_length[254]',
166+
'valid_email',
167+
'is_unique[auth_identities.secret]',
168+
],
158169
],
159170
'password' => [
160-
'label' => 'Auth.password',
171+
'label' => 'Auth.password',
161172
'rules' => 'required|strong_password',
162173
],
163174
'password_confirm' => [
164-
'label' => 'Auth.passwordConfirm',
175+
'label' => 'Auth.passwordConfirm',
165176
'rules' => 'required|matches[password]',
166177
],
167178
];
168179
```
169180

181+
> **Note** If you customize the table names, the table names
182+
> (`users` and `auth_identities`) in the above rules will be automatically
183+
> changed. The rules are implemented in
184+
> `RegisterController::getValidationRules()`.
185+
170186
If you need a different set of rules for registration, you can specify them in your `Validation` configuration (**app/Config/Validation.php**) like:
171187

172188
```php
@@ -175,24 +191,38 @@ If you need a different set of rules for registration, you can specify them in y
175191
//--------------------------------------------------------------------
176192
public $registration = [
177193
'username' => [
178-
'label' => 'Auth.username',
179-
'rules' => 'required|max_length[30]|min_length[3]|regex_match[/\A[a-zA-Z0-9\.]+\z/]|is_unique[' . SHIELD_TABLES['users'] . '.username]',
194+
'label' => 'Auth.username',
195+
'rules' => [
196+
'required',
197+
'max_length[30]',
198+
'min_length[3]',
199+
'regex_match[/\A[a-zA-Z0-9\.]+\z/]',
200+
'is_unique[users.username]',
201+
],
180202
],
181203
'email' => [
182-
'label' => 'Auth.email',
183-
'rules' => 'required|max_length[254]|valid_email|is_unique[' . SHIELD_TABLES['identities'] . '.secret]',
204+
'label' => 'Auth.email',
205+
'rules' => [
206+
'required',
207+
'max_length[254]',
208+
'valid_email',
209+
'is_unique[auth_identities.secret]',
210+
],
184211
],
185212
'password' => [
186-
'label' => 'Auth.password',
213+
'label' => 'Auth.password',
187214
'rules' => 'required|strong_password',
188215
],
189216
'password_confirm' => [
190-
'label' => 'Auth.passwordConfirm',
217+
'label' => 'Auth.passwordConfirm',
191218
'rules' => 'required|matches[password]',
192219
],
193220
];
194221
```
195222

223+
> **Note** If you customize the table names, set the correct table names in the
224+
> rules.
225+
196226
### Login
197227

198228
Similar to the process for validation rules in the **Registration** section, you can add rules for the login form to **app/Config/Validation.php** and change the rules.

0 commit comments

Comments
 (0)