2

I have links over an image, if the user is logged in an ajax to upvote/downvote can happen easily. however if the user is not logged in, I ensure the user is authenticated first.

The implementation is done in template as follows -

{% if not user.is_authenticated %}
<a href="/accounts/login/">Get Started</a>
{% else %}
<a href="my-ajax-url"> Like </a>
{% endif %}

The trouble here is if the user is not logged in, I want him first to login, and then perform the ajax action. Something similar to what next helps do. So the flow should be, if the user is not logged, he is taken to the login url, and then the ajax action automatically takes place.

A reverse way of implementing it is, implementing an ajax_login_decorator, which can be done as here. With the second approach, the flow is something like:

1. The user clicks on the action button.
2. the request goes to the server, if he is not authenticated, a response is sent to client.
3. He is made to login/signup.
4. Then once he logs in, he has to click on the action button again. 

Instead a better approach could be, he is made to login first, and something similar to next can perform the ajax action. So the question boils down to this simple thing -

How to call a an ajaxy url with some next params, after the user has been authenticated.

Community
  • 1
  • 1
user1629366
  • 1,931
  • 5
  • 20
  • 30

1 Answers1

1

How about in step 2 you store the action in (anonymous) session and once he logs in you fire the action from the server side? You won't have to make the AJAX call at all.

freakish
  • 54,167
  • 9
  • 132
  • 169
  • could you please elaborate on how to do that? or in case you could suggest pointers where I can refer and understand how to implement it, as in code. – user1629366 May 01 '13 at 08:21