0

I am attempting to recreate this website: https://what-to-code.com/ using flask and flask-SQLAlchemy. However I have run into a problem. I want each user of the website to only be able to like a post once, which would be easy to do if each user was required to make an account. But I would like to have a completely anonymous system. I have thought of two ways to achieve the like counter but I can't figure out how to implement them.

  1. Every time a new IP address connects to the website, create a user in the sqlite database I am using, and when the user tries to like a post, check to see if their IP already exists in the liked users.

  2. Somehow assign a cookie to each user that connects, that keeps track of their likes. Upon inspection of the website's cookies, I see this is the approach they have taken.

I recognise that these systems both have flaws and can be exploited, but I don't mind that.

How could I achieve this anonymous liking system with flask and flask-SQLAlchemy?

Thank you.

Faizan Shah
  • 59
  • 1
  • 9
  • 1
    The question is too broad. Start looking at tutorials and ask specific questions if you need. – balderman Sep 26 '21 at 20:03
  • I wouldn't exactly know how to do this either, but have you read this article: [remember anonymous users with cookies](https://stackoverflow.com/questions/53899527/python-flask-how-to-remember-anonymous-users-via-cookie-session) Maybe this can send you in the direction you want to go with your likes. Using the article: create an anonymous user and set a cookie that tells that the like is given. When page loads just search for the cookie if a like has been given. – Patrick Kaim Sep 26 '21 at 20:06

1 Answers1

2

I managed to accomplish this by storing a session cookie that kept track of all the posts a user has liked and changing that list accordingly when the like button is hit.

Faizan Shah
  • 59
  • 1
  • 9