Rating Display : restrict a user, by ip address or other method

hi, I have a problem with the Rating Display. I created the function with the ratings and the average, everything works fine. The problem is: how do I get a user to vote only once? and not several times? Is there a check by IP address? or by email? do you have an idea how to do it? this is the code :

$w . onReady ( function () {

});

export function ratingsInput1_change ( event ) {

$w ( “#dynamicDataset” ). onReady (() => {
// get the current item from the dataset
const currentItem = $w ( “#dynamicDataset” ). getCurrentItem ();

// get the current average rating, number of ratings, and
//total ratings for the current dataset item
const average = currentItem . avg ;
const count = currentItem . numRatings ;
const total = currentItem . totalRatings ;

// get the new rating from the ratings input
const newRating = $w ( ‘#ratingsInput1’ ). value ;

// calculate the new average rating based on the current
//average and count
const newAverageLong = ( total + newRating ) / ( count + 1 );
// Round the average rating to 1 decimal point
const newAverageShort = Number . parseFloat ( newAverageLong ). toFixed ( 1 );

// set the dataset fields to the new average, total
// ratings, and number of ratings
$w ( ‘#dynamicDataset’ ). setFieldValues ({
‘avg’ : newAverageShort ,
‘totalRatings’ : total + newRating ,
‘numRatings’ : ( count + 1 )
});

// save the dataset fields to the collection
$w ( ‘#dynamicDataset’ ). save ()
. catch (( err ) => {
console . log ( ‘could not save new rating’ );
});
});

}

Thanks :smile:

I think it will not work with restrict by IP.
But what could work is a referenced fiele in your Database, which will link you to another DB, where you will safe all the User-IDs, which already have voted.

See the Ratings by User example. This example allows registered users to rate recipes when logged in. The user can only submit one rating, but can change it.

This is fantastic thank you

I have tried with exactly that code and exactly same names of the fields but still not working. Extremely frustrating because Andrea wrote that it works for her.