JUserHelper::addUserToGroup and refresh without leaving the session

270 views
Skip to first unread message

Franz

unread,
Nov 22, 2012, 10:11:15 AM11/22/12
to joomla-de...@googlegroups.com
In a custom component I want to the change the current user group after a certain task. 

I use JUserHelper::addUserToGroup and everything is fine, except for the fact that the current user is not assigned new access levels until he/she logs out and in again.

Now I already did some research and this is what i found:

1. JUserHelper::addUserToGroup should already refresh the groups for the current user object:

...
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
...

2. I also followed this thread: 


that tells to recreate the session user object, but the proposed solution does not work for me.

Basically, if I print out _authGroups and _authLevels I can see that they are not changed. 

And I cannot see additional menu items according to the new access levels.



I would be extremely grateful to anyone who can shed some lights on this. 

Thank you very much for your time.

--
Franz

Joe Patterson

unread,
Nov 22, 2012, 10:46:03 AM11/22/12
to joomla-de...@googlegroups.com

Try here. I had similar issue.

https://groups.google.com/d/msg/joomla-dev-general/-/SXw4XwVr7kgJ

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/cUrIBdR1L1cJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Franz

unread,
Nov 22, 2012, 10:55:53 AM11/22/12
to joomla-de...@googlegroups.com


On Thursday, November 22, 2012 4:46:07 PM UTC+1, Joe028 wrote:

Try here. I had similar issue.

https://groups.google.com/d/msg/joomla-dev-general/-/SXw4XwVr7kgJ

Thank you Joe, but that's exactly the post I was referring to in my original post.

I applied same solution but it doesn't seem to work. 

I'll try again now just in case...

elin

unread,
Nov 22, 2012, 4:09:15 PM11/22/12
to joomla-de...@googlegroups.com
There has also been some extensive discussion here

I find the whole thing confusing because the comments clearly show an intent to allow an update but as is discussed in that thread, it's not clear what that means. It seems to only really be meaningful if the user is changing his or her own groups i.e. like organic groups.  But as mentioned in that thread there are problems like the fact that the same use may have multiple sessions.  I'm interested in Andrew's comment there that it may be more of an application/ com_users problem, but I'm not sure I buy it totally since com_users isn't really used here.  I did look a bit and it did make me wonder if we don't have a general problem with handling multiple sessions on some of the queries and updates  of the session table that happen with the onUserLogin event.  Which also makes me wonder if you could have a trigger that does some but not all of the things that happen onUserLogin and thus get the benefits of logging in i.e. updating the session data without actually doing so. 

I'm wondering what you mean in that other thread by saying you have written it to directly change the groups. Could you share some code?

Elin

elin

unread,
Nov 24, 2012, 3:07:17 AM11/24/12
to joomla-de...@googlegroups.com
I think the problem is that $user->id already exists so the factory is not creating a new JUser and hence not getting the new properties.  
In playing around with this, doing this seems to solve the problem.
https://github.com/elinw/joomla-cms/compare/changeuser  

You could try something along those lines i.e. use JAccess directly rather than going through $user.

Elin

Franz

unread,
Nov 24, 2012, 4:09:37 AM11/24/12
to joomla-de...@googlegroups.com
On Saturday, November 24, 2012 9:07:17 AM UTC+1, elin wrote:
I think the problem is that $user->id already exists so the factory is not creating a new JUser and hence not getting the new properties.  
In playing around with this, doing this seems to solve the problem.

Thank you Elin, I will try that soon and report back.

BTW i confirm the *previous* solution didn't work.

--
Franz
Reply all
Reply to author
Forward
0 new messages