python3 -m venv .venv
source .venv/bin/active
pip install flask
pip install flask-wtf
brew install pkg-config
brew install mysql-client
This is a simple web application built with Flask and MySQL that allows users to register, log in, and view their dashboard. It demonstrates the basic use of Flask, MySQL integration, and user authentication using Flask-WTF forms.
- Requirements
- Installation
- Environment Setup
- Application Overview
- Usage
- Contributing
- License
Before you begin, ensure you have met the following requirements:
-
Python 3.x
-
Flask
-
Flask-WTF
-
Flask-MySQL
-
bcrypt
-
MySQL Server
To install and set up the project, follow these steps: 1. Clone the repository:
git clone https://github.com/AbdullahRFA/Flask_AUTH_with_Mysql.git
python -m venv venv
• For Windows:
.\venv\Scripts\activate
• For Mac/Linux:
source venv/bin/activate
pip install -r requirements.txt
This will install all necessary Python libraries including Flask, Flask-WTF, MySQL Connector, and bcrypt.
Environment Setup
Ensure you have MySQL installed and running. Then, create a new database called mydatabase.
CREATE DATABASE mydatabase;
Create a table to store user data (name, email, password):
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL
);
In the app.py file, set the MySQL connection parameters such as MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, and MYSQL_DB according to your local setup.
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'your_password_here'
app.config['MYSQL_DB'] = 'mydatabase'
Home Page: A simple home page that introduces the application
Registration Page: Users can register by providing their name, email, and password.
Login Page: Registered users can log in with their credentials.
Dashboard Page: Displays user information after successful login.
Logout: Allows users to log out and clear their session.
• /: Home Page
• /register: Registration Page
• /login: Login Page
• /dashboard: Dashboard Page (requires login)
• /logout: Log out the user
Registration Form: Contains fields for name, email, and password.
Login Form: Contains fields for email and password.
Passwords are hashed using bcrypt before being stored in the database to ensure secure authentication. Flask-WTF is used to handle form validation and CSRF protection.
After completing the setup, you can run the Flask application with:
python app.py
Once the application is running, you can access it in your web browser at http://127.0.0.1:5000/.
• Registration: You can create a new user account.
• Login: Registered users can log in and view their dashboard.
• Dashboard: Displays user information.
• Logout: After logging in, you can log out and the session will end.
Contributions are welcome! If you want to contribute to the project, follow these steps:
-
Fork the repository.
-
Create a new branch (git checkout -b feature-branch).
-
Make your changes.
-
Commit your changes (git commit -m 'Add new feature').
-
Push to the branch (git push origin feature-branch).
-
Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
• Ensure that your MySQL server is running before starting the application.
• The application uses Flask sessions for storing user login status.
• You can customize the CSS in the app.html and dashboard.html templates to make the app look more professional as per your preference.
This README file should help guide users through the installation and usage of your project and provide clear instructions for setting up the environment, installing dependencies, and contributing to the project.