Skip to content

Commit

Permalink
Refactor user serializers, update Docker configurations, and remove u…
Browse files Browse the repository at this point in the history
…nused Nginx files
  • Loading branch information
seanmorley15 committed Dec 1, 2024
1 parent 84566b8 commit 50dc042
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
16 changes: 3 additions & 13 deletions backend/server/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@
from django.contrib.auth import get_user_model

from adventures.models import Collection
from dj_rest_auth.serializers import PasswordResetSerializer

User = 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 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):
new_email = serializers.EmailField(required=True)
Expand All @@ -37,7 +27,7 @@ def validate_new_email(self, value):
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
UserModel = get_user_model()
from dj_rest_auth.serializers import UserDetailsSerializer
# from dj_rest_auth.serializers import UserDetailsSerializer
from .models import CustomUser

from rest_framework import serializers
Expand Down Expand Up @@ -77,9 +67,9 @@ class Meta:
if hasattr(UserModel, 'public_profile'):
extra_fields.append('public_profile')

class Meta(UserDetailsSerializer.Meta):
class Meta:
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
fields = ('pk', *extra_fields)
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
web:
#build: ./frontend/
image: ghcr.io/seanmorley15/adventurelog-frontend:latest
build: ./frontend/
#image: ghcr.io/seanmorley15/adventurelog-frontend:latest
container_name: adventurelog-frontend
restart: unless-stopped
environment:
Expand All @@ -14,7 +14,7 @@ services:
- server

db:
image: postgis/postgis:15-3.3
image: postgis/postgis:16-3.4
container_name: adventurelog-db
restart: unless-stopped
environment:
Expand All @@ -25,8 +25,8 @@ services:
- postgres_data:/var/lib/postgresql/data/

server:
#build: ./backend/
image: ghcr.io/seanmorley15/adventurelog-backend:latest
build: ./backend/
#image: ghcr.io/seanmorley15/adventurelog-backend:latest
container_name: adventurelog-backend
restart: unless-stopped
environment:
Expand All @@ -39,7 +39,7 @@ services:
- DJANGO_ADMIN_PASSWORD=admin
- [email protected]
- 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
- FRONTEND_URL='http://localhost:8015' # Used for email generation. This should be the url of the frontend
ports:
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
import { redirect, type Actions } from '@sveltejs/kit';
import { themes } from '$lib';
import { fetchCSRFToken } from '$lib/index.server';

const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';

Expand All @@ -16,23 +17,24 @@ export const actions: Actions = {
});
}
},
logout: async ({ cookies }: { cookies: any }) => {
const cookie = cookies.get('auth') || null;
logout: async (event) => {
let sessionId = event.cookies.get('sessionid');
let csrfToken = await fetchCSRFToken();

if (!cookie) {
if (!sessionId) {
return;
}

const res = await fetch(`${serverEndpoint}/auth/logout/`, {
method: 'POST',
const res = await fetch(`${serverEndpoint}/_allauth/browser/v1/auth/session`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Cookie: cookies.get('auth')
}
Cookie: `sessionid=${sessionId}; csrftoken=${csrfToken}`,
'X-CSRFToken': csrfToken
},
credentials: 'include'
});
if (res.ok) {
cookies.delete('auth', { path: '/', secure: false });
cookies.delete('refresh', { path: '/', secure: false });
if (res.status == 401) {
return redirect(302, '/login');
} else {
return redirect(302, '/');
Expand Down
4 changes: 0 additions & 4 deletions proxy/Dockerfile.nginx

This file was deleted.

8 changes: 0 additions & 8 deletions proxy/nginx.conf

This file was deleted.

0 comments on commit 50dc042

Please sign in to comment.