MongoPostConnect is a full-stack web application built with Flask and MongoDB, where users can post multimedia content, like and comment on posts, and manage their personal profiles. The application uses Flask for backend handling, MongoDB as the database, and GridFS to store multimedia files such as images.
- User registration and login with secure password hashing π.
- Post creation with the ability to add multimedia content (images) πΌοΈ.
- Post editing and deletion (only by the creator) βοΈβ.
- Commenting and liking functionality on posts π¬π.
- Profile page where users can view their posts π€.
- Full authentication system using Flask-Login π.
- Backend: Flask
- Database: MongoDB (with GridFS for multimedia)
- Authentication: Flask-Login, Flask-Bcrypt
- Frontend: HTML, CSS, Bootstrap
- Other: PyMongo, GridFS
MongoDB is a NoSQL document-oriented database that stores data in flexible, JSON-like documents, which makes it easy to store, query, and manipulate complex data. Unlike traditional relational databases, MongoDB does not require predefined schemas and tables, providing more flexibility for developers to store and retrieve data. MongoDB is scalable and designed to handle large volumes of data, making it ideal for applications that need to process high amounts of unstructured data. In this project, MongoDB is used to store user data, posts, and multimedia content, while GridFS is used for storing large files such as images.
SocialConnect-Implementation-Part1.mp4
SocialConnect-Implementation-Part2.mp4
- Endpoint:
/
- Description: The main page where users can view posts made by all registered users. Displays posts along with multimedia (images). Users can like, comment, and navigate to their profile from this page.
- Functionalities:
- View all posts π.
- Add a new post (if logged in) β.
- View posts with multimedia files πΈ.
- Like and comment on posts β€οΈπ¬.
- Endpoint:
/login
- Description: The login page where users can authenticate themselves to access their account.
- Methods:
GET
,POST
- Functionalities:
- GET: Displays the login form π.
- POST: Takes the username and password, checks credentials, and logs the user in using Flask-Login π.
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
# Authenticate and log in
- Endpoint:
/register
- Description: The registration page where users can create a new account by providing a username and password.
- Methods:
GET
,POST
- Functionalities:
- GET: Displays the registration form π.
- POST: Registers the user, stores their username and hashed password, and redirects them to the login page π¬.
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
# Hash password and save user data
- Endpoint:
/profile
- Description: The user profile page, where users can view all the posts they have made and manage their content.
- Methods:
GET
- Functionalities:
- Displays the logged-in userβs posts πΈ.
- Option to edit or delete own posts βοΈβ.
@app.route('/profile')
@login_required
def profile():
user_posts = mongo.db.posts.find({"user_id": current_user.username})
return render_template('profile.html', user=current_user, posts=user_posts)
- Endpoint:
/home
- Description: Displays all posts from every user on the platform.
- Methods:
GET
- Functionalities:
- Shows all posts, including multimedia content and comments πΌοΈπ¬.
- Allows users to like or comment on posts β€οΈπ¬.
- Navigates to individual post details (edit, delete if owner) π οΈ.
@app.route('/home')
def index():
posts = mongo.db.posts.find()
return render_template('index.html', posts=posts)
- Endpoint:
/add_post
- Description: Allows users to create and publish a new post, optionally including multimedia content.
- Methods:
GET
,POST
- Functionalities:
- Users can add text and upload images (via GridFS) πΈ.
- The post is saved to MongoDB, and multimedia is stored using GridFS π.
@app.route('/add_post', methods=['GET', 'POST'])
@login_required
def add_post():
if request.method == 'POST':
post_text = request.form['text']
# Handle multimedia file uploads
post = {
"user_id": current_user.username,
"text": post_text,
"multimedia": multimedia_files,
"likes": 0,
"comments": []
}
mongo.db.posts.insert_one(post)
- Endpoint:
/edit_post/<post_id>
- Description: Allows users to edit their own posts.
- Methods:
GET
,POST
- Functionalities:
- Users can edit the text and replace multimedia of their own posts βοΈ.
- Only the original poster can edit the post π.
@app.route('/edit_post/<post_id>', methods=['GET', 'POST'])
@login_required
def edit_post(post_id):
post = mongo.db.posts.find_one({"_id": ObjectId(post_id)})
# Handle edit functionality
- Endpoint:
/delete_post/<post_id>
- Description: Allows users to delete their own posts.
- Methods:
POST
- Functionalities:
- Only the post creator can delete the post and associated multimedia from GridFS ποΈ.
@app.route('/delete_post/<post_id>', methods=['POST'])
@login_required
def delete_post(post_id):
post = mongo.db.posts.find_one({"_id": ObjectId(post_id)})
# Handle deletion logic
- Endpoint:
/like_post/<post_id>
- Description: Allows users to like a post. A user can only like a post once.
- Methods:
POST
- Functionalities:
- Updates the "likes" list in the post document β€οΈ.
- Prevents a user from liking the same post multiple times π.
@app.route('/like_post/<post_id>', methods=['POST'])
@login_required
def like_post(post_id):
# Logic to add like
- Endpoint:
/add_comment/<post_id>
- Description: Allows users to comment on posts.
- Methods:
POST
- Functionalities:
- Users can add comments to posts, which are stored within the post document π¬.
@app.route('/add_comment/<post_id>', methods=['POST'])
@login_required
def add_comment(post_id):
comment_text = request.form['comment']
# Add comment to post
MIT License. See LICENSE for more details.
Feel free to fork this repository, make changes, and submit pull requests. All contributions are welcome!
For any questions or inquiries, feel free to contact me via my GitHub: Bushra-Butt-17.