Save the account when you go and use validation to enforce it. I hacked it together - by counting unique votes and counts that continue to grow! But this time I tried my offer! (despite cutting / pasting errors!).
The "trick" here is to use node priority as a vote count ...
Data:
vote / $ issueBeingVotedOn / user / $ uniqueIdOfVoter = thisVotesCount, priority = thisVotesCount vote / $ issueBeingVotedOn / count = 'user /' + $ idOfLastVoter, priority = CountofLastVote
,"vote": { ".read" : true ,".write" : true ,"$issue" : { "user" : { "$user" : { ".validate" : "!data.exists() && newData.val()==data.parent().parent().child('count').getPriority()+1 && newData.val()==newData.GetPriority()"
the user can vote only once && & the score should be higher than the current counter && the data value should be the same as the priority.
} } ,"count" : { ".validate" : "data.parent().child(newData.val()).val()==newData.getPriority() && newData.getPriority()==data.getPriority()+1 " }
count (the last voter is valid) - a vote must exist, and its score is newcount, && & newcount (priority) can only increase by one.
} }
A test script to add 10 votes from different users (for this example, a fake id, should the user auth.uid during production). Count (i--) 10 to see that the check failed.
<script src='https://cdn.firebase.com/v0/firebase.js'></script> <script> window.fb = new Firebase('https:...vote/iss1/'); window.fb.child('count').once('value', function (dss) { votes = dss.getPriority(); for (var i=1;i<10;i++) vote(dss,i+votes); } ); function vote(dss,count) { var user='user/zz' + count; </script>
The "risk" here is that the vote is taken, but the score is not updated (failure or failure of the script). That's why voices have a unique "priority" - the script should really start with the fact that there is no vote with a priority higher than the current account, if he has to complete this transaction before doing his job - get his clients clear for you :)
Counting must be initialized with priority before you begin - forge does not allow you to do this, so you need a script stub (before validation is active!).