Skip to content

A django-rest authentication project that demonstrates the full functionality.

License

Notifications You must be signed in to change notification settings

amiroooamiran/DjangoRest_authentication

Repository files navigation

Authentication Project

Welcome to the Authentication project! This Django REST Framework project offers a comprehensive set of features for user authentication, user profiles, and security measures. It empowers users to handle account creation, email verification, signin, password reset, and manage their profiles efficiently. Moreover, the project integrates various security options to ensure data integrity and user authentication.

Features

Authentication

  • Signup: Enables users to register new accounts securely. ✅
  • Email Verification: Verifies the authenticity of user emails to enhance security. ✅
  • Signin: Provides a secure login mechanism for registered users. ✅
  • Password Reset: Offers a secure process for users to reset their passwords. ✅
  • Social Media Authentication: Allows users to authenticate using their social media accounts.

User Profile

  • Profile Image: Allows users to upload and update their profile images effortlessly. ✅
  • Bio: Enables users to add, modify, or delete their biography information. ✅
  • Username: Provides the flexibility for users to change their usernames as needed. ✅
  • Remove Full Account: Users can remove all their data from the database from their account.

Security Options

  • Attribute-based Authorization: Controls access to resources based on user attributes. ✅
  • Django-cryptography: Utilizes cryptographic functionalities to ensure data security.
  • Django-honeypot: Implements honeypot techniques for threat detection and mitigation.
  • Input Validation and Output Encoding: Protects against common web vulnerabilities by validating user inputs and encoding outputs securely.
  • Multi-factor Authentication: Enhances security by requiring users to authenticate through multiple methods.

Startup project

Config DataBase

Before starting the project, ensure PostgreSQL is installed on your system. You can follow the instructions below to set up PostgreSQL and create a database:

For Linux:

Install PostgreSQL: PostgreSQL Badge

Arch Linux:

sudo pacman -S postgresql

Debian Linux:

sudo apt-get install postgresql

Start and enable PostgreSQL:

sudo systemctl start postgresql
sudo systemctl enable postgresql

Create Database User and Password

To create a database user and password in PostgreSQL, follow these steps:

  1. Log in to the PostgreSQL database server with the postgres user:
  2. sudo -u postgres psql
  3. Create a new database user with a password. Replace <username> with the desired username and <password> with the desired password:
  4. CREATE USER <username> WITH PASSWORD '<password>';
  5. Grant the user privileges on the database. Replace <database> with the name of your database and <username> with the username you just created:
  6. GRANT ALL PRIVILEGES ON DATABASE <database> TO <username>;
  7. Exit the PostgreSQL prompt:
  8. \q

Here's an example:

sudo -u postgres psql
CREATE USER myuser WITH PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE authenticat TO myuser;
\q

Replace myuser with your desired username and mypassword with your desired password. Also, replace authenticat with the name of your database.

For Windows:

You can download and install PostgreSQL from the official website: PostgreSQL Official Website.

Install Kafka: Apache Kafka Badge

Before installing Kafka on your Linux system, you need to install Java, specifically JDK. You can use the following commands to install JDK on your Linux distribution:

For Arch Linux:

sudo pacman -S jdk-openjdk

For Debian Linux:

sudo apt install openjdk-17-jdk

After installing Java, you can verify the installation by running:

java --version

In the next step, you should install Kafka. You can download your desired version from this link and then configure it for your project:

Extract:

tar -xzf kafka_2.13–3.5.0.tgz
cd kafka_2.13–3.5.0

Start:

  • Generate a Cluster UUID:
    KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"
    
  • Format Log Directories:
    bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/kraft/server.properties
    
  • Start the Kafka Server:
    bin/kafka-server-start.sh config/kraft/server.properties
    
  • Create a topic:
    bin/kafka-console-consumer.sh --topic topic_user_created --bootstrap-server localhost:9092 --from-beginning
    

Config Email App Password

To configure the email app password, please follow the instructions provided by Google at the following link: Google Support.

Migrations and Run Server

After configuring the database and email app password, you can proceed with migrations and running the server:

Run migrations:

python manage.py makemigrations
python manage.py migrate

Run the server:

python manage.py runserver

Docker Support

The project includes a Dockerfile, facilitating the deployment of the application within Docker containers. This simplifies the deployment process and ensures consistent behavior across various environments.

Run

Before running the application with Docker, ensure that Docker and docker-compose are installed on your system. If not, you can install them by following the official documentation.

To start Docker, use the following commands:

sudo systemctl start docker
sudo systemctl enable docker

after install Docker and Run docker on your ststem, move in project directory and up docker-compose file:

sudo docker-compose up

How to Connect to Frontend:

To connect to the frontend, you can follow these steps:

  1. Clone the Frontend Repository:
  2. You can clone the frontend from the Vue.js_authentication repository.

  3. Guidance for Setting Up the Frontend:
  4. Refer to the instructions provided in the frontend repository to set up and configure the frontend application.

  5. Startup Project:
  6. Once the frontend is set up and configured, you can integrate it with the backend authentication project and start both projects simultaneously.

Thank You!

Thank you for choosing the Authentication project! Should you have any inquiries or require further assistance, please do not hesitate to contact us. We're committed to providing support and ensuring your experience with our project is smooth and successful.