feat: add DummyAuthentication for development and include startup script for server management
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 37s
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 37s
This commit is contained in:
parent
1fc0838594
commit
aa26522f9d
3 changed files with 25 additions and 2 deletions
|
|
@ -1,5 +1,17 @@
|
||||||
from rest_framework.authentication import SessionAuthentication
|
from rest_framework.authentication import SessionAuthentication, BaseAuthentication
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from .models import SupplierProfile
|
||||||
|
|
||||||
class CsrfExemptSessionAuthentication(SessionAuthentication):
|
class CsrfExemptSessionAuthentication(SessionAuthentication):
|
||||||
def enforce_csrf(self, request):
|
def enforce_csrf(self, request):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
class DummyAuthentication(BaseAuthentication):
|
||||||
|
def authenticate(self, request):
|
||||||
|
user = User.objects.first()
|
||||||
|
if not user:
|
||||||
|
user = User.objects.create_user(username='dummy', email='dummy@example.com', password='password')
|
||||||
|
SupplierProfile.objects.create(user=user)
|
||||||
|
elif not hasattr(user, 'profile'):
|
||||||
|
SupplierProfile.objects.create(user=user)
|
||||||
|
return (user, None)
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ from datetime import timedelta
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
'api.authentication.DummyAuthentication' if DEBUG else 'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||||
),
|
),
|
||||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||||
'PAGE_SIZE': 20,
|
'PAGE_SIZE': 20,
|
||||||
|
|
|
||||||
11
start.sh
Executable file
11
start.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Activate virtual environment if it exists
|
||||||
|
if [ -d "venv" ]; then
|
||||||
|
source venv/bin/activate
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Apply migrations just in case
|
||||||
|
python manage.py migrate
|
||||||
|
|
||||||
|
# Start the Django server
|
||||||
|
python manage.py runserver 0.0.0.0:8000
|
||||||
Loading…
Reference in a new issue