2

Here is my usecase:

  1. Only authenticated user can vote.
  2. If an anonymous user tries voting, after the voting is done, the user is represented a modal window for login/register.
  3. If the user registers or loges in, the vote is saved.

The vote calculation is done using cron or other module. I do not have tie up with any particular module (and fine with writing a basic one). I am currently trying my luck with Rules, Voting Rules, Fivestar and obviously, Voting API. For login/registration persona and fbauth is used, so no email verification is requierd.

A similar problem is discussed in A module that allows user to create content anonymously, then if they register, assigns the content to them, however my use case involved voting and email-free registration. Voting makes it more complicated while email-free registration (hopefully) makes it easier.

PS: I want to follow the same work flow for different nodes with plus1 (or similar) module, so a generic approach is requested.

1
  • just an idea: if add a vote event is exposed to rules,then on action store the node id where the vote was casted ,now assuming you are able to show the login form in popup- agai in hook_user_presave() and hook_user_save() or hook_user_login check if session values is set then use the vote api to cast the cote programmatically against that user,and then clear the session.
    – arpitr
    Dec 17, 2013 at 17:54

2 Answers 2

2
+50

You could store anonymous votes in a cookie, then on login/register, check to see if that cookie exists and cast the votes accordingly.

  1. When an anon user tries to vote, use user_cookie_save() to save the Entity Type and Entity ID of the Entity that the user was trying to vote on in a cookie. Name it something like pending_votes. At the same time, you can trigger your modal login window. It's possible that a user won't login/register at that time and it's also possible that they will attempt to vote on other Entities before finally logging in. So you'll probably want to store the Entity Type and ID as a serialized array.
  2. Then you can hook into a user logging in with hook_user_login() and check for the existence of the pending_votes cookie. If it's there, use it's contents along with votingapi_set_votes() to cast the pending votes. (delete the pending_votes cookie afterwards so they don't cast more votes each time they log in)
2
  • Nice solution! Do you think I can use it with any popular voting modules, like Fivestar or Rate? Both gives API to execute function chunks before casting the vote.
    – Ratul Saha
    Dec 22, 2013 at 14:22
  • The general idea should work with any module that uses the Voting API, which both Fivestar and Rate do. Dec 23, 2013 at 14:51
0

Lazy Registration was designed for a similar reason but I'm not sure how stable it is. Either way, it will provide a good starting point for you.

The Lazy Registration module captures actions made by anonymous users and stores them against a temporary user account until they are ready to register.

1
  • That's a really interesting module. Thanks. I wasn't aware of it. It looks like it performs the actions by anonymous users regardless of whether they eventually register or not. And it would probably be a lot of work to get the voting_api and whatever front-end module the OP uses to integrate with it. But it's very interesting nonetheless. Dec 23, 2013 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.