Okay, so we are currently using joomla's user class to create new staff, In our staff page. It works well and successfully creates the new user account. But we have an issue, because the user account button at the top of screen also relies on calls to a joomla user object, once we create a new user the moment after creation the name displayed is that of the user we just created. Now once you refresh or move to another page the issue disappears.
If we wish to avoid the confusion this instance might cause, it might make sense to move the method we use to create new users out of the page and into a seperate file correct? Or would it not be worth it, given it has no other effects but a temporary name that is resolved without any real effort on the part of the user?
This is the code we use:
$udata = array(
"name"=>$_POST['firstName'].' '.$_POST['surName'],
"username"=>$_POST['username'],
"password"=>$_POST['password'],
"password2"=>$_POST['password'],
"email"=>$_POST['companyEmail'],
"block"=>0,
"groups"=>array("2","6")
);
$user = new JUser;
//Write to database
if(!$user->bind($udata)) {
echo "<script>alert('Could not bind data. Error: ".$user->getError()."</script>";
}
if (!$user->save()) {
echo "<script>alert('Could not save user. Error: " . $user->getError()."</script>";
} else {
echo "<script>alert('New User $user->id Created');</script>";
// Script Here to enter additional details in usg_usg_staff table
The code is located in the page usg-staff.php. or would it be wiser to remove the user->name call?
I finally resolved the issue. All I had to do was make sure that once the new user was created I set the $user variable back to the active user data by using JFactory::getUser(). I was really over thinking it. It was only displaying the just created user because after creating the user in our joomla table I had not thought to set it back.