1

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?

pisapapiros
  • 355
  • 1
  • 2
  • 12
  • 1
    Have you looked in to token authentication? – The_Cthulhu_Kid Jul 05 '17 at 12:20
  • I know how to do that but for different subdomains to share the same cookie and session. Different domains maybe more work to do, maybe an SSO login solution will fit your need. I don't know how reliable/up to date this Django app is https://github.com/aldryn/django-simple-sso – Mounir Jul 05 '17 at 12:39

1 Answers1

1

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

mrbox
  • 814
  • 1
  • 6
  • 18