pisapapiros
pisapapiros

Reputation: 375

Keep user logged in accross Sites

I'm using Django Sites framework to hadle different sites. They have different domains but same database and same users.

I'd like to add a link to switch between my sites. The thing is I don't want to get redirected to login form. What is the best way to achieve this?

Is it possible to build a view that logs the user in the destination site and then redirect to it?

class SiteSwitcherView(View):
    def get(self, request, *args, **kwargs):
        site = Site.objects.filter(pk=kwargs.get('site_pk')).first()
        # log request.user in the destination Site
        # ...
        return redirect("http://{0}/dashboard/".format(site.domain))

To use authenticate() and login(), I have to pass the user credentials and current request...maybe if I send a post request to login view of the destination site before redirect would work?

Upvotes: 1

Views: 293

Answers (1)

mrbox
mrbox

Reputation: 824

Please check https://github.com/jbittel/django-mama-cas - this seem to be something you're looking for.

Upvotes: 1

Related Questions