mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-02 11:45:17 +02:00
Refactor user serializers, update Docker configurations, and remove unused Nginx files
This commit is contained in:
parent
84566b8ec1
commit
50dc0424a9
5 changed files with 21 additions and 41 deletions
|
@ -2,23 +2,13 @@ from rest_framework import serializers
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
from adventures.models import Collection
|
from adventures.models import Collection
|
||||||
from dj_rest_auth.serializers import PasswordResetSerializer
|
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
try:
|
|
||||||
from allauth.account import app_settings as allauth_account_settings
|
|
||||||
from allauth.account.adapter import get_adapter
|
|
||||||
from allauth.account.utils import setup_user_email
|
|
||||||
from allauth.socialaccount.models import EmailAddress
|
|
||||||
from allauth.utils import get_username_max_length
|
|
||||||
except ImportError:
|
|
||||||
raise ImportError('allauth needs to be added to INSTALLED_APPS.')
|
|
||||||
|
|
||||||
class ChangeEmailSerializer(serializers.Serializer):
|
class ChangeEmailSerializer(serializers.Serializer):
|
||||||
new_email = serializers.EmailField(required=True)
|
new_email = serializers.EmailField(required=True)
|
||||||
|
@ -37,7 +27,7 @@ from django.contrib.auth import get_user_model
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
UserModel = get_user_model()
|
UserModel = get_user_model()
|
||||||
from dj_rest_auth.serializers import UserDetailsSerializer
|
# from dj_rest_auth.serializers import UserDetailsSerializer
|
||||||
from .models import CustomUser
|
from .models import CustomUser
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
@ -77,9 +67,9 @@ class UserDetailsSerializer(serializers.ModelSerializer):
|
||||||
if hasattr(UserModel, 'public_profile'):
|
if hasattr(UserModel, 'public_profile'):
|
||||||
extra_fields.append('public_profile')
|
extra_fields.append('public_profile')
|
||||||
|
|
||||||
class Meta(UserDetailsSerializer.Meta):
|
class Meta:
|
||||||
model = CustomUser
|
model = CustomUser
|
||||||
fields = UserDetailsSerializer.Meta.fields + ('profile_pic', 'uuid', 'public_profile')
|
fields = ('profile_pic', 'uuid', 'public_profile', 'email', 'date_joined', 'is_staff', 'is_superuser', 'is_active', 'pk')
|
||||||
|
|
||||||
model = UserModel
|
model = UserModel
|
||||||
fields = ('pk', *extra_fields)
|
fields = ('pk', *extra_fields)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
services:
|
services:
|
||||||
web:
|
web:
|
||||||
#build: ./frontend/
|
build: ./frontend/
|
||||||
image: ghcr.io/seanmorley15/adventurelog-frontend:latest
|
#image: ghcr.io/seanmorley15/adventurelog-frontend:latest
|
||||||
container_name: adventurelog-frontend
|
container_name: adventurelog-frontend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
|
@ -14,7 +14,7 @@ services:
|
||||||
- server
|
- server
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgis/postgis:15-3.3
|
image: postgis/postgis:16-3.4
|
||||||
container_name: adventurelog-db
|
container_name: adventurelog-db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
|
@ -25,8 +25,8 @@ services:
|
||||||
- postgres_data:/var/lib/postgresql/data/
|
- postgres_data:/var/lib/postgresql/data/
|
||||||
|
|
||||||
server:
|
server:
|
||||||
#build: ./backend/
|
build: ./backend/
|
||||||
image: ghcr.io/seanmorley15/adventurelog-backend:latest
|
#image: ghcr.io/seanmorley15/adventurelog-backend:latest
|
||||||
container_name: adventurelog-backend
|
container_name: adventurelog-backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
|
@ -39,7 +39,7 @@ services:
|
||||||
- DJANGO_ADMIN_PASSWORD=admin
|
- DJANGO_ADMIN_PASSWORD=admin
|
||||||
- DJANGO_ADMIN_EMAIL=admin@example.com
|
- DJANGO_ADMIN_EMAIL=admin@example.com
|
||||||
- PUBLIC_URL='http://localhost:8016' # Match the outward port, used for the creation of image urls
|
- PUBLIC_URL='http://localhost:8016' # Match the outward port, used for the creation of image urls
|
||||||
- CSRF_TRUSTED_ORIGINS=http://localhost:8016 # Comma separated list of trusted origins for CSRF
|
- CSRF_TRUSTED_ORIGINS=http://localhost:8016,http://localhost:8015 # Comma separated list of trusted origins for CSRF
|
||||||
- DEBUG=False
|
- DEBUG=False
|
||||||
- FRONTEND_URL='http://localhost:8015' # Used for email generation. This should be the url of the frontend
|
- FRONTEND_URL='http://localhost:8015' # Used for email generation. This should be the url of the frontend
|
||||||
ports:
|
ports:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||||
import { redirect, type Actions } from '@sveltejs/kit';
|
import { redirect, type Actions } from '@sveltejs/kit';
|
||||||
import { themes } from '$lib';
|
import { themes } from '$lib';
|
||||||
|
import { fetchCSRFToken } from '$lib/index.server';
|
||||||
|
|
||||||
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||||
|
|
||||||
|
@ -16,23 +17,24 @@ export const actions: Actions = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
logout: async ({ cookies }: { cookies: any }) => {
|
logout: async (event) => {
|
||||||
const cookie = cookies.get('auth') || null;
|
let sessionId = event.cookies.get('sessionid');
|
||||||
|
let csrfToken = await fetchCSRFToken();
|
||||||
|
|
||||||
if (!cookie) {
|
if (!sessionId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(`${serverEndpoint}/auth/logout/`, {
|
const res = await fetch(`${serverEndpoint}/_allauth/browser/v1/auth/session`, {
|
||||||
method: 'POST',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Cookie: cookies.get('auth')
|
Cookie: `sessionid=${sessionId}; csrftoken=${csrfToken}`,
|
||||||
}
|
'X-CSRFToken': csrfToken
|
||||||
|
},
|
||||||
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.status == 401) {
|
||||||
cookies.delete('auth', { path: '/', secure: false });
|
|
||||||
cookies.delete('refresh', { path: '/', secure: false });
|
|
||||||
return redirect(302, '/login');
|
return redirect(302, '/login');
|
||||||
} else {
|
} else {
|
||||||
return redirect(302, '/');
|
return redirect(302, '/');
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
FROM nginx:alpine
|
|
||||||
|
|
||||||
RUN rm /etc/nginx/conf.d/default.conf
|
|
||||||
COPY nginx.conf /etc/nginx/conf.d
|
|
|
@ -1,8 +0,0 @@
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name localhost;
|
|
||||||
|
|
||||||
location /media/ {
|
|
||||||
alias /app/media/;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue