HaHaHUb

HaHaHub - A Flask-Based Joke Sharing Platform

HaHaHub is a web application that allows users to submit, view, and vote on jokes. It features user authentication, an admin dashboard, and an API for joke retrieval and voting. The application is currently hosted at hahahub.bhavya31.hackclub.app.

Features

Installation

Prerequisites

Setup

  1. Clone the repository:
    git clone https://github.com/yourusername/HaHaHub.git
    cd HaHaHub
    
  2. Create a virtual environment and install dependencies:
    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
       
    
  3. Set up the database:
    python setup_db.py
    
  4. Run the application:
    python app.py
    

    The app will be available at http://127.0.0.1:5080/.

API Usage

1. Get a Random Joke

Endpoint: /api/joke
Method: GET
Response:

{
    "id": 1,
    "joke": "Why don’t skeletons fight each other? They don’t have the guts."
}

Curl Command:

curl -X GET https://hahahub.bhavya31.hackclub.app/api/joke

2. Vote on a Joke

Endpoint: /api/vote/<direction>/<int:joke_id>
Method: POST
Parameters:

Response:

{
    "status": "success",
    "id": 2,
    "joke": "Another joke after voting"
}

Curl Command:

curl -X POST https://hahahub.bhavya31.hackclub.app/api/vote/up/26

3. Register a New User

Endpoint: /register
Method: POST
Request Body:

{
    "username": "newuser",
    "password": "password123"
}

Response:

{
    "status": "success"
}

4. Login User

Endpoint: /login
Method: POST
Request Body:

{
    "username": "newuser",
    "password": "password123"
}

Response:

{
    "status": "success"
}

5. Submit a Joke

Endpoint: /submit_joke
Method: POST
Request Body:

{
    "joke": "Why did the chicken cross the road? To get to the other side!"
}

Response:

{
    "status": "success"
}

6. Get User Dashboard Jokes

Endpoint: /user
Method: GET
Response:

{
    "jokes": [
        "Joke 1",
        "Joke 2"
    ]
}

7. Admin Dashboard

Endpoint: /admin
Method: GET
Response:

{
    "total_jokes": 100,
    "top_jokes": [
        {
            "id": 1,
            "joke": "Top voted joke"
        }
    ]
}

8. Edit a Joke (Admin Only)

Endpoint: /admin/edit/<int:joke_id>
Method: POST
Request Body:

{
    "joke_text": "Updated joke content."
}

Response:

{
    "status": "success"
}

9. Delete a Joke (Admin Only)

Endpoint: /admin/delete/<int:joke_id>
Method: POST
Response:

{
    "status": "success"
}

10. Change Password

Endpoint: /change_password
Method: POST
Request Body:

{
    "old_password": "currentpassword",
    "new_password": "newpassword123",
    "confirm_password": "newpassword123"
}

Response:

{
    "status": "success"
}

Curl Command:

curl -X POST https://hahahub.bhavya31.hackclub.app/api/change_password \
     -H "Content-Type: application/json" \
     -d '{"old_password": "password123", "new_password": "newpassword456"}' \
     -b cookies.txt

Deployment

The application is deployed on PythonAnywhere. To deploy:

  1. Upload your project files.
  2. Set up a virtual environment and install dependencies.
  3. Configure the WSGI file to point to your Flask app.
  4. Restart the web app from the PythonAnywhere dashboard.

Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-name).
  3. Make changes and commit (git commit -m "Add new feature").
  4. Push to the branch (git push origin feature-name).
  5. Open a Pull Request.

License

This project is licensed under the MIT License.


Enjoy sharing and laughing with HaHaHub! 🎉