Skip to content

every vote an IP #111

@omidMolaverdi

Description

@omidMolaverdi

Hi,

Thank you for your package. I encountered an issue that blocks my way forward.

It seems that you have locked an IP one vote however, there should be a freedom of vote interval for voting otherwise it won't work for the websites proxied by e.g. Cloudflare that the IP addresses are limited.

I normally cope with this issue by defining a freedom of voting variable and set it to a value like 1 hour. In your case it would be rewriting the following function with the added extra line:

public function hasVoted($poll_id,$freedomofvoteHours )
    {
        $poll = Poll::findOrFail($poll_id);

        if ($poll->canGuestVote()) {
            $result = DB::table('larapoll_polls')
                ->selectRaw('count(*) As total')
                ->join('larapoll_options', 'larapoll_polls.id', '=', 'larapoll_options.poll_id')
                ->join('larapoll_votes', 'larapoll_votes.option_id', '=', 'larapoll_options.id')
                *******->whereRaw('larapoll_votes.created_at >= DATE_ADD(NOW, INTERVAL -' . $freedomofvoteHours . ' HOUR)')
                ->where('larapoll_votes.user_id', request()->ip())
                ->where('larapoll_options.poll_id', $poll_id)->count();
            return $result !== 0;
        }

        return $this->options()->where('poll_id', $poll->id)->count() !== 0;
    }

The other difficult policy in this package is to edit the options by the admin. Obviously, there may be always typos and your current policy does not allow any adjustment to the option after the first vote.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions