Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect to last page not working on python social auth

I'm using python social auth to use social logins but I'm unable to redirect to the last page after successful login.

For instance if I'm on the following page http://localhost:8000/docprofile/14/and click the login button, instead of redirecting me to the last page http://localhost:8000/docprofile/14/ it redirects me to the login page.

If I put this:

<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}"> | Login with Facebook</a>

It redirects to the login page and the url ends with strange characters:

http://localhost:8000/login/#_=_

I also tried this:

<a href="{% url 'social:begin' 'facebook' %}?next={{ request.get_full_path }}"> | Login with Facebook</a>

This time it does take the path of the /docprofile/14 but still doesn't redirect me back and takes me to the login page with the url http://localhost:8000/login/?next=/docprofile/14/#_=_

like image 361
James L. Avatar asked Nov 15 '14 18:11

James L.


1 Answers

What I had to do was strip off the next parameter from the query string in my GET and modify the html to include it in the template like this

def home(request):
    c = context()
    if request.GET.get('next'):
        c = context(next=request.GET['next'])

    return render_to_response('home.html',
                              context_instance=RequestContext(request, c))

def context(**extra):
    return dict({
        'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS)
    }, **extra)

And my template now gets the next parameter from the context and when i log in the redirect works.

<a class="col-md-2 btn btn-default" name="{{ backend|backend_class }}" href="{% url "social:begin" backend=name %}?next={{next}}">
like image 96
ThrowsException Avatar answered Nov 09 '22 08:11

ThrowsException