-
OK , I figured out how to add new user with custom personalFields, that's working fine. Now I need to be able to edit the user, it all works, until i call $user->saveEmailIdentity(); It has PHP error, There is no data to update. All other fields are saving correctly except for EmailIdentiy (email password) What do you suggest? public function edit($id) {
$users = $this->getUserProvider();
$rules = $this->getValidationEditRules();
$validation = service('validation');
if (!$this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $validation->getErrors());
}
$allowedPostFields = array_merge(setting('Auth.validFields'), setting('Auth.personalFields'));
$user = $this->getUserProvider()->findById($id);
$user->fill($this->request->getPost($allowedPostFields));
// Workaround for email only registration/login
if ($user->username === null) {
$user->username = null;
}
if (! $users->save($user)) {
return redirect()->back()->withInput()->with('errors', $validation->getErrors());
}
// Store the email/password identity for this user.
$user->saveEmailIdentity();
// Success!
return redirect()->back()->withInput()->with('message', 'User successfully updated.');;
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Also how to update JUST email or JUST password and password_confirm |
Beta Was this translation helpful? Give feedback.
-
OK I did some more testing,
But how to update just email address ? or Just Password / confirm. This does not do anything:
But this (if the firstname is different than whats saved already ) does work:
|
Beta Was this translation helpful? Give feedback.
-
OK I figured it out, my pleasure It was this that helped;
I was skimming through the tests and found this; public function testUpdateEmail(): void
{
// Update user's email
$this->user->email = '[email protected]';
$this->user->active = 0;
$users = model(UserModel::class);
$users->save($this->user);
$user = $users->find($this->user->id);
$this->seeInDatabase('auth_identities', [
'user_id' => $user->id,
'secret' => '[email protected]',
]);
$this->assertSame('[email protected]', $user->email);
} |
Beta Was this translation helpful? Give feedback.
-
Also to update the password field, it seems you must set it explicitly; public function edit($id) {
$users = $this->getUserProvider();
$rules = $this->getValidationEditRules();
$validation = service('validation');
if (!$this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $validation->getErrors());
}
$allowedPostFields = array_merge(setting('Auth.validFields'), setting('Auth.personalFields'));
$user = $this->getUserProvider()->findById($id);
$user->fill($this->request->getPost($allowedPostFields));
if (!empty($this->request->getPost('password')))
$user->password = $this->request->getPost('password');
$user->active = 1;
if (! $users->save($user)) {
return redirect()->back()->withInput()->with('errors', $validation->getErrors());
}
// Success!
return redirect()->back()->withInput()->with('message', 'User successfully updated.');;
} |
Beta Was this translation helpful? Give feedback.
OK I figured it out, my pleasure
It was this that helped;
$user->active = 1;
I was skimming through the tests and found this;