Implementing voting restrictions

Right now, anybody on the internet can essentially stuff the ballot with as many votes as our poor system will allow them to! This doesn't make for very fair polls, so we'll take a naive approach and implement an IP-based list of people who have already voted on each particular poll!

We'll need to start off by figuring out a way to identify the user's IP address. The good news is that Phoenix already has that information ready for us in the conn object! In the conn object, one of the keys in the map is remote_ip, which is a tuple of the four octets in the IP address of the connecting user! We can verify this either by placing an IEx.pry statement in one of our controller actions and taking a look at the output ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.