On 3/03/2011 15:15, Benedict Verheyen wrote: > Hi, > > i have a problem with logging in a user to more than one site. > SIte A and B are on the same subdomain. > > When a user visits site B, he is redirected to site A. > Site A shows a login screen, checks the credentials with LDAP. > After a succesful login, the user is redirected back to site B. > > However, when I then visit site A, the user is logged out (Anonymous) > The userdatabase is in the database of site A and site B gets the info > by using multiple databases and thus getting the info from site A. > > As for some more detailed info, site B has a login view. > From there, I redirect to site A with a return param specified as GET > parameter to > this same login view. > When i get there, i receive the user id, and get the user like this (in the > backend to authenticate) > > user = User.objects.using('central_users').get(pk=key) > > where 'central_users' is specified in settings.py: > > 'central_users': { > 'ENGINE': 'django.db.backends.postgresql_psycopg2', > 'NAME': 'site A', > 'USER': 'xxx', > 'PASSWORD': 'xxx', > 'HOST': 'localhost', > 'PORT': '', > } > > This finally works but as i said, I then run into problems on site A, the > user is logged out. > The user is first logged in, in site A when i check the credentials. > > Would this have anything to do with the fact that the user gets logged out > later? > > Trying to log in a user to more than 1 site is more frustrating than i > thought :) > > Regards, > Benedict >
Wow, what a pain this is. I succeeded in making it work but I have to do some more testing to be sure my solution is ok. I had to make a User for site B as well and then, the user is logged in, in site A and B. Off course, having the same user object in Site B defeats the whole purpose. I'm not sure I'm happy with the fact that you have to call authenticate before a call to login. In the login view of site B, i get the id of the user that is logged in. So i thought this would work: user = User.objects.using('central_users').get(pk=key) login(request, user) where 'central_users' is set in settings.py to link to the users database of site A. Off course, the above doesn't work because of the authenticate so you have to write a backend. No probs, you write the backend to get the users from 'central_users' and return that user. Simple enough. Nope, if you do that, the user is logged out of site A. I have only been able to solve this by creating a new user for site B. As I said, i'm going to test further but it has been a painful journey. Cheers, Benedict -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.