mirror of
https://github.com/lemeow125/DRF_Template.git
synced 2024-11-17 04:09:25 +08:00
Initial commit
This commit is contained in:
commit
0ad426398a
25 changed files with 2648 additions and 0 deletions
172
.gitignore
vendored
Normal file
172
.gitignore
vendored
Normal file
|
@ -0,0 +1,172 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Static Media Stuff
|
||||
equipment_tracker/media/*
|
||||
equipment_tracker/static/*
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
backend/db.sqlite3
|
||||
backend/.env
|
||||
backend/static/*
|
||||
backend/static/
|
||||
backend/media/
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
**/__pycache__/
|
28
Dockerfile
Normal file
28
Dockerfile
Normal file
|
@ -0,0 +1,28 @@
|
|||
ARG DOCKER_PLATFORM=$TARGETPLATFORM
|
||||
FROM --platform=$DOCKER_PLATFORM python:3.11.4-bookworm
|
||||
|
||||
ENV PYTHONBUFFERED 1
|
||||
|
||||
# Create directory
|
||||
RUN mkdir /code
|
||||
|
||||
# Set the working directory to /code
|
||||
WORKDIR /code
|
||||
|
||||
# Mirror the current directory to the working directory for hotreloading
|
||||
ADD . /code/
|
||||
|
||||
# Install pipenv
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Make migrations
|
||||
RUN python backend/manage.py makemigrations
|
||||
|
||||
# Run custom migrate
|
||||
RUN python backend/manage.py migrate
|
||||
|
||||
# Generate DRF Spectacular Documentation
|
||||
RUN python backend/manage.py spectacular --color --file backend/schema.yml
|
||||
|
||||
# Expose port 8000 for the web server
|
||||
EXPOSE 8000
|
24
Pipfile
Normal file
24
Pipfile
Normal file
|
@ -0,0 +1,24 @@
|
|||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
django = "*"
|
||||
djangorestframework = "*"
|
||||
python-dotenv = "*"
|
||||
whitenoise = "*"
|
||||
djoser = "*"
|
||||
django-cors-headers = "*"
|
||||
drf-spectacular = {version = "*", extras = ["sidecar"]}
|
||||
django-extra-fields = "*"
|
||||
pillow = "*"
|
||||
psycopg2 = "*"
|
||||
django-simple-history = "*"
|
||||
django-unfold = "*"
|
||||
django-resized = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.11"
|
1080
Pipfile.lock
generated
Normal file
1080
Pipfile.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
21
backend/.env.sample
Normal file
21
backend/.env.sample
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Django
|
||||
SECRET_KEY = ""
|
||||
|
||||
# Superuser Credentials
|
||||
DJANGO_ADMIN_USERNAME = ""
|
||||
DJANGO_ADMIN_EMAIL = ""
|
||||
DJANGO_ADMIN_PASSWORD = ""
|
||||
|
||||
# Production Email Credentials
|
||||
PROD_EMAIL_HOST = ""
|
||||
PROD_EMAIL_HOST_USER = ""
|
||||
PROD_EMAIL_HOST_PASSWORD = ""
|
||||
PROD_EMAIL_PORT = ""
|
||||
PROD_EMAIL_TLS = ""
|
||||
|
||||
|
||||
# Dev Email Credentials
|
||||
DEV_EMAIL_HOST = ""
|
||||
DEV_EMAIL_HOST_USER = ""
|
||||
DEV_EMAIL_HOST_PASSWORD = ""
|
||||
DEV_EMAIL_PORT = ""
|
0
backend/accounts/__init__.py
Normal file
0
backend/accounts/__init__.py
Normal file
16
backend/accounts/admin.py
Normal file
16
backend/accounts/admin.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from .models import CustomUser
|
||||
|
||||
|
||||
class CustomUserAdmin(UserAdmin):
|
||||
model = CustomUser
|
||||
list_display = ('id',) + UserAdmin.list_display
|
||||
# Editable fields per instance
|
||||
fieldsets = UserAdmin.fieldsets + (
|
||||
(None, {'fields': ('avatar',)}),
|
||||
)
|
||||
|
||||
|
||||
admin.site.register(CustomUser, CustomUserAdmin)
|
6
backend/accounts/apps.py
Normal file
6
backend/accounts/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'accounts'
|
45
backend/accounts/migrations/0001_initial.py
Normal file
45
backend/accounts/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
# Generated by Django 5.0.1 on 2024-01-06 04:09
|
||||
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CustomUser',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
||||
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
|
||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('avatar', models.ImageField(null=True, upload_to='avatars/')),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
'verbose_name_plural': 'users',
|
||||
'abstract': False,
|
||||
},
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
]
|
0
backend/accounts/migrations/__init__.py
Normal file
0
backend/accounts/migrations/__init__.py
Normal file
87
backend/accounts/models.py
Normal file
87
backend/accounts/models.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.urls import reverse
|
||||
from django.db.models.signals import post_migrate
|
||||
from django.dispatch import receiver
|
||||
from django_resized import ResizedImageField
|
||||
import os
|
||||
|
||||
|
||||
class CustomUser(AbstractUser):
|
||||
# first_name inherited from base user class
|
||||
# last_name inherited from base user class
|
||||
# email inherited from base user class
|
||||
# username inherited from base user class
|
||||
# password inherited from base user class
|
||||
# is_admin inherited from base user class
|
||||
|
||||
avatar = models.ImageField(
|
||||
null=True, upload_to='avatars/')
|
||||
|
||||
def avatar_url(self):
|
||||
# Assuming your media root is set to 'media/'
|
||||
return f'/api/v1/media/avatars/{self.avatar.name}'
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
@property
|
||||
def admin_url(self):
|
||||
return reverse('admin:users_customuser_change', args=(self.pk,))
|
||||
|
||||
def get_prep_value(self, value):
|
||||
# Get the original filename without the random string
|
||||
original_filename = self.avatar.field.storage.name(self.avatar.path)
|
||||
return original_filename
|
||||
pass
|
||||
|
||||
|
||||
@receiver(post_migrate)
|
||||
def create_superuser(sender, **kwargs):
|
||||
if sender.name == 'accounts':
|
||||
# Add test users here if needed
|
||||
# They will automatically be created after migrating the db
|
||||
users = [
|
||||
# Superadmin Account
|
||||
{
|
||||
'username': os.getenv('DJANGO_ADMIN_USERNAME'),
|
||||
'email': os.getenv('DJANGO_ADMIN_EMAIL'),
|
||||
'password': os.getenv('DJANGO_ADMIN_PASSWORD'),
|
||||
'is_staff': True,
|
||||
'is_superuser': True,
|
||||
'first_name': 'Super',
|
||||
'last_name': 'Admin'
|
||||
},
|
||||
# Debug User
|
||||
{
|
||||
'username': 'debug-user',
|
||||
'email': os.getenv('DJANGO_ADMIN_EMAIL'),
|
||||
'password': os.getenv('DJANGO_ADMIN_PASSWORD'),
|
||||
'is_staff': False,
|
||||
'is_superuser': False,
|
||||
'first_name': "Test",
|
||||
'last_name': "User"
|
||||
},
|
||||
]
|
||||
|
||||
for user in users:
|
||||
if not CustomUser.objects.filter(username=user['username']).exists():
|
||||
if (user['is_superuser']):
|
||||
USER = CustomUser.objects.create_superuser(
|
||||
username=user['username'],
|
||||
password=user['password'],
|
||||
email=user['email'],
|
||||
)
|
||||
print('Created Superuser:', user['username'])
|
||||
else:
|
||||
USER = CustomUser.objects.create_user(
|
||||
username=user['username'],
|
||||
password=user['password'],
|
||||
email=user['email'],
|
||||
)
|
||||
print('Created User:', user['username'])
|
||||
USER.first_name = user['first_name']
|
||||
USER.last_name = user['last_name']
|
||||
USER.is_active = True
|
||||
USER.save()
|
53
backend/accounts/serializers.py
Normal file
53
backend/accounts/serializers.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer
|
||||
from djoser.serializers import UserSerializer as BaseUserSerializer
|
||||
from django.core import exceptions as django_exceptions
|
||||
from rest_framework import serializers
|
||||
from accounts.models import CustomUser
|
||||
from rest_framework.settings import api_settings
|
||||
from django.contrib.auth.password_validation import validate_password
|
||||
from django.utils.encoding import smart_str
|
||||
from drf_spectacular.utils import extend_schema_field
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
from drf_extra_fields.fields import Base64ImageField
|
||||
|
||||
# There can be multiple subject instances with the same name, only differing in course, year level, and semester. We filter them here
|
||||
|
||||
|
||||
class CustomUserSerializer(BaseUserSerializer):
|
||||
avatar = Base64ImageField()
|
||||
|
||||
class Meta(BaseUserSerializer.Meta):
|
||||
model = CustomUser
|
||||
fields = ('id', 'username', 'email', 'avatar', 'first_name',
|
||||
'last_name')
|
||||
|
||||
|
||||
class UserRegistrationSerializer(serializers.ModelSerializer):
|
||||
email = serializers.EmailField(required=True)
|
||||
password = serializers.CharField(
|
||||
write_only=True, style={'input_type': 'password', 'placeholder': 'Password'})
|
||||
|
||||
class Meta:
|
||||
model = CustomUser # Use your custom user model here
|
||||
fields = ('username', 'email', 'password', 'avatar',
|
||||
'first_name', 'last_name')
|
||||
|
||||
def validate(self, attrs):
|
||||
user = self.Meta.model(**attrs)
|
||||
password = attrs.get("password")
|
||||
try:
|
||||
validate_password(password, user)
|
||||
except django_exceptions.ValidationError as e:
|
||||
serializer_error = serializers.as_serializer_error(e)
|
||||
raise serializers.ValidationError(
|
||||
{"password": serializer_error[api_settings.NON_FIELD_ERRORS_KEY]}
|
||||
)
|
||||
|
||||
return super().validate(attrs)
|
||||
|
||||
def create(self, validated_data):
|
||||
user = self.Meta.model(**validated_data)
|
||||
user.set_password(validated_data['password'])
|
||||
user.save()
|
||||
|
||||
return user
|
7
backend/accounts/urls.py
Normal file
7
backend/accounts/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('', include('djoser.urls')),
|
||||
path('', include('djoser.urls.jwt')),
|
||||
]
|
5
backend/accounts/views.py
Normal file
5
backend/accounts/views.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import generics
|
||||
from accounts.serializers import CustomUserSerializer
|
||||
from rest_framework.response import Response
|
||||
from accounts.models import CustomUser
|
0
backend/api/__init__.py
Normal file
0
backend/api/__init__.py
Normal file
14
backend/api/urls.py
Normal file
14
backend/api/urls.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from django.urls import path, include
|
||||
from config import settings
|
||||
urlpatterns = [
|
||||
path('accounts/', include('accounts.urls')),
|
||||
|
||||
]
|
||||
if settings.DEBUG:
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from django.conf.urls.static import static
|
||||
|
||||
# Media files
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
urlpatterns += static(
|
||||
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
0
backend/config/__init__.py
Normal file
0
backend/config/__init__.py
Normal file
16
backend/config/asgi.py
Normal file
16
backend/config/asgi.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
ASGI config for equipment_tracker project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_asgi_application()
|
227
backend/config/settings.py
Normal file
227
backend/config/settings.py
Normal file
|
@ -0,0 +1,227 @@
|
|||
"""
|
||||
Django settings for test backend project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.6.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv # Python dotenv
|
||||
import os
|
||||
|
||||
load_dotenv() # loads the configs from .env
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = str(os.getenv('SECRET_KEY'))
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
CSRF_TRUSTED_ORIGINS = ["https://testing.keannu1.duckdns.org"]
|
||||
|
||||
# Email credentials
|
||||
EMAIL_HOST = ''
|
||||
EMAIL_HOST_USER = ''
|
||||
EMAIL_HOST_PASSWORD = ''
|
||||
EMAIL_PORT = ''
|
||||
EMAIL_USE_TLS = False
|
||||
|
||||
if (DEBUG == True):
|
||||
EMAIL_HOST = str(os.getenv('DEV_EMAIL_HOST'))
|
||||
EMAIL_HOST_USER = str(os.getenv('DEV_EMAIL_HOST_USER'))
|
||||
EMAIL_HOST_PASSWORD = str(os.getenv('DEV_EMAIL_HOST_PASSWORD'))
|
||||
EMAIL_PORT = str(os.getenv('DEV_EMAIL_PORT'))
|
||||
else:
|
||||
EMAIL_HOST = str(os.getenv('PROD_EMAIL_HOST'))
|
||||
EMAIL_HOST_USER = str(os.getenv('PROD_EMAIL_HOST_USER'))
|
||||
EMAIL_HOST_PASSWORD = str(os.getenv('PROD_EMAIL_HOST_PASSWORD'))
|
||||
EMAIL_PORT = str(os.getenv('PROD_EMAIL_PORT'))
|
||||
EMAIL_USE_TLS = str(os.getenv('PROD_EMAIL_TLS'))
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'unfold',
|
||||
'unfold.contrib.simple_history',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'rest_framework_simplejwt',
|
||||
'simple_history',
|
||||
'djoser',
|
||||
'corsheaders',
|
||||
'drf_spectacular',
|
||||
'drf_spectacular_sidecar',
|
||||
'accounts',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
"whitenoise.middleware.WhiteNoiseMiddleware",
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
"corsheaders.middleware.CorsMiddleware",
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||
MEDIA_URL = 'api/v1/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
ROOT_URLCONF = 'config.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||
),
|
||||
'DEFAULT_THROTTLE_CLASSES': [
|
||||
|
||||
'rest_framework.throttling.AnonRateThrottle',
|
||||
|
||||
'rest_framework.throttling.UserRateThrottle'
|
||||
|
||||
],
|
||||
|
||||
'DEFAULT_THROTTLE_RATES': {
|
||||
|
||||
'anon': '360/min',
|
||||
|
||||
'user': '1440/min'
|
||||
|
||||
},
|
||||
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
|
||||
}
|
||||
|
||||
# DRF-Spectacular
|
||||
SPECTACULAR_SETTINGS = {
|
||||
'TITLE': 'Test Backend',
|
||||
'DESCRIPTION': 'A Project by Keannu Bernasol',
|
||||
'VERSION': '1.0.0',
|
||||
'SERVE_INCLUDE_SCHEMA': False,
|
||||
'SWAGGER_UI_DIST': 'SIDECAR',
|
||||
'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',
|
||||
'REDOC_DIST': 'SIDECAR',
|
||||
# OTHER SETTINGS
|
||||
}
|
||||
|
||||
WSGI_APPLICATION = 'config.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
AUTH_USER_MODEL = 'accounts.CustomUser'
|
||||
|
||||
DJOSER = {
|
||||
'SEND_ACTIVATION_EMAIL': True,
|
||||
'SEND_CONFIRMATION_EMAIL': True,
|
||||
'PASSWORD_RESET_CONFIRM_URL': 'reset_password_confirm/{uid}/{token}',
|
||||
'ACTIVATION_URL': 'activation/{uid}/{token}',
|
||||
'USER_AUTHENTICATION_RULES': ['djoser.authentication.TokenAuthenticationRule'],
|
||||
'SERIALIZERS': {
|
||||
'user': 'accounts.serializers.CustomUserSerializer',
|
||||
'current_user': 'accounts.serializers.CustomUserSerializer',
|
||||
'user_create': 'accounts.serializers.UserRegistrationSerializer',
|
||||
},
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'Asia/Manila'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
DOMAIN = 'testing.keannu1.duckdns.org/#'
|
||||
|
||||
SITE_NAME = 'Test Backend'
|
||||
|
||||
# 1 week access token lifetime
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=10080),
|
||||
"REFRESH_TOKEN_LIFETIME": timedelta(minutes=10080)
|
||||
}
|
||||
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
||||
SESSION_CACHE_ALIAS = "default"
|
||||
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
CORS_ALLOW_CREDENTIALS = True
|
29
backend/config/urls.py
Normal file
29
backend/config/urls.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
"""
|
||||
URL configuration for equipment_tracker project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/v1/', include('api.urls')),
|
||||
path('schema/', SpectacularAPIView.as_view(), name='schema'),
|
||||
path('swagger/',
|
||||
SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
||||
path('redoc/',
|
||||
SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
||||
]
|
16
backend/config/wsgi.py
Normal file
16
backend/config/wsgi.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for equipment_tracker project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_wsgi_application()
|
22
backend/manage.py
Normal file
22
backend/manage.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/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', 'config.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
713
backend/schema.yml
Normal file
713
backend/schema.yml
Normal file
|
@ -0,0 +1,713 @@
|
|||
openapi: 3.0.3
|
||||
info:
|
||||
title: Test Backend
|
||||
version: 1.0.0
|
||||
description: A Project by Keannu Bernasol
|
||||
paths:
|
||||
/api/v1/accounts/jwt/create/:
|
||||
post:
|
||||
operationId: api_v1_accounts_jwt_create_create
|
||||
description: |-
|
||||
Takes a set of user credentials and returns an access and refresh JSON web
|
||||
token pair to prove the authentication of those credentials.
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenObtainPair'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenObtainPair'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenObtainPair'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenObtainPair'
|
||||
description: ''
|
||||
/api/v1/accounts/jwt/refresh/:
|
||||
post:
|
||||
operationId: api_v1_accounts_jwt_refresh_create
|
||||
description: |-
|
||||
Takes a refresh type JSON web token and returns an access type JSON web
|
||||
token if the refresh token is valid.
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenRefresh'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenRefresh'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenRefresh'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenRefresh'
|
||||
description: ''
|
||||
/api/v1/accounts/jwt/verify/:
|
||||
post:
|
||||
operationId: api_v1_accounts_jwt_verify_create
|
||||
description: |-
|
||||
Takes a token and indicates if it is valid. This view provides no
|
||||
information about a token's fitness for a particular use.
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenVerify'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenVerify'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenVerify'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TokenVerify'
|
||||
description: ''
|
||||
/api/v1/accounts/users/:
|
||||
get:
|
||||
operationId: api_v1_accounts_users_list
|
||||
tags:
|
||||
- api
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
description: ''
|
||||
post:
|
||||
operationId: api_v1_accounts_users_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UserRegistration'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UserRegistration'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UserRegistration'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
- {}
|
||||
responses:
|
||||
'201':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UserRegistration'
|
||||
description: ''
|
||||
/api/v1/accounts/users/{id}/:
|
||||
get:
|
||||
operationId: api_v1_accounts_users_retrieve
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
description: A unique integer value identifying this user.
|
||||
required: true
|
||||
tags:
|
||||
- api
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
description: ''
|
||||
put:
|
||||
operationId: api_v1_accounts_users_update
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
description: A unique integer value identifying this user.
|
||||
required: true
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
description: ''
|
||||
patch:
|
||||
operationId: api_v1_accounts_users_partial_update
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
description: A unique integer value identifying this user.
|
||||
required: true
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PatchedCustomUser'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PatchedCustomUser'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PatchedCustomUser'
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
description: ''
|
||||
delete:
|
||||
operationId: api_v1_accounts_users_destroy
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
description: A unique integer value identifying this user.
|
||||
required: true
|
||||
tags:
|
||||
- api
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'204':
|
||||
description: No response body
|
||||
/api/v1/accounts/users/activation/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_activation_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Activation'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Activation'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Activation'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
- {}
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Activation'
|
||||
description: ''
|
||||
/api/v1/accounts/users/me/:
|
||||
get:
|
||||
operationId: api_v1_accounts_users_me_retrieve
|
||||
tags:
|
||||
- api
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
description: ''
|
||||
put:
|
||||
operationId: api_v1_accounts_users_me_update
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
description: ''
|
||||
patch:
|
||||
operationId: api_v1_accounts_users_me_partial_update
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PatchedCustomUser'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PatchedCustomUser'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PatchedCustomUser'
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CustomUser'
|
||||
description: ''
|
||||
delete:
|
||||
operationId: api_v1_accounts_users_me_destroy
|
||||
tags:
|
||||
- api
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'204':
|
||||
description: No response body
|
||||
/api/v1/accounts/users/resend_activation/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_resend_activation_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
- {}
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
description: ''
|
||||
/api/v1/accounts/users/reset_password/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_reset_password_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
- {}
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
description: ''
|
||||
/api/v1/accounts/users/reset_password_confirm/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_reset_password_confirm_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PasswordResetConfirm'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PasswordResetConfirm'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PasswordResetConfirm'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
- {}
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PasswordResetConfirm'
|
||||
description: ''
|
||||
/api/v1/accounts/users/reset_username/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_reset_username_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
- {}
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SendEmailReset'
|
||||
description: ''
|
||||
/api/v1/accounts/users/reset_username_confirm/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_reset_username_confirm_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UsernameResetConfirm'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UsernameResetConfirm'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UsernameResetConfirm'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
- {}
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UsernameResetConfirm'
|
||||
description: ''
|
||||
/api/v1/accounts/users/set_password/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_set_password_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetPassword'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetPassword'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetPassword'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetPassword'
|
||||
description: ''
|
||||
/api/v1/accounts/users/set_username/:
|
||||
post:
|
||||
operationId: api_v1_accounts_users_set_username_create
|
||||
tags:
|
||||
- api
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetUsername'
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetUsername'
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetUsername'
|
||||
required: true
|
||||
security:
|
||||
- jwtAuth: []
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SetUsername'
|
||||
description: ''
|
||||
components:
|
||||
schemas:
|
||||
Activation:
|
||||
type: object
|
||||
properties:
|
||||
uid:
|
||||
type: string
|
||||
token:
|
||||
type: string
|
||||
required:
|
||||
- token
|
||||
- uid
|
||||
CustomUser:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
readOnly: true
|
||||
username:
|
||||
type: string
|
||||
readOnly: true
|
||||
description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
|
||||
only.
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
title: Email address
|
||||
maxLength: 254
|
||||
avatar:
|
||||
type: string
|
||||
format: uri
|
||||
first_name:
|
||||
type: string
|
||||
maxLength: 150
|
||||
last_name:
|
||||
type: string
|
||||
maxLength: 150
|
||||
required:
|
||||
- avatar
|
||||
- id
|
||||
- username
|
||||
PasswordResetConfirm:
|
||||
type: object
|
||||
properties:
|
||||
uid:
|
||||
type: string
|
||||
token:
|
||||
type: string
|
||||
new_password:
|
||||
type: string
|
||||
required:
|
||||
- new_password
|
||||
- token
|
||||
- uid
|
||||
PatchedCustomUser:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
readOnly: true
|
||||
username:
|
||||
type: string
|
||||
readOnly: true
|
||||
description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
|
||||
only.
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
title: Email address
|
||||
maxLength: 254
|
||||
avatar:
|
||||
type: string
|
||||
format: uri
|
||||
first_name:
|
||||
type: string
|
||||
maxLength: 150
|
||||
last_name:
|
||||
type: string
|
||||
maxLength: 150
|
||||
SendEmailReset:
|
||||
type: object
|
||||
properties:
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
required:
|
||||
- email
|
||||
SetPassword:
|
||||
type: object
|
||||
properties:
|
||||
new_password:
|
||||
type: string
|
||||
current_password:
|
||||
type: string
|
||||
required:
|
||||
- current_password
|
||||
- new_password
|
||||
SetUsername:
|
||||
type: object
|
||||
properties:
|
||||
current_password:
|
||||
type: string
|
||||
new_username:
|
||||
type: string
|
||||
title: Username
|
||||
description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
|
||||
only.
|
||||
pattern: ^[\w.@+-]+$
|
||||
maxLength: 150
|
||||
required:
|
||||
- current_password
|
||||
- new_username
|
||||
TokenObtainPair:
|
||||
type: object
|
||||
properties:
|
||||
username:
|
||||
type: string
|
||||
writeOnly: true
|
||||
password:
|
||||
type: string
|
||||
writeOnly: true
|
||||
access:
|
||||
type: string
|
||||
readOnly: true
|
||||
refresh:
|
||||
type: string
|
||||
readOnly: true
|
||||
required:
|
||||
- access
|
||||
- password
|
||||
- refresh
|
||||
- username
|
||||
TokenRefresh:
|
||||
type: object
|
||||
properties:
|
||||
access:
|
||||
type: string
|
||||
readOnly: true
|
||||
refresh:
|
||||
type: string
|
||||
writeOnly: true
|
||||
required:
|
||||
- access
|
||||
- refresh
|
||||
TokenVerify:
|
||||
type: object
|
||||
properties:
|
||||
token:
|
||||
type: string
|
||||
writeOnly: true
|
||||
required:
|
||||
- token
|
||||
UserRegistration:
|
||||
type: object
|
||||
properties:
|
||||
username:
|
||||
type: string
|
||||
description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
|
||||
only.
|
||||
pattern: ^[\w.@+-]+$
|
||||
maxLength: 150
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
password:
|
||||
type: string
|
||||
writeOnly: true
|
||||
avatar:
|
||||
type: string
|
||||
format: uri
|
||||
nullable: true
|
||||
first_name:
|
||||
type: string
|
||||
maxLength: 150
|
||||
last_name:
|
||||
type: string
|
||||
maxLength: 150
|
||||
required:
|
||||
- email
|
||||
- password
|
||||
- username
|
||||
UsernameResetConfirm:
|
||||
type: object
|
||||
properties:
|
||||
new_username:
|
||||
type: string
|
||||
title: Username
|
||||
description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
|
||||
only.
|
||||
pattern: ^[\w.@+-]+$
|
||||
maxLength: 150
|
||||
required:
|
||||
- new_username
|
||||
securitySchemes:
|
||||
jwtAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
24
docker-compose.yml
Normal file
24
docker-compose.yml
Normal file
|
@ -0,0 +1,24 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
# Django App
|
||||
django_backend:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: dmca_backend:latest
|
||||
ports:
|
||||
- "8092:8000"
|
||||
environment:
|
||||
- PYTHONBUFFERED=1
|
||||
command:
|
||||
[
|
||||
"sh",
|
||||
"-c",
|
||||
"python backend/manage.py spectacular --color --file backend/schema.yml && python backend/manage.py collectstatic --noinput && python backend/manage.py makemigrations && python backend/manage.py migrate && python backend/manage.py runserver 127.0.0.1:8000",
|
||||
]
|
||||
volumes:
|
||||
- .:/code # For hotreloading
|
||||
|
||||
volumes:
|
||||
dmca_backend:
|
43
requirements.txt
Normal file
43
requirements.txt
Normal file
|
@ -0,0 +1,43 @@
|
|||
-i https://pypi.org/simple
|
||||
asgiref==3.7.2; python_version >= '3.7'
|
||||
attrs==23.1.0; python_version >= '3.7'
|
||||
certifi==2023.11.17; python_version >= '3.6'
|
||||
cffi==1.16.0; python_version >= '3.8'
|
||||
charset-normalizer==3.3.2; python_full_version >= '3.7.0'
|
||||
cryptography==41.0.7; python_version >= '3.7'
|
||||
defusedxml==0.8.0rc2; python_version >= '3.6'
|
||||
django==4.2.7
|
||||
django-cors-headers==4.3.1
|
||||
django-extra-fields==3.0.2
|
||||
django-simple-history==3.4.0
|
||||
django-templated-mail==1.1.1
|
||||
django-unfold==0.17.1
|
||||
djangorestframework==3.14.0
|
||||
djangorestframework-simplejwt==5.3.0; python_version >= '3.7'
|
||||
djoser==2.2.2
|
||||
drf-spectacular[sidecar]==0.26.5
|
||||
drf-spectacular-sidecar==2023.10.1
|
||||
idna==3.6; python_version >= '3.5'
|
||||
inflection==0.5.1; python_version >= '3.5'
|
||||
jsonschema==4.20.0; python_version >= '3.8'
|
||||
jsonschema-specifications==2023.11.2; python_version >= '3.8'
|
||||
oauthlib==3.2.2; python_version >= '3.6'
|
||||
pillow==10.1.0
|
||||
psycopg2==2.9.9
|
||||
pycparser==2.21
|
||||
pyjwt==2.8.0; python_version >= '3.7'
|
||||
python-dotenv==1.0.0
|
||||
python3-openid==3.2.0
|
||||
pytz==2023.3.post1
|
||||
pyyaml==6.0.1; python_version >= '3.6'
|
||||
referencing==0.31.1; python_version >= '3.8'
|
||||
requests==2.31.0; python_version >= '3.7'
|
||||
requests-oauthlib==1.3.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
||||
rpds-py==0.13.2; python_version >= '3.8'
|
||||
social-auth-app-django==5.4.0; python_version >= '3.8'
|
||||
social-auth-core==4.5.1; python_version >= '3.8'
|
||||
sqlparse==0.4.4; python_version >= '3.5'
|
||||
tzdata==2023.3; sys_platform == 'win32'
|
||||
uritemplate==4.1.1; python_version >= '3.6'
|
||||
urllib3==2.1.0; python_version >= '3.8'
|
||||
whitenoise==6.6.0
|
Loading…
Reference in a new issue