Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/datashop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added apps/auth/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions apps/auth/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions apps/auth/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AuthConfig(AppConfig):
name = 'auth'
5 changes: 5 additions & 0 deletions apps/auth/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django import forms

class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput)
3 changes: 3 additions & 0 deletions apps/auth/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
13 changes: 13 additions & 0 deletions apps/auth/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer


class MyTokenObtainPairSerializer(TokenObtainPairSerializer):

@classmethod
def get_token(cls, user):
token = super(MyTokenObtainPairSerializer, cls).get_token(user)

# Add custom claims
token['username'] = user.username
return token

3 changes: 3 additions & 0 deletions apps/auth/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
6 changes: 6 additions & 0 deletions apps/auth/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('login/', views.user_login, name='index'),
]
36 changes: 36 additions & 0 deletions apps/auth/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth import authenticate, login
from .forms import LoginForm

from .serializers import MyTokenObtainPairSerializer
from rest_framework.permissions import AllowAny
from rest_framework_simplejwt.views import TokenObtainPairView


class MyObtainTokenPairView(TokenObtainPairView):
permission_classes = (AllowAny,)
serializer_class = MyTokenObtainPairSerializer


def user_login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
user = authenticate(request, username=cd['username'], password=cd['password'])
if user is not None:
if user.is_active:
login(request, user)
return HttpResponse("Logged in successfully")

else:
return HttpResponse("Disabled account")

else:
return HttpResponse("Invalid credentials")

else:
form = LoginForm()

return render(request, 'account/login.html', {'form': form})
136 changes: 96 additions & 40 deletions apps/core/templates/base.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions apps/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from apps.store.models import Product
from apps.store.models import BannerHome, TanilganBrendlar, FooterPayBrands


def index(request):
return render(request, 'index.html')


def frontpage(request):
products = Product.objects.all()
is_featured_products = Product.objects.filter(is_featured=True)
Expand All @@ -21,13 +26,12 @@ def frontpage(request):
'brand_image': brand_image,
'popular_products': popular_products,
'recently_viewed_products': recently_viewed_products,

}

return render(request, 'frontpage.html', context)



def contact(request):
return render(request, 'contact.html')

Expand Down
26 changes: 21 additions & 5 deletions datashop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
SECRET_KEY = os.getenv("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True

ALLOWED_HOSTS = ["datashop.uz", "www.datashop.uz", ".datashop.uz", "localhost", "127.0.0.1"]

Expand Down Expand Up @@ -61,7 +61,10 @@
'apps.order',
'apps.store',
'apps.tgbot',
'users',

'apps.auth',

'rest_framework',

]

Expand All @@ -80,7 +83,9 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
BASE_DIR / 'frontend/build'
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -155,7 +160,7 @@
STATIC_ROOT = BASE_DIR / 'staticfiles'

STATICFILES_DIRS = [
BASE_DIR / "static"
BASE_DIR / "frontend/build/static"
]

MEDIA_URL = 'media/'
Expand All @@ -180,4 +185,15 @@

REDIS_HOST = '127.0.0.1'
REDIS_PORT = 6379
REDIS_DB = 1
REDIS_DB = 1

# Rest Framework

REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': [
'django_filters.rest_framework.DjangoFilterBackend'
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
}
26 changes: 21 additions & 5 deletions datashop/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,35 @@
from django.conf import settings


# rest api imports
from reviews.views import ProductViewSet, ImageViewSet
from rest_framework.routers import DefaultRouter


from apps.cart.views import cart_detail
from apps.core.views import frontpage, contact, about, login, auth
from apps.core.views import frontpage, contact, about, index
from apps.store.views import product_detail, category_detail, product_list, product_list_colm, search

from apps.store.api import api_add_to_cart, api_remove_from_cart, api_checkout

# rest routers

router = DefaultRouter()
router.register(r'product', ProductViewSet, basename='Product')
router.register(r'image', ImageViewSet, basename='Image')


urlpatterns = [
path('', frontpage, name='frontpage'),
path('', index, name='frontpage'),
path('search/', search, name='search'),
path('cart/', cart_detail, name='cart'),
path('contact/', contact, name='contact'),
path('about/', about, name='about'),
path('login/', login, name='login'),
path('auth/', auth, name='auth'),
# path('account/', include('auth.urls')),
path('auth/', include('auth.urls')),
path('yangi-mahsulotlar/', product_list, name='product_list'),
path('yangi-mahsulotlar-colm/', product_list_colm, name='product_list_colm'),
path('frontpage/', frontpage, name='frontpage'),
path('admin/', admin.site.urls),

# API
Expand All @@ -51,4 +64,7 @@

re_path(r'^ckeditor/', include('ckeditor_uploader.urls')), # The CKEditor path

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading