Skip to content

Commit

Permalink
Merge pull request #3 from CrzyHAX91/local_changes
Browse files Browse the repository at this point in the history
Local changes
  • Loading branch information
CrzyHAX91 authored Nov 21, 2024
2 parents 3b80185 + bb664ed commit e161baf
Show file tree
Hide file tree
Showing 45 changed files with 86 additions and 23 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed db.sqlite3
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion manage.py → dropship_project/manage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dropship_project.settings')
try:
from django.core.management import execute_from_command_line
Expand All @@ -15,5 +17,6 @@ def main():
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
59 changes: 59 additions & 0 deletions dropship_project/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.contrib.auth.models import AbstractUser
from django.db import models

class CustomUser(AbstractUser):
phone_number = models.CharField(max_length=15, blank=True, null=True)
address = models.TextField(blank=True, null=True)
date_of_birth = models.DateField(blank=True, null=True)

def __str__(self):
return self.email

class Category(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField(unique=True)

def __str__(self):
return self.name

class Product(models.Model):
name = models.CharField(max_length=200)
description = models.TextField()
price = models.DecimalField(max_digits=10, decimal_places=2)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
stock = models.PositiveIntegerField()

def __str__(self):
return self.name

class Order(models.Model):
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
total_price = models.DecimalField(max_digits=10, decimal_places=2)
status = models.CharField(max_length=20, default='pending')

def __str__(self):
return f"Order {self.id} by {self.user.username}"

class CartItem(models.Model):
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=1)

def __str__(self):
return f"{self.quantity} x {self.product.name}"


from django.utils.crypto import get_random_string

class EmailVerificationToken(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
token = models.CharField(max_length=64, unique=True)
created_at = models.DateTimeField(auto_now_add=True)

@classmethod
def create_token(cls, user):
token = get_random_string(64)
return cls.objects.create(user=user, token=token)

1 change: 0 additions & 1 deletion requirements.txt → dropship_project/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ charset-normalizer
click
comm
cryptography
dbus-python
debugpy
decorator
defusedxml
Expand Down
File renamed without changes.
18 changes: 16 additions & 2 deletions settings.py → dropship_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
SECURE_HSTS_PRELOAD = True

INSTALLED_APPS = [
'django_recaptcha',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand All @@ -30,7 +31,7 @@
'django.contrib.sites',
'rest_framework',
'oauth2_provider',
'dropship_project.api',
'dropship_project',
'django_otp',
'django_otp.plugins.otp_static',
'django_otp.plugins.otp_totp',
Expand All @@ -43,7 +44,7 @@
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.github',
'axes',
'captcha',
'django_recaptcha',
]

REST_FRAMEWORK = {
Expand Down Expand Up @@ -193,3 +194,16 @@
},
}
# Test change

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware',
'axes.middleware.AxesMiddleware',
]

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 7 additions & 9 deletions views.py → dropship_project/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import logging
from django.shortcuts import render, redirect
from django.contrib.auth import login, authenticate, update_session_auth_hash
Expand All @@ -17,11 +16,14 @@
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.contrib.auth.views import PasswordResetView, LoginView
from ratelimit.decorators import ratelimit
from .models import Product, Order, EmailVerificationToken, CustomUser
from django_ratelimit.decorators import ratelimit

from .models import Product, Order, CustomUser
from .serializers import ProductSerializer, OrderSerializer
from .forms import UserRegistrationForm, CustomPasswordChangeForm, UserProfileForm, CustomAuthenticationForm

logger = logging.getLogger('dropship')

@login_required
@sensitive_post_parameters()
@csrf_protect
Expand Down Expand Up @@ -55,8 +57,6 @@ def user_profile(request):
form = UserProfileForm(instance=request.user)
return render(request, 'user_profile.html', {'form': form})

logger = logging.getLogger('dropship')

class RateLimitedLoginView(LoginView):
authentication_form = CustomAuthenticationForm

Expand Down Expand Up @@ -97,6 +97,7 @@ def register(request):
user = form.save(commit=False)
user.is_active = False
user.save()
from .models import EmailVerificationToken
token = EmailVerificationToken.create_token(user)
current_site = get_current_site(request)
subject = 'Activate Your Account'
Expand All @@ -119,6 +120,7 @@ def activate_account(request, uidb64, token):
try:
uid = force_str(urlsafe_base64_decode(uidb64))
user = CustomUser.objects.get(pk=uid)
from .models import EmailVerificationToken
token_obj = EmailVerificationToken.objects.get(user=user, token=token)
except (TypeError, ValueError, OverflowError, CustomUser.DoesNotExist, EmailVerificationToken.DoesNotExist):
user = None
Expand All @@ -135,14 +137,10 @@ def activate_account(request, uidb64, token):
logger.warning(f"Invalid account activation attempt: {uidb64}")
return render(request, 'registration/activation_invalid.html')

from oauth2_provider.contrib.rest_framework import TokenHasReadWriteScope, TokenHasScope

class ProductViewSet(viewsets.ModelViewSet):
queryset = Product.objects.all()
serializer_class = ProductSerializer
permission_classes = [TokenHasReadWriteScope]

class OrderViewSet(viewsets.ModelViewSet):
queryset = Order.objects.all()
serializer_class = OrderSerializer
permission_classes = [TokenHasReadWriteScope]
10 changes: 0 additions & 10 deletions models.py

This file was deleted.

0 comments on commit e161baf

Please sign in to comment.