Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

every vote an IP #111

Open
omidMolaverdi opened this issue Jun 10, 2021 · 4 comments
Open

every vote an IP #111

omidMolaverdi opened this issue Jun 10, 2021 · 4 comments

Comments

@omidMolaverdi
Copy link

omidMolaverdi commented Jun 10, 2021

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.

@mrwhale
Copy link

mrwhale commented Jun 10, 2021

I encountered something similar a little while ago as I had the need for any user to be able to vote, rather then basing it on IP As this poll feature I used was only published to target 1 company who resided in 1 office (so everyone had the same external IP)

I got around that by using the request session rather then the request IP

#80 (comment)

edit:
Also note that I had to change the Guest model so the Guest ID was the session token too
Guest.php

    public function __construct(Request $request)
    {
            $this->user_id = $request->session()->token();
    }

@akiyamaSM
Copy link
Owner

I'll be working on that for the next release.

@omidMolaverdi
Copy link
Author

omidMolaverdi commented Jun 14, 2021

Hi

@akiyamaSM Just a touch base, do you plan to fix this?

@akiyamaSM
Copy link
Owner

@omidMolaverdi Not any soon. I'd be happy to see a PR from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants