diff --git a/.gitignore b/.gitignore index 7b7dcdc..831cf37 100644 --- a/.gitignore +++ b/.gitignore @@ -3,12 +3,10 @@ *.sqlite3 -*.cpp -*.txt - *node_modules *.bin *db.sqlite3 db.sqlite3 *.vscode vscode +*media diff --git a/Backend/Dockerfile b/Backend/Dockerfile new file mode 100644 index 0000000..07d3e96 --- /dev/null +++ b/Backend/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.10 + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Set the working directory in the container +WORKDIR /opt/app + +RUN pip install --upgrade pip +# Copy the requirements file into the container +COPY ./requirements.txt /opt/app + +# Install the required packages +RUN pip install -r requirements.txt + +# Copy the Django backend files into the container +COPY . /opt/app + +# Expose port 8000 for the Django server +EXPOSE 8000 + +# Run the Django server +CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] \ No newline at end of file diff --git a/Backend/api/__pycache__/views.cpython-310.pyc b/Backend/api/__pycache__/views.cpython-310.pyc index 018c5a4..625bea2 100644 Binary files a/Backend/api/__pycache__/views.cpython-310.pyc and b/Backend/api/__pycache__/views.cpython-310.pyc differ diff --git a/Backend/api/accounts/__pycache__/serializers.cpython-310.pyc b/Backend/api/accounts/__pycache__/serializers.cpython-310.pyc index 3618d23..3dcd501 100644 Binary files a/Backend/api/accounts/__pycache__/serializers.cpython-310.pyc and b/Backend/api/accounts/__pycache__/serializers.cpython-310.pyc differ diff --git a/Backend/api/accounts/__pycache__/views.cpython-310.pyc b/Backend/api/accounts/__pycache__/views.cpython-310.pyc index 00fe14d..39a37ab 100644 Binary files a/Backend/api/accounts/__pycache__/views.cpython-310.pyc and b/Backend/api/accounts/__pycache__/views.cpython-310.pyc differ diff --git a/Backend/api/accounts/serializers.py b/Backend/api/accounts/serializers.py index 3b7603e..0cda5b6 100644 --- a/Backend/api/accounts/serializers.py +++ b/Backend/api/accounts/serializers.py @@ -50,7 +50,6 @@ def validate(self, attrs): password = attrs.get('password') password2 = attrs.get('password2') user = self.context.get('user') - # print(user) if password != password2: raise serializers.ValidationError("Password and Confirm Password don't match") @@ -70,12 +69,8 @@ def validate(self, attrs): if CustomUser.objects.filter(email=email).exists(): user = CustomUser.objects.get(email = email) uid = urlsafe_base64_encode(force_bytes(user.uid)) - # print('Encoded UID', uid) token = PasswordResetTokenGenerator().make_token(user) - # print('Password Reset Token', token) link = 'http://localhost:8000/api/accounts/reset-password/'+ uid +'/'+token - print('Password Reset Link', link) - # Send EMail body = 'Click Following Link to Reset Your Password ' + link data = { 'subject':'Reset Your Password', diff --git a/Backend/api/accounts/views.py b/Backend/api/accounts/views.py index 4ce78ba..002f9fe 100644 --- a/Backend/api/accounts/views.py +++ b/Backend/api/accounts/views.py @@ -34,9 +34,10 @@ from .mixins import PublicApiMixin, ApiErrorsMixin from .utils import google_get_access_token, google_get_user_info, generate_tokens_for_user from api.utils import upload_to_cloudinary - +from rest_framework.parsers import MultiPartParser, FormParser # Social Auth + class GoogleLoginApi(PublicApiMixin, ApiErrorsMixin, APIView): class InputSerializer(serializers.Serializer): code = serializers.CharField(required=False) @@ -112,7 +113,7 @@ def generate_verification_token(length = 32): class UserRegistrationView(APIView): permission_classes = [AllowAny] renderer_classes = [UserRenderer] - + parser_classes = [MultiPartParser, FormParser] def post(self, request, format=None): data = request.data data['profile_pic'] = upload_to_cloudinary(data['profile_pic']) @@ -174,12 +175,14 @@ def verify_account(request, uid, token): class UserLoginView(APIView): permission_classes = [AllowAny] renderer_classes = [UserRenderer] + parser_classes = [MultiPartParser, FormParser] def post(self, request, format=None): serializer = UserLoginSerializer(data=request.data) serializer.is_valid(raise_exception=True) email = serializer.data.get('email') password = serializer.data.get('password') user = authenticate(email=email, password=password) + print(user) if user is not None: if user.verified is not False: token = get_tokens_for_user(user) diff --git a/Backend/api/views.py b/Backend/api/views.py index a0173fc..b1c7317 100644 --- a/Backend/api/views.py +++ b/Backend/api/views.py @@ -3,4 +3,4 @@ # Create your views here. def home(request): - return JsonResponse({'info':'Django react Combos Home','name': 'Sagar Kumar Sameer'}) \ No newline at end of file + return JsonResponse({'info':'This is base api.'}) \ No newline at end of file diff --git a/Backend/backend/__pycache__/settings.cpython-310.pyc b/Backend/backend/__pycache__/settings.cpython-310.pyc index 81cdb15..c9de30e 100644 Binary files a/Backend/backend/__pycache__/settings.cpython-310.pyc and b/Backend/backend/__pycache__/settings.cpython-310.pyc differ diff --git a/Backend/backend/__pycache__/urls.cpython-310.pyc b/Backend/backend/__pycache__/urls.cpython-310.pyc index a785e8c..3f40024 100644 Binary files a/Backend/backend/__pycache__/urls.cpython-310.pyc and b/Backend/backend/__pycache__/urls.cpython-310.pyc differ diff --git a/Backend/backend/settings.py b/Backend/backend/settings.py index 5db3ec6..8acc5e3 100644 --- a/Backend/backend/settings.py +++ b/Backend/backend/settings.py @@ -101,23 +101,23 @@ # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.sqlite3', -# 'NAME': BASE_DIR / 'db.sqlite3', -# } -# } +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} -DATABASES = { - 'default': dj_database_url.config( - default=os.environ.get('DB_URL') - ) -} +# DATABASES = { +# 'default': dj_database_url.config( +# default=os.environ.get('DB_URL') +# ) +# } # 'default': { # 'ENGINE': 'django.db.backends.postgresql', # 'NAME': os.environ.get('DATABASE_NAME'), @@ -187,7 +187,9 @@ 'rest_framework.authentication.SessionAuthentication', 'rest_framework_simplejwt.authentication.JWTAuthentication', ], - + 'DEFAULT_PARSER_CLASSES': [ + 'rest_framework.parsers.JSONParser', + ] } @@ -243,7 +245,7 @@ # Cloudinary config CLOUDINARY_STORAGE = { - 'CLOUD_NAME' : os.environ.get('CLOUDNARY_CLOUD_NAME'), + 'CLOUD_NAME' : os.environ.get('CLOUDINARY_CLOUD_NAME'), 'API_KEY' : os.environ.get('CLOUDINARY_API_KEY'), 'API_SECRET' : os.environ.get('CLOUDINARY_API_SECRET') } diff --git a/Backend/backend/urls.py b/Backend/backend/urls.py index dda67ab..cac92f5 100644 --- a/Backend/backend/urls.py +++ b/Backend/backend/urls.py @@ -3,11 +3,12 @@ from django.urls import path,include from django.conf.urls.static import static from django.conf import settings - +from api.views import home urlpatterns = [ path('admin/', admin.site.urls), path('api/',include('api.urls')), + path('',include('api.urls')), ] urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT) diff --git a/Backend/docker-compose.yml b/Backend/docker-compose.yml new file mode 100644 index 0000000..2eb0c94 --- /dev/null +++ b/Backend/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3' + +services: + web: + build: . + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - .:/app + ports: + - "8000:8000" + depends_on: + - db + environment: + DJANGO_SETTINGS_MODULE: "backend.settings" + POSTGRES_DB: ${DB_NAME} + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + networks: + - backend + + db: + image: postgres:latest + volumes: + - postgres_data:/var/lib/postgresql/data + environment: + POSTGRES_DB: ${DATABASE_NAME} + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + networks: + - backend + +networks: + backend: + +volumes: + postgres_data: diff --git a/Backend/requirements.txt b/Backend/requirements.txt new file mode 100644 index 0000000..077174c --- /dev/null +++ b/Backend/requirements.txt @@ -0,0 +1,45 @@ +asgiref==3.7.2 +cachetools==5.3.2 +certifi==2023.11.17 +cffi==1.16.0 +charset-normalizer==3.3.2 +cloudinary==1.39.0 +cryptography==41.0.7 +defusedxml==0.7.1 +dj-database-url==2.1.0 +dj-rest-auth==5.0.2 +Django==5.0 +django-allauth==0.59.0 +django-ckeditor==6.7.1 +django-cloudinary-storage==0.3.0 +django-cors-headers==4.3.1 +django-environ==0.11.2 +django-js-asset==2.2.0 +djangorestframework==3.14.0 +djangorestframework-simplejwt==5.3.1 +google-auth==2.25.2 +google-auth-httplib2==0.2.0 +google-auth-oauthlib==1.2.0 +httplib2==0.22.0 +idna==3.6 +oauthlib==3.2.2 +Pillow==10.1.0 +psycopg2==2.9.9 +psycopg2-binary==2.9.9 +pyasn1==0.5.1 +pyasn1-modules==0.3.0 +pycparser==2.21 +PyJWT==2.8.0 +pyparsing==3.1.1 +python-dotenv==1.0.0 +python3-openid==3.2.0 +pytube==15.0.0 +pytz==2023.3.post1 +razorpay==1.4.1 +requests==2.31.0 +requests-oauthlib==1.3.1 +rsa==4.9 +six==1.16.0 +sqlparse==0.4.4 +typing_extensions==4.9.0 +urllib3==2.1.0 diff --git a/README.md b/README.md index 582ed35..77ae6e7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This is an eCommerce web application built with Django and React.js. It utilizes - Frontend: - React.js: JavaScript library for building interactive user interfaces. - React Router Dom: Library for handling client-side routing in a React application. - + - React Redux Toolkit: Library for Managing states. ## Installation and Setup 1. Clone the repository: diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..ad138de --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,23 @@ +# Use the official Node image as the base image +FROM node:20-alpine + +# Set the working directory inside the container +WORKDIR /app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install project dependencies +RUN npm install + +# Copy the entire project to the working directory +COPY . . + +# Build the React app +RUN npm run build + +# Expose the port on which the app will run +EXPOSE 3000 + +# Command to start the application +CMD ["npm", "start"] diff --git a/frontend/docker-compose.yml b/frontend/docker-compose.yml new file mode 100644 index 0000000..2ca8b32 --- /dev/null +++ b/frontend/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' + +services: + frontend: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + volumes: + - ./src:/app/src + - ./public:/app/public + environment: + - NODE_ENV=development diff --git a/frontend/src/category/AddCategory.js b/frontend/src/category/AddCategory.js index 75dfcf5..d1d8f4d 100644 --- a/frontend/src/category/AddCategory.js +++ b/frontend/src/category/AddCategory.js @@ -4,14 +4,10 @@ import { useDispatch } from 'react-redux'; import { createCategory } from '../features/actions/categoryActions'; import { unwrapResult } from '@reduxjs/toolkit'; import Swal from 'sweetalert2'; -import { useLocation, useNavigate } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; const AddCategory = () => { - - const location = useLocation(); - // console.log("location...", location); - const [values, setValues] = useState({ name: "", description: "", @@ -30,11 +26,9 @@ const AddCategory = () => { }; const onSubmit = async (e) => { - e.preventDefault(); // Corrected typo - + e.preventDefault(); const res1 = await dispatch(createCategory({ name, description })); const res = await unwrapResult(res1); - console.log("category res...", res); if (!res.errors) { Swal.fire({ icon: 'success', diff --git a/frontend/src/category/Categories.jsx b/frontend/src/category/Categories.jsx index e85466b..21f0845 100644 --- a/frontend/src/category/Categories.jsx +++ b/frontend/src/category/Categories.jsx @@ -1,6 +1,6 @@ import React, { useEffect, useState, useRef } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { Link, useNavigate } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; import { loadCategory } from '../features/actions/categoryActions'; const Categories = () => { diff --git a/frontend/src/features/actions/paymentAction.js b/frontend/src/features/actions/paymentAction.js index 0b2eea4..60beff3 100644 --- a/frontend/src/features/actions/paymentAction.js +++ b/frontend/src/features/actions/paymentAction.js @@ -1,5 +1,4 @@ -import Swal from 'sweetalert2'; import { API } from '../../backend'; import { createAsyncThunk } from "@reduxjs/toolkit"; diff --git a/frontend/src/helper/DisplayOrderList.jsx b/frontend/src/helper/DisplayOrderList.jsx index 83f78dd..b2a39e8 100644 --- a/frontend/src/helper/DisplayOrderList.jsx +++ b/frontend/src/helper/DisplayOrderList.jsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; import { Link } from 'react-router-dom'; -import { BaseUrl } from '../backend'; import { mapDeliveryTime, mapOderType, @@ -38,7 +37,7 @@ const DisplayOrderList = ({ data }) => {