-
Notifications
You must be signed in to change notification settings - Fork 139
fix: UserModel::save() can't update User's email/password #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2c9367b
docs: fix doc comment
kenjis 0f029f6
fix: UserModel::save() can't update User's email/password
kenjis 510f4fb
fix: registerAction() so that it does not insert the identity twice
kenjis d72ac0a
docs: update the docs
kenjis 2c01462
fix: add missing syncOriginal()
kenjis 7b0145d
fix: can't update User's email/password
kenjis c657cae
fix: add missing `throw $e`
kenjis 45cd4c4
refactor: change UserModel::save() to saveWithEmailIdentity()
kenjis a3f7e10
refactor: remove unnecessary if condition
kenjis e9604a9
fix: add missing checkQueryReturn()
kenjis 95953f4
refactor: add ValidationException and use it
kenjis f17355e
fix: catch ValidationException
kenjis 9487136
feat: UserModel::save() can save Email Identity again
kenjis 51bb61b
feat: insert(), update(), save() can save Email Identity with Model E…
kenjis af13b4c
docs: update about UserModel::insert() and update()
kenjis 8868006
feat: when you pass an array user data to insert()/update(), Model ev…
kenjis 1ecdbdd
fix: reset $this->tempUser after save Email Identity
kenjis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,21 +265,20 @@ Since Shield uses a more complex user setup than many other systems, due to the | |
|
||
### Creating Users | ||
|
||
By default, the only values stored in a user is the username. The first step is to create the user record with the username. If you don't have a username, be sure to set the value to `null` anyway, so that it passes CodeIgniter's empty data check. | ||
By default, the only values stored in the users table is the username. The first step is to create the user record with the username. If you don't have a username, be sure to set the value to `null` anyway, so that it passes CodeIgniter's empty data check. | ||
|
||
```php | ||
$users = model('UserModel'); | ||
$user = new User([ | ||
'username' => 'foo-bar' | ||
'username' => 'foo-bar', | ||
'email' => '[email protected]', | ||
'password' => 'secret plain text password', | ||
]); | ||
$users->save($user); | ||
|
||
// Get the updated user so we have the ID... | ||
// To get the complete user object with ID, we need to get from the database | ||
$user = $users->findById($users->getInsertID()); | ||
|
||
// Store the email/password identity for this user. | ||
$user->createEmailIdentity($this->request->getPost(['email', 'password'])); | ||
|
||
// Add to default group | ||
$users->addToDefaultGroup($user); | ||
``` | ||
|
@@ -297,7 +296,7 @@ NOTE: The User rows use [soft deletes](https://codeigniter.com/user_guide/models | |
|
||
### Editing A User | ||
|
||
The `UserModel::save()` method has been modified to ensure that an email or password previously set on the `User` entity will be automatically updated in the correct `UserIdentity` record. | ||
The `UserModel::save()`, `update()` and `insert()` methods have been modified to ensure that an email or password previously set on the `User` entity will be automatically updated in the correct `UserIdentity` record. | ||
|
||
```php | ||
$users = model('UserModel'); | ||
|
@@ -310,21 +309,3 @@ $user->fill([ | |
]); | ||
$users->save($user); | ||
``` | ||
|
||
If you prefer to use the `update()` method then you will have to update the user's appropriate UserIdentity manually. | ||
|
||
```php | ||
$users = model('UserModel'); | ||
$user = $users->findById(123); | ||
|
||
$user->fill([ | ||
'username' => 'JoeSmith111', | ||
'email' => '[email protected]', | ||
'password' => 'secret123' | ||
]); | ||
|
||
// Saves the username field | ||
$users->update($user); | ||
// Updates the email and password | ||
$user->saveEmailIdentity(); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace CodeIgniter\Shield\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
class ValidationException extends RuntimeException | ||
{ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.