Skip to content

Commit 8e47138

Browse files
authored
Merge branch 'codeigniter4:develop' into multilevel-permissions
2 parents cd5f021 + 2601a59 commit 8e47138

File tree

7 files changed

+35
-8
lines changed

7 files changed

+35
-8
lines changed

.github/workflows/no-merge-commits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ jobs:
1919
uses: actions/checkout@v4
2020

2121
- name: Run test
22-
uses: NexusPHP/no-merge-commits@v2.1.0
22+
uses: NexusPHP/no-merge-commits@v2.2.1
2323
with:
2424
token: ${{ secrets.GITHUB_TOKEN }}

docs/customization/user_provider.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,17 @@ class UserModel extends ShieldUserModel
5454
}
5555
}
5656
```
57+
58+
## Creating a Custom User Entity
59+
60+
Starting from v1.2.0, `UserModel` in Shield has the `createNewUser()` method to
61+
create a new User Entity.
62+
63+
```php
64+
$user = $userModel->createNewUser($data);
65+
```
66+
67+
It takes an optional user data array as the first argument, and passes it to the
68+
constructor of the `$returnType` class.
69+
70+
If your custom User entity cannot be instantiated in this way, override this method.

docs/references/authentication/hmac.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ permissions the token grants to the user. Scopes are provided when the token is
119119
cannot be modified afterword.
120120

121121
```php
122-
$token = $user->gererateHmacToken('Work Laptop', ['posts.manage', 'forums.manage']);
122+
$token = $user->generateHmacToken('Work Laptop', ['posts.manage', 'forums.manage']);
123123
```
124124

125125
By default, a user is granted a wildcard scope which provides access to all scopes. This is the
126126
same as:
127127

128128
```php
129-
$token = $user->gererateHmacToken('Work Laptop', ['*']);
129+
$token = $user->generateHmacToken('Work Laptop', ['*']);
130130
```
131131

132132
During authentication, the HMAC Keys the user used is stored on the user. Once authenticated, you

docs/user_management/forcing_password_reset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if ($user->requiresPasswordReset()) {
3838

3939
!!! note
4040

41-
You can use the [force-reset](../references/controller_filters/#forcing-password-reset)
41+
You can use the [force-reset](../references/controller_filters.md/#forcing-password-reset)
4242
filter to check.
4343

4444
### Force Password Reset On a User

src/Collectors/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function display(): string
8383

8484
$html = '<h3>Current User</h3>';
8585
$html .= '<table><tbody>';
86-
$html .= "<tr><td style='width:150px;'>User ID</td><td>#{$user->id}</td></tr>";
86+
$html .= "<tr><td width=\"150\">User ID</td><td>#{$user->id}</td></tr>";
8787
$html .= "<tr><td>Username</td><td>{$user->username}</td></tr>";
8888
$html .= "<tr><td>Email</td><td>{$user->email}</td></tr>";
8989
$html .= "<tr><td>Groups</td><td>{$groupsForUser}</td></tr>";

src/Controllers/RegisterController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ public function registerAction(): RedirectResponse
103103

104104
// Save the user
105105
$allowedPostFields = array_keys($rules);
106-
$user = $this->getUserEntity();
107-
$user->fill($this->request->getPost($allowedPostFields));
106+
$user = $users->createNewUser($this->request->getPost($allowedPostFields));
108107

109108
// Workaround for email only registration/login
110109
if ($user->username === null) {
@@ -160,10 +159,14 @@ protected function getUserProvider(): UserModel
160159

161160
/**
162161
* Returns the Entity class that should be used
162+
*
163+
* @deprecated 1.2.0 No longer used.
163164
*/
164165
protected function getUserEntity(): User
165166
{
166-
return new User();
167+
$userProvider = $this->getUserProvider();
168+
169+
return $userProvider->createNewUser();
167170
}
168171

169172
/**

src/Models/UserModel.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,14 @@ private function checkReturnType(): void
397397
throw new LogicException('Return type must be a subclass of ' . User::class);
398398
}
399399
}
400+
401+
/**
402+
* Returns a new User Entity.
403+
*
404+
* @param array<string, array<array-key, mixed>|bool|float|int|object|string|null> $data (Optional) user data
405+
*/
406+
public function createNewUser(array $data = []): User
407+
{
408+
return new $this->returnType($data);
409+
}
400410
}

0 commit comments

Comments
 (0)