Wednesday, January 9, 2008

Plone - redirecting authenticated users to member folder after login

Another in the useful-hack-department

Task :

After login you want authenticated users to be directed straight to their folders. Normally, after login, the users are redirected to the where ever they wanted to go in the first place.

Solution :

The file that controls what happens after a user logs in is the file CMFPlone/skins/plone_login/login_next.cpy. So customize this file and edit it.

Basically what is happening here is, login_next.cpy will look for a variable called came_from. If the came_from variable is set, then it will redirect the user to whatever came_from is set as. At this point I knew what I had to do, the challenge was to find the right methods to achieve what I want. I needed the method to tell me what is the authenticated user's home folder. After some digging around I found it.

Just add this line to the login_next.cpy, somewhere at line 25 :

home_url = membership_tool.getAuthenticatedMember().getHomeFolder().absolute_url()
came_from = home_url


It's pretty evident what this two lines does, it basically calls the membership_tool's methods to determine the authenticated user's home folder's url and set's came_from to that value. After adding those two lines in there, login and logout again and all of your authenticated user's should be redirected to their home folders after login. Happy hacking !
Post a Comment