Edit Profile

bcouvin 08 Feb, 2016
Hello,

I made a registration via CFv5. Everything is OK.
I made also the form for users to make themselve some changes, like chaning the mail address, the password etc...

What I did for this form in a setup tab is a DB Read with a condition to get the current user:

<?php
$user = JFactory::getUser();
return array("user_id" => $user->get("id"));
?>


and in a submit action, before a DBsave, I have a custom code and alse Joomla registration component:

<?php

$form->data['Name'] = "{$form->data['FirstName']} {$form->data['LastName']}";
$form->data['_PLUGINS_']['joomla_registration']['name']=$form->data['Name'];
$form->data['_PLUGINS_']['joomla_registration']['username']=$form->data['Username'];
$form->data['_PLUGINS_']['joomla_registration']['email']=$form->data['Email'];
$form->data['_PLUGINS_']['joomla_registration']['password']=$form->data['Password'];

?>



When I try to change in front end email address and password, I got the message:

Couldn't save new user, Joomla returned this error : Username in use.


What could I do to make this change also in joomla #__users table?

Thanks in advance for your help
Bertrand
GreyHead 08 Feb, 2016
1 Likes
Hi Bertrand,

By far the best way is to use the Joomla! JUser methods in a Custom Code action. The basics are here the Helper methods to encrypt a password, etc. are here and the main docs here

Bob
bcouvin 08 Feb, 2016
Hi Bob,

Thank you for your help.

I wrote a custom code to change values in #__users table. All values could be changed.
I could not login with the new password. I must miss something that I did not masterize.

Here is the code.

<?php

$user = JFactory::getUser(); 
$data = array(); 

$data['name'] = $form->data['FirstName'].' '.$form->data['LastName'];
$data['username'] = $form->data['Username'];
$data['email'] = $form->data['Email'];

$password = JUserHelper::hashPassword($form->data['Password']);

$data['password']  = $password;
$data['password2'] = $password;
$data['sendEmail'] = 1; // user receive system mails

$user->bind($data);
$user->save();

?>


Is there something I omitted? Even with the previous method,


$salt = JUserHelper::genRandomPassword(32);
$crypt_password = JUserHelper::getCryptedPassword($form->data['Password'], $salt);

$data['password'] = $crypt_password.':'.$salt;
.....


Thanks
Bertrand
bcouvin 08 Feb, 2016
Answer
Hello Bob,

I found the solution.

Thank you very much.

Bertrand
This topic is locked and no more replies can be posted.